]> git.lizzy.rs Git - dragonstd.git/blobdiff - bits/wrappers.h
refactoring + documentation + testing + added Map and Refcount
[dragonstd.git] / bits / wrappers.h
diff --git a/bits/wrappers.h b/bits/wrappers.h
new file mode 100644 (file)
index 0000000..60d8784
--- /dev/null
@@ -0,0 +1,32 @@
+#define WRAP_NODE_FUNCTIONS(Type, prefix) \
+       void *prefix ## add(Type *self, void *dat, Comparator cmp, Transformer func) \
+       { \
+               Type ## Node **node = prefix ## nfd(self, dat, cmp); \
+ \
+               if (! *node) \
+                       prefix ## nmk(self, node, func ? func(dat) : dat); \
+ \
+               return (*node)->dat; \
+       } \
+ \
+       void *prefix ## get(Type *self, void *key, Comparator cmp, Transformer func) \
+       { \
+               Type ## Node **node = prefix ## nfd(self, key, cmp); \
+ \
+               if (! *node) \
+                       return NULL; \
+ \
+               return func ? func((*node)->dat) : (*node)->dat; \
+       } \
+ \
+       void *prefix ## del(Type *self, void *key, Comparator cmp, Transformer func) \
+       { \
+               Type ## Node **node = prefix ## nfd(self, key, cmp); \
+ \
+               if (! *node) \
+                       return NULL; \
+ \
+               void *dat = func ? func((*node)->dat) : (*node)->dat; \
+               prefix ## nrm(self, node); \
+               return dat; \
+       }