aboutsummaryrefslogtreecommitdiff
path: root/src/trie.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-03-22 20:11:11 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-03-22 20:17:52 +0100
commitd46183860c1f3f10095e95023adcb79b1896ab0e (patch)
treedd331a0efe9777bfe84160139da1e39df3226b71 /src/trie.h
parentAdd stuff to test.scm. (diff)
downloadcalp-d46183860c1f3f10095e95023adcb79b1896ab0e.tar.gz
calp-d46183860c1f3f10095e95023adcb79b1896ab0e.tar.xz
Move C and Scheme code into subdirs.
Diffstat (limited to 'src/trie.h')
-rw-r--r--src/trie.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/trie.h b/src/trie.h
new file mode 100644
index 00000000..9de38be3
--- /dev/null
+++ b/src/trie.h
@@ -0,0 +1,54 @@
+#ifndef TRIE_H
+#define TRIE_H
+
+#include <stdio.h>
+
+#include "macro.h"
+
+#define TRIE(T) TEMPL(trie, T)
+#define TRIE_NODE(T) TEMPL(trie_node, T)
+
+#endif /* TRIE_H */
+#ifdef TYPE
+
+#include "linked_list.h"
+#include "strbuf.h"
+
+typedef struct TRIE_NODE(TYPE) {
+ char c;
+ TYPE* value;
+ struct TRIE_NODE(TYPE)* next;
+ struct TRIE_NODE(TYPE)* child;
+} TRIE_NODE(TYPE);
+
+typedef struct {
+ TRIE_NODE(TYPE)* root;
+} TRIE(TYPE);
+
+
+INIT_F ( TRIE(TYPE) );
+
+INIT_F (TRIE_NODE(TYPE), char c);
+
+INIT_F (TRIE_NODE(TYPE),
+ char c, TRIE_NODE(TYPE)* next, TRIE_NODE(TYPE)* child );
+
+int PUSH(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key, TYPE* val );
+
+TYPE* GET(TRIE(TYPE)) ( TRIE(TYPE)* trie, char* key );
+
+FREE_F(TRIE_NODE(TYPE));
+
+FREE_F(TRIE(TYPE));
+
+int EMPTY(TRIE(TYPE))(TRIE(TYPE)*);
+
+FMT_F(TRIE_NODE(TYPE));
+FMT_F(TRIE(TYPE));
+
+int DEEP_COPY(TRIE_NODE(TYPE)) (TRIE_NODE(TYPE)* dest, TRIE_NODE(TYPE)* src);
+int DEEP_COPY(TRIE(TYPE)) (TRIE(TYPE)* dest, TRIE(TYPE)* src);
+
+LLIST(strbuf)* KEYS(TRIE(TYPE)) (TRIE(TYPE)*);
+
+#endif /* TYPE */