Commit a998a910 authored by Geoff Simmons's avatar Geoff Simmons

Rename the struct for qp tries.

parent 5454faa6
...@@ -44,21 +44,21 @@ ...@@ -44,21 +44,21 @@
#define ANIB(x) AZ((x) & ~0x0f) #define ANIB(x) AZ((x) & ~0x0f)
struct pt_y { struct qp_y {
unsigned magic; unsigned magic;
#define QP_Y_MAGIC 0x6dfde24a #define QP_Y_MAGIC 0x6dfde24a
unsigned idx; unsigned idx;
struct pt_y **branch; struct qp_y **branch;
unsigned short off; unsigned short off;
unsigned short len; unsigned short len;
uint16_t bitmap; uint16_t bitmap;
unsigned char hilo; unsigned char hilo;
}; };
static struct pt_y * static struct qp_y *
y_alloc(unsigned idx, unsigned short off, size_t len) y_alloc(unsigned idx, unsigned short off, size_t len)
{ {
struct pt_y *y; struct qp_y *y;
if (len > USHRT_MAX) { if (len > USHRT_MAX) {
errno = ERANGE; errno = ERANGE;
...@@ -79,7 +79,7 @@ y_alloc(unsigned idx, unsigned short off, size_t len) ...@@ -79,7 +79,7 @@ y_alloc(unsigned idx, unsigned short off, size_t len)
return (y); return (y);
} }
static inline struct pt_y * static inline struct qp_y *
y_leaf_alloc(unsigned idx, unsigned char *c, unsigned char *b) y_leaf_alloc(unsigned idx, unsigned char *c, unsigned char *b)
{ {
return y_alloc(idx, (unsigned short)(uintptr_t)(c - b), return y_alloc(idx, (unsigned short)(uintptr_t)(c - b),
...@@ -87,7 +87,7 @@ y_leaf_alloc(unsigned idx, unsigned char *c, unsigned char *b) ...@@ -87,7 +87,7 @@ y_leaf_alloc(unsigned idx, unsigned char *c, unsigned char *b)
} }
static int static int
y_realloc_branch(struct pt_y * const y, uint16_t bitmap) y_realloc_branch(struct qp_y * const y, uint16_t bitmap)
{ {
int len; int len;
uint16_t prev, lobitmap; uint16_t prev, lobitmap;
...@@ -121,10 +121,10 @@ y_realloc_branch(struct pt_y * const y, uint16_t bitmap) ...@@ -121,10 +121,10 @@ y_realloc_branch(struct pt_y * const y, uint16_t bitmap)
return (0); return (0);
} }
static struct pt_y * static struct qp_y *
y_dup(struct pt_y *y0, unsigned short len) y_dup(struct qp_y *y0, unsigned short len)
{ {
struct pt_y *y; struct qp_y *y;
assert(len < y0->len); assert(len < y0->len);
...@@ -139,7 +139,7 @@ y_dup(struct pt_y *y0, unsigned short len) ...@@ -139,7 +139,7 @@ y_dup(struct pt_y *y0, unsigned short len)
} }
static inline uint16_t static inline uint16_t
getbits(const struct pt_y * const restrict y, unsigned char c) getbits(const struct qp_y * const restrict y, unsigned char c)
{ {
unsigned shift = y->hilo << 2; unsigned shift = y->hilo << 2;
unsigned mask = 0x0f << shift; unsigned mask = 0x0f << shift;
...@@ -147,16 +147,16 @@ getbits(const struct pt_y * const restrict y, unsigned char c) ...@@ -147,16 +147,16 @@ getbits(const struct pt_y * const restrict y, unsigned char c)
} }
static inline uint8_t static inline uint8_t
getidx(const struct pt_y * const restrict y, uint16_t bitmap) getidx(const struct qp_y * const restrict y, uint16_t bitmap)
{ {
return (popcount(y->bitmap & (bitmap - 1))); return (popcount(y->bitmap & (bitmap - 1)));
} }
int int
QP_Insert(struct pt_y * * restrict root, unsigned idx, QP_Insert(struct qp_y * * restrict root, unsigned idx,
char * const restrict * const restrict strings) char * const restrict * const restrict strings)
{ {
struct pt_y *y; struct qp_y *y;
unsigned char *c, *b; unsigned char *c, *b;
AN(root); AN(root);
...@@ -181,7 +181,7 @@ QP_Insert(struct pt_y * * restrict root, unsigned idx, ...@@ -181,7 +181,7 @@ QP_Insert(struct pt_y * * restrict root, unsigned idx,
unsigned char *s; unsigned char *s;
uint16_t bitmap; uint16_t bitmap;
uint8_t n; uint8_t n;
struct pt_y *y_new, *y_old; struct qp_y *y_new, *y_old;
CHECK_OBJ(y, QP_Y_MAGIC); CHECK_OBJ(y, QP_Y_MAGIC);
...@@ -353,11 +353,11 @@ QP_Insert(struct pt_y * * restrict root, unsigned idx, ...@@ -353,11 +353,11 @@ QP_Insert(struct pt_y * * restrict root, unsigned idx,
} }
unsigned unsigned
QP_Lookup(const struct pt_y * const restrict root, QP_Lookup(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
const char * const restrict subject) const char * const restrict subject)
{ {
const struct pt_y *y; const struct qp_y *y;
size_t len; size_t len;
AN(strings); AN(strings);
...@@ -392,7 +392,7 @@ QP_Lookup(const struct pt_y * const restrict root, ...@@ -392,7 +392,7 @@ QP_Lookup(const struct pt_y * const restrict root,
} }
static int static int
qp_search(const struct pt_y * const restrict y, qp_search(const struct qp_y * const restrict y,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
const unsigned char * restrict subject, size_t len, const unsigned char * restrict subject, size_t len,
struct match_data * const restrict match) struct match_data * const restrict match)
...@@ -446,7 +446,7 @@ qp_search(const struct pt_y * const restrict y, ...@@ -446,7 +446,7 @@ qp_search(const struct pt_y * const restrict y,
} }
int int
QP_Prefixes(const struct pt_y * const restrict root, QP_Prefixes(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
const char * const restrict subject, const char * const restrict subject,
struct match_data * const restrict match) struct match_data * const restrict match)
...@@ -469,7 +469,7 @@ QP_Prefixes(const struct pt_y * const restrict root, ...@@ -469,7 +469,7 @@ QP_Prefixes(const struct pt_y * const restrict root,
} }
void void
QP_Free(struct pt_y *y) QP_Free(struct qp_y *y)
{ {
if (y == NULL) if (y == NULL)
return; return;
...@@ -486,7 +486,7 @@ QP_Free(struct pt_y *y) ...@@ -486,7 +486,7 @@ QP_Free(struct pt_y *y)
} }
static void static void
qp_print_tree(struct pt_y *y, struct vsb *sb, char **strings) qp_print_tree(struct qp_y *y, struct vsb *sb, char **strings)
{ {
CHECK_OBJ_NOTNULL(y, QP_Y_MAGIC); CHECK_OBJ_NOTNULL(y, QP_Y_MAGIC);
CHECK_OBJ_NOTNULL(sb, VSB_MAGIC); CHECK_OBJ_NOTNULL(sb, VSB_MAGIC);
...@@ -523,7 +523,7 @@ qp_print_tree(struct pt_y *y, struct vsb *sb, char **strings) ...@@ -523,7 +523,7 @@ qp_print_tree(struct pt_y *y, struct vsb *sb, char **strings)
} }
struct vsb * struct vsb *
QP_Dump(struct pt_y *root, char **strings) QP_Dump(struct qp_y *root, char **strings)
{ {
struct vsb *sb = VSB_new_auto(); struct vsb *sb = VSB_new_auto();
...@@ -538,7 +538,7 @@ QP_Dump(struct pt_y *root, char **strings) ...@@ -538,7 +538,7 @@ QP_Dump(struct pt_y *root, char **strings)
} }
void void
qp_stats(const struct pt_y * const restrict y, qp_stats(const struct qp_y * const restrict y,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
struct qp_stats * const restrict stats, unsigned depth) struct qp_stats * const restrict stats, unsigned depth)
{ {
...@@ -581,7 +581,7 @@ qp_stats(const struct pt_y * const restrict y, ...@@ -581,7 +581,7 @@ qp_stats(const struct pt_y * const restrict y,
} }
void void
QP_Stats(const struct pt_y * const restrict root, QP_Stats(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
struct qp_stats * const restrict stats) struct qp_stats * const restrict stats)
{ {
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "vsb.h" #include "vsb.h"
struct pt_y; struct qp_y;
struct match_data { struct match_data {
unsigned magic; unsigned magic;
...@@ -60,17 +60,17 @@ struct qp_stats { ...@@ -60,17 +60,17 @@ struct qp_stats {
double favg; double favg;
}; };
int QP_Insert(struct pt_y * * restrict root, unsigned idx, int QP_Insert(struct qp_y * * restrict root, unsigned idx,
char * const restrict * const restrict strings); char * const restrict * const restrict strings);
unsigned QP_Lookup(const struct pt_y * const restrict root, unsigned QP_Lookup(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
const char * const restrict subject); const char * const restrict subject);
int QP_Prefixes(const struct pt_y * const restrict root, int QP_Prefixes(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
const char * const restrict subject, const char * const restrict subject,
struct match_data * const restrict match); struct match_data * const restrict match);
void QP_Stats(const struct pt_y * const restrict root, void QP_Stats(const struct qp_y * const restrict root,
char * const restrict * const restrict strings, char * const restrict * const restrict strings,
struct qp_stats * const restrict stats); struct qp_stats * const restrict stats);
void QP_Free(struct pt_y *y); void QP_Free(struct qp_y *y);
struct vsb * QP_Dump(struct pt_y *root, char **strings); struct vsb * QP_Dump(struct qp_y *root, char **strings);
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#define ITERATIONS (1000) #define ITERATIONS (1000)
#define CLOCK (CLOCK_MONOTONIC) #define CLOCK (CLOCK_MONOTONIC)
static struct pt_y *origo = NULL; static struct qp_y *origo = NULL;
static uint64_t static uint64_t
tdiff(struct timespec *before, struct timespec *after) tdiff(struct timespec *before, struct timespec *after)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment