now the DUMP command
[rxpd] / psplay.h
index d9645f7..ea65417 100644 (file)
--- a/psplay.h
+++ b/psplay.h
 #include <stdint.h>
 #include <stdio.h>
 
+enum psplay_order_e
+  {
+    PSPLAY_PREORDER,
+    PSPLAY_INORDER,
+    PSPLAY_POSTORDER
+  };
+
+typedef struct psplayroot_struct psplayroot;
+typedef psplayroot* PSplayroot;
+
 typedef struct psplay_struct psplay;
 typedef psplay* PSplay;
-typedef PSplay* PSplay_ref;
 
+typedef int (*psplay_cmp_t)(const void*, const void*);
+typedef void (*psplay_delete_t)(PSplay);
+typedef psplay_delete_t (*psplay_action_t)(PSplay node, const enum psplay_order_e which, int level, void* data);
+
+//
+struct psplayroot_struct
+{
+  PSplay tree;
+  psplay_cmp_t cmp;
+  psplay_delete_t delete;
+  /* amount of elements will some day adjust the probability fucntions, further research necessary */
+  size_t elem_cnt;
+  /* PSplay history[64]; ringbuffer storing the path of a search, optimize 'up' pointer out */
+};
+
+PSplayroot
+psplay_init_root (PSplayroot self, psplay_cmp_t cmp, psplay_delete_t delete);
+
+PSplayroot
+psplay_destroy_root (PSplayroot self);
+
+static inline int
+psplay_isempty_root (PSplayroot root)
+{
+  return !root->tree;
+}
+
+#define PSPLAYROOT_INITIALIZER(cmp, delete) {NULL, cmp, delete, 0}
+
+//
 struct psplay_struct
 {
-  void* key;
+  const void* key;
   PSplay up;
   PSplay left;
   PSplay right;
 };
 
-typedef int (*psplay_cmp_t)(const void*, const void*);
 
 PSplay
 psplay_new (void * key);
 
 PSplay
-psplay_init (PSplay self, void* key);
+psplay_init (PSplay self, const void* key);
 
 void
 psplay_delete (PSplay node);
 
 PSplay
-psplay_insert (PSplay_ref root, PSplay node, psplay_cmp_t cmp);
+psplay_insert (PSplayroot root, PSplay node);
 
 PSplay
-psplay_find (PSplay_ref root, void* key, psplay_cmp_t cmp);
+psplay_find (PSplayroot root, void* key);
 
 PSplay
-psplay_remove (PSplay_ref root, PSplay node);
+psplay_remove (PSplayroot root, PSplay node);
+
+extern const psplay_delete_t PSPLAY_CONT;
+extern const psplay_delete_t PSPLAY_STOP;
+extern const psplay_delete_t PSPLAY_REMOVE;
+
+int
+psplay_walk (PSplayroot root, PSplay node, psplay_action_t action, int level, void* data);
+
 
-/*
 void
-psplay_dump (PSplay root, FILE* dest, unsigned level);
-*/
+psplay_dump (PSplayroot root, FILE* dest);
+
 
 #endif