aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--bitmapped_patricia_tree.c3
-rw-r--r--bitmapped_patricia_tree.h5
-rwxr-xr-xconfigure25
4 files changed, 44 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 53892cd..26af52a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
RM_F = rm -f
-CFLAGS = -std=c99 -Wall -pedantic -ggdb -g -DUSE_TERMIOS
+ADDITIONAL_CFLAGS = -DCHUNK_LENGTH=6 -DKEY_LENGTH=64 -DOFFSET_MASK=63 -DMAX_CHUNKS=11 -DLAST_CHUNK_LENGTH=4 -DBPT_EXPLICIT_CONFIGURATION -DBPT_KEY_T=intptr_t -DBPT_KEY_BITMASK_T=int64_t
+CFLAGS = -std=c99 -Wall -pedantic -ggdb -g -DUSE_TERMIOS $(ADDITIONAL_CFLAGS)
LIBTOOL = libtool
LDFLAGS = -lc
CC = clang
@@ -15,6 +16,10 @@ bpttest_C_SOURCES = bpt_test.c
bpttest_OBJECTS = $(patsubst %.c,%.o,$(bpttest_C_SOURCES))
bpttest_TARGET = bpt_test
+config_C_SOURCES = config.c
+config_OBJECTS = $(patsubst %.c,%.o,$(config_C_SOURCES))
+config_TARGET = config
+
.PHONY: all clean
all: $(mulklib_TARGET) $(bpttest_TARGET)
@@ -24,6 +29,8 @@ clean:
$(RM_F) $(mulklib_TARGET)
$(RM_F) $(bpttest_OBJECTS)
$(RM_F) $(bpttest_TARGET)
+ $(RM_F) $(config_OBJECTS)
+ $(RM_F) $(config_TARGET)
$(mulklib_TARGET): $(mulklib_OBJECTS)
@@ -32,5 +39,9 @@ $(mulklib_TARGET): $(mulklib_OBJECTS)
$(bpttest_TARGET): $(bpttest_OBJECTS) $(mulklib_TARGET)
$(CC) -o $@ $+
+$(config_TARGET): $(config_OBJECTS)
+ $(CC) -o $@ $+
+
bitmapped_patricia_tree.o: bitmapped_patricia_tree.c bitmapped_patricia_tree.h
bpt_test.o: bpt_test.c bitmapped_patricia_tree.h
+config.o: config.c
diff --git a/bitmapped_patricia_tree.c b/bitmapped_patricia_tree.c
index 79ac076..543ffb8 100644
--- a/bitmapped_patricia_tree.c
+++ b/bitmapped_patricia_tree.c
@@ -49,12 +49,13 @@
#include "bitmapped_patricia_tree.h"
+#ifndef BPT_EXPLICIT_CONFIGURATION
#define CHUNK_LENGTH 5
#define KEY_LENGTH 32
#define OFFSET_MASK 0x1ffff //((1 << chunk_length) - 1)
#define MAX_CHUNKS 7 //key_length / chunk_length + ((key_length % chunk_length == 0) ? 0 : 1)
#define LAST_CHUNK_LENGTH 2 //key_length - ((max_chunks - 1) * chunk_length)
-
+#endif //!BPT_EXPLICIT_CONFIGURATION
typedef struct bpt_nonempty *bpt_nonempty_t;
typedef struct bpt_node *bpt_node_t;
diff --git a/bitmapped_patricia_tree.h b/bitmapped_patricia_tree.h
index b1a3e32..f1d65c3 100644
--- a/bitmapped_patricia_tree.h
+++ b/bitmapped_patricia_tree.h
@@ -32,8 +32,13 @@ extern "C" {
#define BPT_ENABLE_DEALLOC_HOOKS 1
+#ifdef BPT_EXPLICIT_CONFIGURATION
+typedef BPT_KEY_T bpt_key_t;
+typedef BPT_KEY_BITMASK_T bpt_key_bitmask_t;
+#else
typedef int32_t bpt_key_t;
typedef int32_t bpt_key_bitmask_t;
+#endif //!BPT_EXPLICIT_CONFIGURATION
enum bpt_tag {
BPT_LEAF,
diff --git a/configure b/configure
new file mode 100755
index 0000000..7e9d15e
--- /dev/null
+++ b/configure
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+if [ sed --version >/dev/null 2>&1 ]; then
+ GSED=sed
+else
+ GSED=gsed
+fi
+
+if [ "$#" -lt 2 ]; then
+ echo "Usage:"
+ echo " ./configure <bpt_key_t> <bpt_key_bitmask_t>"
+ echo
+ echo "Example:"
+ echo " ./configure intptr_t int64_t"
+ exit 2
+fi
+
+KEY_T=$1
+BITMASK_T=$2
+
+make config ADDITIONAL_CFLAGS="-DBPT_KEY_T=$KEY_T -DBPT_KEY_BITMASK_T=$BITMASK_T"
+CONFIG_CFLAGS=$(./config)
+make clean
+
+"$GSED" --in-place "s/ADDITIONAL_CFLAGS =.*\$/ADDITIONAL_CFLAGS = $CONFIG_CFLAGS -DBPT_EXPLICIT_CONFIGURATION -DBPT_KEY_T=$KEY_T -DBPT_KEY_BITMASK_T=$BITMASK_T/" Makefile