bst.h

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. - All rights reserved.
00003  */
00004 
00005 #ifndef _U_BST_H_
00006 #define _U_BST_H_
00007 
00008 #include <u/libu_conf.h>
00009 #include <sys/types.h>
00010 
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif  /* __cplusplus */
00014 
00015 /* forward decls */ 
00016 struct u_bst_s;
00017 struct u_bst_node_s;
00018 
00025 typedef struct u_bst_s u_bst_t;
00026 
00028 typedef struct u_bst_node_s u_bst_node_t;
00029 
00030 
00032 typedef enum {
00033     U_BST_TYPE_STRING,  
00034     U_BST_TYPE_OPAQUE,  
00035     U_BST_TYPE_PTR      
00036 } u_bst_type_t;
00037 
00039 typedef enum {
00040     U_BST_ROT_LEFT,     
00041     U_BST_ROT_RIGHT     
00042 } u_bst_rot_t;
00043 
00045 typedef enum {
00046     U_BST_OPT_NONE          = 0,
00047     U_BST_OPT_PUSH_TOP      = (1 << 0),   
00048     U_BST_OPT_PUSH_BOTTOM   = (1 << 1),   
00049     U_BST_OPT_RANDOMIZED    = (1 << 2)    
00050 } u_bst_opt_t;
00051 
00052 /* Base interface. */
00053 int u_bst_new (int opts, u_bst_t **pbst);
00054 void u_bst_free (u_bst_t *bst);
00055 ssize_t u_bst_count (u_bst_t *bst);
00056 u_bst_node_t *u_bst_search (u_bst_t *bst, const void *key);
00057 int u_bst_push (u_bst_t *bst, const void *key, const void *val);
00058 int u_bst_foreach (u_bst_t *bst, void (*cb)(u_bst_node_t *, void *), 
00059         void *cb_args);
00060 u_bst_node_t *u_bst_rotate (u_bst_node_t *node, u_bst_rot_t dir);
00061 int u_bst_empty (u_bst_t *bst);
00062 u_bst_node_t *u_bst_find_nth (u_bst_t *bst, size_t n);
00063 int u_bst_delete (u_bst_t *bst, const void *key);
00064 int u_bst_balance (u_bst_t *bst);
00065 
00066 /* BST configuration. */
00067 int u_bst_set_cmp (u_bst_t *bst, int (*f)(const void *, const void *));
00068 int u_bst_set_keyattr (u_bst_t *bst, u_bst_type_t kt, size_t ks);
00069 int u_bst_set_valattr (u_bst_t *bst, u_bst_type_t vt, size_t vs);
00070 int u_bst_set_keyfree (u_bst_t *bst, void (*f)(void *));
00071 int u_bst_set_valfree (u_bst_t *bst, void (*f)(void *));
00072 
00073 /* Getters/Setters. */
00074 const void *u_bst_node_key (u_bst_node_t *node);
00075 const void *u_bst_node_val (u_bst_node_t *node);
00076 ssize_t u_bst_node_count (u_bst_node_t *node);
00077 
00082 #ifdef __cplusplus
00083 }
00084 #endif  /* __cplusplus */
00085 
00086 #endif  /* !_U_BST_H_ */

←Products
© 2005-2012 - KoanLogic S.r.l. - All rights reserved