summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/patree.c43
-rw-r--r--test/patree_bench.c2
-rw-r--r--test/patree_test.c8
-rw-r--r--wscript15
-rw-r--r--zix/patree.h2
5 files changed, 36 insertions, 34 deletions
diff --git a/src/patree.c b/src/patree.c
index 1903cd1..1e843e1 100644
--- a/src/patree.c
+++ b/src/patree.c
@@ -30,9 +30,9 @@
#ifdef __SSE4_2__
#include <smmintrin.h>
-#warning Using SSE 4.2
+//#warning Using SSE 4.2
#else
-#warning SSE 4.2 disabled
+//#warning SSE 4.2 disabled
#endif
typedef uint_fast8_t n_edges_t;
@@ -45,9 +45,9 @@ typedef struct {
} ZixChildRef;
typedef struct _ZixPatreeNode {
- char* label_first; /* Start of incoming label */
- char* label_last; /* End of incoming label */
- char* str; /* String stored at this node */
+ const char* label_first; /* Start of incoming label */
+ const char* label_last; /* End of incoming label */
+ const char* str; /* String stored at this node */
n_edges_t num_children; /* Number of outgoing edges */
ZixChildRef children[]; /* Children of this node */
} ZixPatreeNode;
@@ -144,9 +144,9 @@ patree_find_edge(const ZixPatreeNode* n, const char c, n_edges_t* const index)
static void
patree_add_edge(ZixPatreeNode** n_ptr,
- char* str,
- char* first,
- char* last)
+ const char* str,
+ const char* first,
+ const char* last)
{
ZixPatreeNode* n = *n_ptr;
@@ -212,21 +212,22 @@ patree_split_edge(ZixPatreeNode** child_ptr,
}
static ZixStatus
-patree_insert_internal(ZixPatreeNode** n_ptr, char* str, char* first, char* last)
+patree_insert_internal(ZixPatreeNode** n_ptr,
+ const char* str, const char* first, const char* last)
{
n_edges_t child_i;
assert(first <= last);
ZixPatreeNode* n = *n_ptr;
if (patree_find_edge(n, *first, &child_i)) {
- ZixPatreeNode** child_ptr = &n->children[child_i].child;
- ZixPatreeNode* child = *child_ptr;
- char* const label_first = child->label_first;
- char* const label_last = child->label_last;
- size_t split_i = 0;
- const size_t label_len = label_last - label_first + 1;
- const size_t s_len = last - first + 1;
- const size_t max_len = (s_len < label_len) ? s_len : label_len;
+ ZixPatreeNode** child_ptr = &n->children[child_i].child;
+ ZixPatreeNode* child = *child_ptr;
+ const char* const label_first = child->label_first;
+ const char* const label_last = child->label_last;
+ size_t split_i = 0;
+ const size_t label_len = label_last - label_first + 1;
+ const size_t s_len = last - first + 1;
+ const size_t max_len = (s_len < label_len) ? s_len : label_len;
while (split_i < max_len && first[split_i] == label_first[split_i]) {
++split_i;
@@ -269,7 +270,7 @@ zix_patree_insert(ZixPatree* t, const char* str)
return patree_insert_internal(&t->root, (char*)str, (char*)str, (char*)str + len - 1);
}
-int
+static inline int
change_index_c(const char* a, const char* b, size_t len)
{
for (size_t i = 0; i < len; ++i) {
@@ -281,7 +282,7 @@ change_index_c(const char* a, const char* b, size_t len)
}
#ifdef __SSE4_2__
-int
+static inline int
change_index_sse(const char* a, const char* b, const size_t len)
{
int ret;
@@ -306,7 +307,7 @@ change_index_sse(const char* a, const char* b, const size_t len)
ZIX_API
ZixStatus
-zix_patree_find(const ZixPatree* t, const char* const str, char** match)
+zix_patree_find(const ZixPatree* t, const char* const str, const char** match)
{
ZixPatreeNode* n = t->root;
n_edges_t child_i;
@@ -316,7 +317,7 @@ zix_patree_find(const ZixPatree* t, const char* const str, char** match)
while (patree_find_edge(n, p[0], &child_i)) {
assert(child_i <= n->num_children);
ZixPatreeNode* const child = n->children[child_i].child;
- char* const child_str = child->str;
+ const char* const child_str = child->str;
/* Prefix compare search string and label */
const char* l = child->label_first;
diff --git a/test/patree_bench.c b/test/patree_bench.c
index 8af9f9b..02998d6 100644
--- a/test/patree_bench.c
+++ b/test/patree_bench.c
@@ -146,7 +146,7 @@ main(int argc, char** argv)
search_start = bench_start();
for (size_t i = 0; i < n; ++i) {
const size_t index = rand() % n;
- char* match = NULL;
+ const char* match = NULL;
if (zix_patree_find(patree, strings[index], &match)) {
return test_fail("Patree: Failed to find `%s'\n", strings[index]);
}
diff --git a/test/patree_test.c b/test/patree_test.c
index 07d4a79..6d30509 100644
--- a/test/patree_test.c
+++ b/test/patree_test.c
@@ -81,8 +81,8 @@ main(int argc, char** argv)
// Search for each string
for (size_t i = 0; i < n_strings; ++i) {
- char* match = NULL;
- ZixStatus st = zix_patree_find(patree, strings[i], &match);
+ const char* match = NULL;
+ ZixStatus st = zix_patree_find(patree, strings[i], &match);
if (st) {
return test_fail("Failed to find `%s'\n", strings[i]);
}
@@ -100,8 +100,8 @@ main(int argc, char** argv)
};
const size_t n_not_indexed = sizeof(not_indexed) / sizeof(char*);
for (size_t i = 0; i < n_not_indexed; ++i) {
- char* match = NULL;
- ZixStatus st = zix_patree_find(patree, not_indexed[i], &match);
+ const char* match = NULL;
+ ZixStatus st = zix_patree_find(patree, not_indexed[i], &match);
if (st != ZIX_STATUS_NOT_FOUND) {
return test_fail("Unexpectedly found `%s'\n", not_indexed[i]);
}
diff --git a/wscript b/wscript
index 949d14e..b2521f1 100644
--- a/wscript
+++ b/wscript
@@ -41,24 +41,25 @@ def configure(conf):
conf.load('compiler_c')
conf.env.append_value('CFLAGS', '-std=c99')
- autowaf.check_pkg(conf, 'glib-2.0', uselib_store='GLIB',
- atleast_version='2.0.0', mandatory=False)
-
- # Check for dladdr
+ # Check for mlock
conf.check(function_name='mlock',
header_name='sys/mman.h',
define_name='HAVE_MLOCK',
mandatory=False)
+ conf.env['BUILD_BENCH'] = Options.options.build_bench
conf.env['BUILD_TESTS'] = Options.options.build_tests
- if conf.is_defined('HAVE_GLIB'):
- conf.env['BUILD_BENCH'] = Options.options.build_bench
+ if Options.options.build_bench:
+ autowaf.check_pkg(conf, 'glib-2.0', uselib_store='GLIB',
+ atleast_version='2.0.0', mandatory=False)
+ if not conf.is_defined('HAVE_GLIB'):
+ conf.fatal("Glib is required to build benchmarks")
autowaf.define(conf, 'ZIX_VERSION', ZIX_VERSION)
conf.write_config_header('zix-config.h', remove=False)
autowaf.display_msg(conf, "Unit tests", str(conf.env['BUILD_TESTS']))
- autowaf.display_msg(conf, "Benchmarks", str(conf.env['BUILD_BENCHx']))
+ autowaf.display_msg(conf, "Benchmarks", str(conf.env['BUILD_BENCH']))
print('')
tests = [
diff --git a/zix/patree.h b/zix/patree.h
index d3cf4da..09f3538 100644
--- a/zix/patree.h
+++ b/zix/patree.h
@@ -61,7 +61,7 @@ zix_patree_insert(ZixPatree* t, const char* str);
*/
ZIX_API
ZixStatus
-zix_patree_find(const ZixPatree* t, const char* str, char** match);
+zix_patree_find(const ZixPatree* t, const char* str, const char** match);
/**
@}