1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-22 13:30:17 +02:00

qpkg/jrb.h: general code cleanup

- jrb.h: fixed indentation
- jrb.h: named anonymous parameters
- jrb.h: removed "extern" from function prototypes
This commit is contained in:
Werner Almesberger 2010-11-19 19:57:38 -03:00
parent cc92c67080
commit dec07f359a

View File

@ -46,57 +46,57 @@ Fax: 865-974-4404
typedef struct jrb_node { typedef struct jrb_node {
unsigned char red; unsigned char red;
unsigned char internal; unsigned char internal;
unsigned char left; unsigned char left;
unsigned char roothead; /* (bit 1 is root, bit 2 is head) */ unsigned char roothead; /* (bit 1 is root, bit 2 is head) */
struct jrb_node *flink; struct jrb_node *flink;
struct jrb_node *blink; struct jrb_node *blink;
struct jrb_node *parent; struct jrb_node *parent;
void *key; void *key;
void *val; void *val;
} *JRB; } *JRB;
extern JRB make_jrb(void); /* Creates a new rb-tree */ JRB make_jrb(void); /* Creates a new rb-tree */
/* Creates a node with key key and val val and inserts it into the tree. /* Creates a node with key key and val val and inserts it into the tree.
jrb_insert uses strcmp() as comparison funcion. jrb_inserti uses <>=, jrb_insert uses strcmp() as comparison funcion. jrb_inserti uses <>=,
jrb_insertg uses func() */ jrb_insertg uses func() */
extern JRB jrb_insert(JRB tree, void *key, void *val, JRB jrb_insert(JRB tree, void *key, void *val,
int (*func)(const void *, const void *)); int (*func)(const void *a, const void *b));
/* returns an external node in t whose value is equal k. Returns NULL if /* returns an external node in t whose value is equal k. Returns NULL if
there is no such node in the tree */ there is no such node in the tree */
extern JRB jrb_find(JRB root, const void *, JRB jrb_find(JRB root, const void *key,
int (*func)(const void *, const void *)); int (*func)(const void *a, const void *b));
/* returns an external node in t whose value is equal /* returns an external node in t whose value is equal
k or whose value is the smallest value greater than k. Sets found to k or whose value is the smallest value greater than k. Sets found to
1 if the key was found, and 0 otherwise. */ 1 if the key was found, and 0 otherwise. */
extern JRB jrb_find_gte(JRB root, const void *key, JRB jrb_find_gte(JRB root, const void *key,
int (*func)(const void *, const void *), int *found); int (*func)(const void *a, const void *b), int *found);
/* Creates a node with key key and val val and inserts it into the /* Creates a node with key key and val val and inserts it into the
tree before/after node nd. Does not check to ensure that you are tree before/after node nd. Does not check to ensure that you are
keeping the correct order */ keeping the correct order */
extern void jrb_delete_node(JRB node); /* Deletes and frees a node (but void jrb_delete_node(JRB node); /* Deletes and frees a node (but
not the key or val) */ not the key or val) */
extern void jrb_free_tree(JRB root); /* Deletes and frees an entire tree */ void jrb_free_tree(JRB root); /* Deletes and frees an entire tree */
extern void *jrb_val(JRB node); /* Returns node->v.val -- this is to shut void *jrb_val(JRB node); /* Returns node->v.val -- this is to shut
lint up */ lint up */
extern int jrb_nblack(JRB n); /* returns # of black nodes in path from int jrb_nblack(JRB n); /* returns # of black nodes in path from
n to the root */ n to the root */
int jrb_plength(JRB n); /* returns the # of nodes in path from int jrb_plength(JRB n); /* returns the # of nodes in path from
n to the root */ n to the root */
#define jrb_first(n) ((n)->flink) #define jrb_first(n) ((n)->flink)
#define jrb_last(n) ((n)->blink) #define jrb_last(n) ((n)->blink)
@ -108,9 +108,9 @@ int jrb_plength(JRB n); /* returns the # of nodes in path from
#endif #endif
#define jrb_traverse(ptr, lst) \ #define jrb_traverse(ptr, lst) \
for(ptr = jrb_first(lst); ptr != jrb_nil(lst); ptr = jrb_next(ptr)) for (ptr = jrb_first(lst); ptr != jrb_nil(lst); ptr = jrb_next(ptr))
#define jrb_rtraverse(ptr, lst) \ #define jrb_rtraverse(ptr, lst) \
for(ptr = jrb_last(lst); ptr != jrb_nil(lst); ptr = jrb_prev(ptr)) for (ptr = jrb_last(lst); ptr != jrb_nil(lst); ptr = jrb_prev(ptr))
#endif #endif