command LOAD
[rxpd] / psplay.h
index a42cff5..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;
 
@@ -35,6 +42,7 @@ typedef psplay* PSplay;
 
 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
@@ -53,12 +61,18 @@ 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;
@@ -69,7 +83,7 @@ PSplay
 psplay_new (void * key);
 
 PSplay
-psplay_init (PSplay self, void* key);
+psplay_init (PSplay self, const void* key);
 
 void
 psplay_delete (PSplay node);
@@ -83,7 +97,16 @@ psplay_find (PSplayroot root, void* key);
 PSplay
 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