From 5d758f6938dc3c73e2c858255748f781aac17010 Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Tue, 9 Jul 2013 20:51:42 -0700 Subject: Added ternary tree implementation and a simple test program for it --- tern.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tern.h (limited to 'tern.h') diff --git a/tern.h b/tern.h new file mode 100644 index 0000000..0c5935a --- /dev/null +++ b/tern.h @@ -0,0 +1,28 @@ +#ifndef TERN_H_ +#define TERN_H_ + +#include + +typedef union { + void *ptrval; + intptr_t intval; +} tern_val; + +typedef struct tern_node { + struct tern_node *left; + union { + struct tern_node *next; + tern_val value; + } straight; + struct tern_node *right; + char el; +} tern_node; + +tern_node * tern_insert(tern_node * head, char * key, tern_val value); +int tern_find(tern_node * head, char * key, tern_val *ret); +intptr_t tern_find_int(tern_node * head, char * key, intptr_t def); +tern_node * tern_insert_int(tern_node * head, char * key, intptr_t value); +void * tern_find_ptr(tern_node * head, char * key); +tern_node * tern_insert_ptr(tern_node * head, char * key, void * value); + +#endif //TERN_H_ -- cgit v1.2.3