Code style compliance;

master
Alexander Vdolainen 6 years ago
parent bb6a20313b
commit 4ab3fc2b3d

@ -56,12 +56,14 @@ static void splay_insert(usrtc_t *us,usrtc_node_t *node,const void *key)
while(node != tree_root_priv(us)) while(node != tree_root_priv(us))
splay_node(us, node); splay_node(us, node);
return;
} }
static void splay_delete(usrtc_t *us, usrtc_node_t *node) static void splay_delete(usrtc_t *us, usrtc_node_t *node)
{ {
usrtc_node_t *dummy; usrtc_node_t *dummy;
usrtc_tree_delete(us, node, &dummy, &dummy); usrtc_tree_delete(us, node, &dummy, &dummy);
return;
} }
static usrtc_node_t *splay_lookup(usrtc_t *us, const void *key) static usrtc_node_t *splay_lookup(usrtc_t *us, const void *key)
@ -75,28 +77,36 @@ static usrtc_node_t *splay_lookup(usrtc_t *us,const void *key)
return node; return node;
} }
static void right_zig_zig(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa) static void right_zig_zig(usrtc_node_t *child, usrtc_node_t *parent,
usrtc_node_t *grandpa)
{ {
usrtc_tree_rotate_right(parent, grandpa); usrtc_tree_rotate_right(parent, grandpa);
usrtc_tree_rotate_right(child, parent); usrtc_tree_rotate_right(child, parent);
return;
} }
static void left_zig_zig(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa) static void left_zig_zig(usrtc_node_t *child, usrtc_node_t *parent,
usrtc_node_t *grandpa)
{ {
usrtc_tree_rotate_left(parent, grandpa); usrtc_tree_rotate_left(parent, grandpa);
usrtc_tree_rotate_left(child, parent); usrtc_tree_rotate_left(child, parent);
return;
} }
static void right_zig_zag(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa) static void right_zig_zag(usrtc_node_t *child, usrtc_node_t *parent,
usrtc_node_t *grandpa)
{ {
usrtc_tree_rotate_right(child, parent); usrtc_tree_rotate_right(child, parent);
usrtc_tree_rotate_left(child, grandpa); usrtc_tree_rotate_left(child, grandpa);
return;
} }
static void left_zig_zag(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa) static void left_zig_zag(usrtc_node_t *child, usrtc_node_t *parent,
usrtc_node_t *grandpa)
{ {
usrtc_tree_rotate_left(child, parent); usrtc_tree_rotate_left(child, parent);
usrtc_tree_rotate_right(child, grandpa); usrtc_tree_rotate_right(child, grandpa);
return;
} }
static void splay_node(usrtc_t *us, usrtc_node_t *node) static void splay_node(usrtc_t *us, usrtc_node_t *node)
@ -139,4 +149,5 @@ static void splay_node(usrtc_t *us,usrtc_node_t *node)
} }
} }
return;
} }

@ -53,6 +53,7 @@ void usrtc_tree_init(usrtc_t *us)
us->sentinel.impl_specific.usrtc_dummy = 0; us->sentinel.impl_specific.usrtc_dummy = 0;
us->sentinel.data = 0; us->sentinel.data = 0;
us->sentinel.key = 0; us->sentinel.key = 0;
return;
} }
void usrtc_tree_insert(usrtc_t *us, usrtc_node_t *node, const void *key) void usrtc_tree_insert(usrtc_t *us, usrtc_node_t *node, const void *key)
@ -89,9 +90,11 @@ void usrtc_tree_insert(usrtc_t *us,usrtc_node_t *node,const void *key)
node->right = nil; node->right = nil;
us->nodecount++; us->nodecount++;
return;
} }
void usrtc_tree_delete(usrtc_t *us,usrtc_node_t *node,usrtc_node_t **pswap,usrtc_node_t **pchild) void usrtc_tree_delete(usrtc_t *us, usrtc_node_t *node, usrtc_node_t **pswap,
usrtc_node_t **pchild)
{ {
usrtc_node_t *nil = tree_null_priv(us); usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *child; usrtc_node_t *child;
@ -150,14 +153,16 @@ void usrtc_tree_delete(usrtc_t *us,usrtc_node_t *node,usrtc_node_t **pswap,usrtc
} }
} }
node->parent=0; node->parent = NULL;
node->right=0; node->right = NULL;
node->left=0; node->left = NULL;
us->nodecount--; us->nodecount--;
*pswap = next; *pswap = next;
*pchild = child; *pchild = child;
return;
} }
usrtc_node_t *usrtc_tree_lookup(usrtc_t *us, const void *key) usrtc_node_t *usrtc_tree_lookup(usrtc_t *us, const void *key)
@ -288,7 +293,7 @@ usrtc_node_t *usrtc_tree_next(usrtc_t *us, usrtc_node_t *curr)
parent = curr->parent; parent = curr->parent;
while(parent!=nil && curr==parent->right) { while((parent != nil) && (curr == parent->right)) {
curr = parent; curr = parent;
parent = curr->parent; parent = curr->parent;
} }
@ -311,7 +316,7 @@ usrtc_node_t *usrtc_tree_prev(usrtc_t *us, usrtc_node_t *curr)
parent = curr->parent; parent = curr->parent;
while(parent!=nil && curr==parent->left) { while((parent != nil) && (curr == parent->left)) {
curr = parent; curr = parent;
parent = curr->parent; parent = curr->parent;
} }
@ -335,14 +340,16 @@ void usrtc_tree_convert_to_list(usrtc_t *us)
tempsentinel.prev = nil; tempsentinel.prev = nil;
/* two passes */ /* two passes */
for(tail=nil,node=usrtc_tree_first(us);node!=0;tail=node,node=next) { for(tail = nil, node = usrtc_tree_first(us); node != 0; tail = node,
node = next) {
next = usrtc_tree_next(us, node); next = usrtc_tree_next(us, node);
node->prev = tail; node->prev = tail;
} }
nil->prev = tail; nil->prev = tail;
for(tail=nil,node=nil->prev;node!=nil;tail=node,node=node->prev) for(tail = nil, node = nil->prev; node != nil; tail = node,
node = node->prev)
node->next = tail; node->next = tail;
nil->next = tail; nil->next = tail;
@ -351,6 +358,7 @@ void usrtc_tree_convert_to_list(usrtc_t *us)
us->sentinel.prev = tempsentinel.prev; us->sentinel.prev = tempsentinel.prev;
us->sentinel.next->prev = treenil; us->sentinel.next->prev = treenil;
us->sentinel.prev->next = treenil; us->sentinel.prev->next = treenil;
return;
} }
void usrtc_tree_convert_from_list(usrtc_t *us) void usrtc_tree_convert_from_list(usrtc_t *us)
@ -367,7 +375,7 @@ void usrtc_tree_convert_from_list(usrtc_t *us)
int level = 0; int level = 0;
int i = 0; int i = 0;
while (fullcount>=nodecount && fullcount) /* calc */ while ((fullcount >= nodecount) && fullcount) /* calc */
fullcount >>= 1; fullcount >>= 1;
botrowcount = nodecount - fullcount; botrowcount = nodecount - fullcount;
@ -375,7 +383,7 @@ void usrtc_tree_convert_from_list(usrtc_t *us)
for(curr = nil->next; curr != nil; curr = next) { for(curr = nil->next; curr != nil; curr = next) {
next = curr->next; next = curr->next;
if(complete==NULL && botrowcount-- ==0) { if((complete == NULL) && (botrowcount-- == 0)) {
baselevel = level = 1; baselevel = level = 1;
complete = tree[0]; complete = tree[0];
@ -428,6 +436,7 @@ void usrtc_tree_convert_from_list(usrtc_t *us)
nil->left = complete; nil->left = complete;
complete->parent = nil; complete->parent = nil;
return;
} }
void usrtc_tree_rotate_left(usrtc_node_t *child, usrtc_node_t *parent) void usrtc_tree_rotate_left(usrtc_node_t *child, usrtc_node_t *parent)
@ -454,6 +463,7 @@ void usrtc_tree_rotate_left(usrtc_node_t *child,usrtc_node_t *parent)
child->left = parent; child->left = parent;
parent->parent = child; parent->parent = child;
return;
} }
void usrtc_tree_rotate_right(usrtc_node_t *child, usrtc_node_t *parent) void usrtc_tree_rotate_right(usrtc_node_t *child, usrtc_node_t *parent)
@ -479,6 +489,7 @@ void usrtc_tree_rotate_right(usrtc_node_t *child,usrtc_node_t *parent)
child->right = parent; child->right = parent;
parent->parent = child; parent->parent = child;
return;
} }
/* local functions */ /* local functions */

@ -49,9 +49,11 @@ static usrtc_node_t *default_node_alloc(void *context)
static void default_node_free(void *context, usrtc_node_t *node) static void default_node_free(void *context, usrtc_node_t *node)
{ {
free(node); free(node);
return;
} }
void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t compare) void usrtc_init(usrtc_t *us, int impl, usrtc_count_t maxcount,
usrtc_compare_t compare)
{ {
if(!us) if(!us)
return; return;
@ -67,9 +69,11 @@ void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t comp
us->context = 0; us->context = 0;
us->futable = impl_table[impl]; us->futable = impl_table[impl];
us->futable->usrtc_init(us); us->futable->usrtc_init(us);
return;
} }
usrtc_t *usrtc_create(int impl,usrtc_count_t maxcount,usrtc_compare_t compare) usrtc_t *usrtc_create(int impl, usrtc_count_t maxcount,
usrtc_compare_t compare)
{ {
usrtc_t *newrtc = (usrtc_t *) malloc(sizeof *newrtc); usrtc_t *newrtc = (usrtc_t *) malloc(sizeof *newrtc);
@ -86,6 +90,7 @@ void usrtc_destroy(usrtc_t *us)
return; return;
free(us); free(us);
return;
} }
void usrtc_convert_to(usrtc_t *us,int impl) void usrtc_convert_to(usrtc_t *us,int impl)
@ -93,7 +98,8 @@ void usrtc_convert_to(usrtc_t *us,int impl)
if(impl_table[impl] == us->futable) if(impl_table[impl] == us->futable)
return; return;
if(us->futable->usrtc_type==usrtc_bst && (impl==USRTC_BST || impl==USRTC_SPLAY)) { if((us->futable->usrtc_type == usrtc_bst) &&
(impl == USRTC_BST || impl == USRTC_SPLAY)) {
us->futable = impl_table[impl]; us->futable = impl_table[impl];
return; return;
} }
@ -105,6 +111,7 @@ void usrtc_convert_to(usrtc_t *us,int impl)
return; return;
us->futable->usrtc_convert_from_list(us); us->futable->usrtc_convert_from_list(us);
return;
} }
usrtc_count_t usrtc_count(usrtc_t *us) usrtc_count_t usrtc_count(usrtc_t *us)
@ -138,13 +145,16 @@ void usrtc_delete_free(usrtc_t *us,usrtc_node_t *node)
{ {
us->futable->usrtc_delete(us, node); us->futable->usrtc_delete(us, node);
us->node_free(us->context, node); us->node_free(us->context, node);
return;
} }
void usrtc_set_allocator(usrtc_t *us,usrtc_node_alloc_t alloc,usrtc_node_free_t n_free,void *context) void usrtc_set_allocator(usrtc_t *us, usrtc_node_alloc_t alloc,
usrtc_node_free_t n_free, void *context)
{ {
us->node_alloc = alloc; us->node_alloc = alloc;
us->node_free = n_free; us->node_free = n_free;
us->context = context; us->context = context;
return;
} }
void usrtc_allow_dupes(usrtc_t *us) void usrtc_allow_dupes(usrtc_t *us)
@ -154,6 +164,7 @@ void usrtc_allow_dupes(usrtc_t *us)
return; return;
us->dupes_allowed = 1; us->dupes_allowed = 1;
return;
} }
void usrtc_node_init(usrtc_node_t *node, void *data) void usrtc_node_init(usrtc_node_t *node, void *data)
@ -178,6 +189,7 @@ usrtc_node_t *usrtc_node_create(void *data)
void usrtc_node_destroy(usrtc_node_t *node) void usrtc_node_destroy(usrtc_node_t *node)
{ {
free(node); free(node);
return;
} }
void *usrtc_node_getdata(usrtc_node_t *node) void *usrtc_node_getdata(usrtc_node_t *node)
@ -188,6 +200,7 @@ void *usrtc_node_getdata(usrtc_node_t *node)
void usrtc_node_setdata(usrtc_node_t *node, void *data) void usrtc_node_setdata(usrtc_node_t *node, void *data)
{ {
node->data = data; node->data = data;
return;
} }
const void *usrtc_node_getkey(usrtc_node_t *node) const void *usrtc_node_getkey(usrtc_node_t *node)
@ -198,11 +211,13 @@ const void *usrtc_node_getkey(usrtc_node_t *node)
void usrtc_insert(usrtc_t *us, usrtc_node_t *node, const void *key) void usrtc_insert(usrtc_t *us, usrtc_node_t *node, const void *key)
{ {
us->futable->usrtc_insert(us, node, key); us->futable->usrtc_insert(us, node, key);
return;
} }
void usrtc_delete(usrtc_t *us, usrtc_node_t *node) void usrtc_delete(usrtc_t *us, usrtc_node_t *node)
{ {
us->futable->usrtc_delete(us, node); us->futable->usrtc_delete(us, node);
return;
} }
usrtc_node_t *usrtc_lookup(usrtc_t *us, const void *key) usrtc_node_t *usrtc_lookup(usrtc_t *us, const void *key)
@ -240,4 +255,3 @@ usrtc_node_t *usrtc_prev(usrtc_t *us,usrtc_node_t *node)
return us->futable->usrtc_prev(us, node); return us->futable->usrtc_prev(us, node);
} }

Loading…
Cancel
Save