nary.h

Go to the documentation of this file.
00001 #ifndef _CP_NARYTREE_H
00002 #define _CP_NARYTREE_H
00003 
00011 #include "common.h"
00012 
00013 __BEGIN_DECLS
00014 
00015 #include "collection.h"
00016 
00017 struct _cp_narytree;
00018 
00019 typedef CPROPS_DLL struct _cp_narynode
00020 {
00021     void **key;
00022     void **value;
00023     int items;
00024 
00025     struct _cp_narynode **child;
00026     struct _cp_narynode *parent;
00027 } cp_narynode;
00028 
00029 CPROPS_DLL
00030 cp_narynode *cp_narynode_create(void *key, void *value);
00031 CPROPS_DLL
00032 void cp_narynode_destroy(cp_narynode *node);
00033 CPROPS_DLL
00034 void cp_narynode_destroy_deep(cp_narynode *node, struct _cp_narytree *owner);
00035 
00036 typedef CPROPS_DLL struct _cp_narytree
00037 {
00038     cp_narynode *root;
00039 
00040     int items;
00041     int order;                   /* max. number of children per node */
00042 
00043     int mode;
00044 
00045     cp_compare_fn cmp;
00046     cp_copy_fn key_copy;         /* key copy function */
00047     cp_destructor_fn key_dtr;    /* key destructor */
00048     cp_copy_fn value_copy;       /* value copy function */
00049     cp_destructor_fn value_dtr;  /* value destructor */
00050 
00051     cp_lock *lock;
00052     cp_thread txowner;           /* set if a transaction is in progress */
00053     int txtype;                  /* lock type */
00054 } cp_narytree;
00055 
00056 CPROPS_DLL
00057 cp_narytree *cp_narytree_create(int order, cp_compare_fn cmp);
00058 
00059 CPROPS_DLL
00060 cp_narytree *cp_narytree_create_by_option(int mode, 
00061                                           int order, 
00062                                           cp_compare_fn cmp, 
00063                                           cp_copy_fn key_copy,
00064                                           cp_destructor_fn key_dtr, 
00065                                           cp_copy_fn value_copy, 
00066                                           cp_destructor_fn value_dtr);
00067 
00068 CPROPS_DLL
00069 void cp_narytree_destroy(cp_narytree *tree);
00070 
00071 CPROPS_DLL
00072 void cp_narytree_destroy_custom(cp_narytree *tree, 
00073                                 cp_destructor_fn key_dtr, 
00074                                 cp_destructor_fn value_dtr);
00075 
00076 CPROPS_DLL
00077 void *cp_narytree_insert(cp_narytree *tree, void *key, void *value);
00078 CPROPS_DLL
00079 void *cp_narytree_get(cp_narytree *tree, void *key);
00080 CPROPS_DLL
00081 int cp_narytree_contains(cp_narytree *tree, void *key);
00082 CPROPS_DLL
00083 void *cp_narytree_delete(cp_narytree *tree, void *key);
00084 CPROPS_DLL
00085 int cp_narytree_callback(cp_narytree *tree, 
00086                          cp_callback_fn callback, 
00087                          void *prm);
00088 CPROPS_DLL
00089 int cp_narytree_count(cp_narytree *tree);
00090 
00092 CPROPS_DLL
00093 void cp_narytree_dump(cp_narytree *tree);
00094 
00095 CPROPS_DLL
00096 int cp_narytree_get_mode(cp_narytree *tree);
00097     
00098 CPROPS_DLL
00099 int cp_narytree_set_mode(cp_narytree *tree, int mode);
00100 
00101 /* unset mode bits on the tree mode indicator. if unsetting 
00102  * COLLECTION_MODE_NOSYNC and the tree was not previously synchronized, the 
00103  * internal synchronization structure is initialized.
00104  */
00105 CPROPS_DLL
00106 int cp_narytree_unset_mode(cp_narytree *tree, int mode);
00107 
00108 
00109 /* lock and set the transaction indicators */
00110 CPROPS_DLL
00111 int cp_narytree_lock(cp_narytree *tree, int type);
00112 
00113 #define cp_narytree_rdlock(tree) \
00114     (cp_narytree_lock((tree), COLLECTION_LOCK_READ))
00115 
00116 #define cp_narytree_wrlock(tree) \
00117     (cp_narytree_lock((tree), COLLECTION_LOCK_WRITE))
00118         
00119 /* unset the transaction indicators and unlock */
00120 CPROPS_DLL
00121 int cp_narytree_unlock(cp_narytree *tree);
00122 
00123 __END_DECLS
00124 
00127 #endif
00128 

Generated on Mon Dec 5 23:00:22 2011 for cprops by  doxygen 1.4.7