Compare commits

...

5 Commits

Author SHA1 Message Date
2759f0da87 packet debianization; 2025-03-05 16:37:24 +02:00
Alexander Vdolainen
dfc1b90513 Changes below:
- Code style fix in usrtc header file
 - Added autotools stuff for manpages
 - Added manpage for usrtc_init block:
   - usrtc_init()
   - usrtc_create()
   - usrtc_destroy()
2019-05-21 23:56:12 +03:00
Alexander Vdolainen
70072351a2 Code style compliance; 2019-05-21 22:33:49 +03:00
Alexander Vdolainen
5a60edd6ef Version number increase; 2019-05-21 22:21:18 +03:00
Alexander Vdolainen
4ab3fc2b3d Code style compliance; 2019-05-21 22:13:40 +03:00
22 changed files with 817 additions and 561 deletions

View File

@ -7,7 +7,7 @@ if BUILD_TESTS
EXTRA += tests
endif
SUBDIRS = include lib $(EXTRA)
SUBDIRS = include lib man $(EXTRA)
libtdatadocdir = ${prefix}/doc/libtdata
libtdatadoc_DATA = \

View File

@ -1 +1 @@
0.2.4
0.2.5

View File

@ -62,4 +62,5 @@ Makefile
lib/libtdata.pc
lib/Makefile
tests/Makefile
include/Makefile])
include/Makefile
man/Makefile])

1
debian/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.debhelper

6
debian/README.Debian vendored Normal file
View File

@ -0,0 +1,6 @@
libtdata for Debian
-------------------
This packages has been built with older versions of the autotools
-- Alexander Vdolainen <alex@vapaa.xyz> Wed, 5 Nov 2025 16:52:48 +0200

9
debian/README.source vendored Normal file
View File

@ -0,0 +1,9 @@
libtdata for Debian
-------------------
<this file describes information about the source package, see Debian policy
manual section 4.14. You WILL either need to modify or delete this file>

6
debian/changelog vendored Normal file
View File

@ -0,0 +1,6 @@
libtdata (0.2.5) stable; urgency=medium
* Release 0.2.5 minor fixes, documentation
* Updates to the new and uptodate libraries
-- Alexander Vdolainen <alex@vapaa.xyz> Mon, 3 Jun 2019 23:34:56 +0100

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
8

23
debian/control vendored Normal file
View File

@ -0,0 +1,23 @@
Source: libtdata
Priority: extra
Maintainer: Alexander Vdolainen <alex@vapaa.xyz>
Build-Depends: debhelper (>= 8.0.0), autotools-dev, libc-dev
Standards-Version: 3.9.3
Section: libs
Homepage: https://vapaa.work/public/libtdata
#Vcs-Git: git://git.debian.org/collab-maint/libsexpr.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/libsexpr.git;a=summary
Package: libtdata-dev
Section: libdevel
Architecture: any
Depends: libtdata (= ${binary:Version}), libc-dev
Description: Development files for libtdata
Development files for library implements various data structure implementation
Package: libtdata
Section: libs
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Implements various data structures
Library implements various data structure implementations

38
debian/copyright vendored Normal file
View File

@ -0,0 +1,38 @@
Upstream-Name: libtdata
Source: <https://vapaa.work/public/libtdata>
Files: *
Copyright: 2004 - 2019 Alexander Vdolainen <alex@vapaa.xyz>
License: LGPL-2
Additionally, this library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U SA
Files: debian/*
Copyright: 2014, 2025 Alexander Vdolainen <alex@vapaa.xyz>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".

2
debian/docs vendored Normal file
View File

@ -0,0 +1,2 @@
NEWS
README

13
debian/rules vendored Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@ --with autotools-dev

View File

@ -22,14 +22,11 @@
#define USRTC_COUNT_T_MAX ((1 << (sizeof(unsigned long)*(sizeof(char) << 1)))-1)
/*count and some misc typedefs*/
/* count and some misc typedefs */
typedef unsigned long usrtc_count_t;
typedef unsigned int usrtc_impl_id_t;
/* implementations ids,
* if you want to add some
* add the id here, don't forget to do it.
*/
/* implementation's typedefs */
#define USRTC_LIST 0
#define USRTC_BST 1
#define USRTC_REDBLACK 2
@ -102,9 +99,14 @@ typedef struct __usrtc_functions_t {
usrtc_impltype_t usrtc_type;
} usrtc_functions_t;
/*basic rtc functions*/
void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t compare);
usrtc_t *usrtc_create(int impl,usrtc_count_t maxcount,usrtc_compare_t compare);
/* basic usrtc functions */
/* initialize usrtc core structure */
void usrtc_init(usrtc_t *us, int impl, usrtc_count_t maxcount,
usrtc_compare_t compare);
/* allocate and initialize core structure: going to be deprecated */
usrtc_t *usrtc_create(int impl, usrtc_count_t maxcount,
usrtc_compare_t compare);
/* destroy(free) usrtc core structure: going to be deprecated */
void usrtc_destroy(usrtc_t *us);
void usrtc_convert_to(usrtc_t *us,int impl);

View File

@ -32,19 +32,19 @@ static void redblack_delete(usrtc_t *, usrtc_node_t *);
static void redblack_convert_from_list(usrtc_t *);
usrtc_functions_t usrtc_redblack_fu = {
redblack_init,
redblack_insert,
redblack_delete,
usrtc_tree_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
redblack_convert_from_list,
usrtc_bst
redblack_init,
redblack_insert,
redblack_delete,
usrtc_tree_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
redblack_convert_from_list,
usrtc_bst
};
/*implementation*/
@ -59,251 +59,254 @@ static void redblack_insert(usrtc_t *us, usrtc_node_t *node, const void *key)
usrtc_node_t *parent;
/* simple bt insert */
usrtc_tree_insert(us,node,key);
usrtc_tree_insert(us, node, key);
/* implementation specific insert */
node->color = usrtc_red;
parent=node->parent;
while(parent->color==usrtc_red) {
usrtc_node_t *grandpa=parent->parent;
if(parent==grandpa->left) {
usrtc_node_t *uncle=grandpa->right;
if(uncle->color==usrtc_red) { /*red parent->red uncle*/
parent->color=usrtc_black;
uncle->color=usrtc_black;
grandpa->color=usrtc_red;
node=grandpa;
parent=grandpa->parent;
} else { /*red parent->black uncle */
if(node==parent->right) {
usrtc_tree_rotate_left(node,parent);
parent=node;
if(grandpa!=parent->parent)
return;
}
parent->color=usrtc_black;
grandpa->color=usrtc_red;
usrtc_tree_rotate_right(parent,grandpa);
break;
}
} else { /*ooh,parent == parent->parent->right*/
usrtc_node_t *uncle=grandpa->left;
if(uncle->color==usrtc_red) {
parent->color=usrtc_black;
uncle->color=usrtc_black;
grandpa->color=usrtc_red;
node=grandpa;
parent=grandpa->parent;
} else {
if(node==parent->left) {
usrtc_tree_rotate_right(node,parent);
parent=node;
parent = node->parent;
if(grandpa!=parent->parent)
return;
}
parent->color=usrtc_black;
grandpa->color=usrtc_red;
usrtc_tree_rotate_left(parent,grandpa);
break;
while(parent->color == usrtc_red) {
usrtc_node_t *grandpa = parent->parent;
if(parent == grandpa->left) {
usrtc_node_t *uncle = grandpa->right;
if(uncle->color == usrtc_red) { /*red parent->red uncle*/
parent->color = usrtc_black;
uncle->color = usrtc_black;
grandpa->color = usrtc_red;
node = grandpa;
parent = grandpa->parent;
} else { /*red parent->black uncle */
if(node == parent->right) {
usrtc_tree_rotate_left(node, parent);
parent = node;
if(grandpa != parent->parent)
return;
}
parent->color = usrtc_black;
grandpa->color = usrtc_red;
usrtc_tree_rotate_right(parent, grandpa);
break;
}
} else { /* parent == parent->parent->right */
usrtc_node_t *uncle = grandpa->left;
if(uncle->color == usrtc_red) {
parent->color = usrtc_black;
uncle->color = usrtc_black;
grandpa->color = usrtc_red;
node = grandpa;
parent = grandpa->parent;
} else {
if(node == parent->left) {
usrtc_tree_rotate_right(node, parent);
parent = node;
if(grandpa != parent->parent)
return;
}
parent->color = usrtc_black;
grandpa->color = usrtc_red;
usrtc_tree_rotate_left(parent, grandpa);
break;
}
}
}
tree_root_priv(us)->color=usrtc_black;
tree_root_priv(us)->color = usrtc_black;
}
static void redblack_delete(usrtc_t *us,usrtc_node_t *node)
static void redblack_delete(usrtc_t *us, usrtc_node_t *node)
{
usrtc_node_t *swap;
usrtc_node_t *child;
usrtc_rb_color_t savecolor;
/*basic bt delete*/
usrtc_tree_delete(us,node,&swap,&child);
/*implementation specific deletion*/
savecolor=node->color;
node->color=swap->color;
swap->color=savecolor;
usrtc_tree_delete(us, node, &swap, &child);
if(node->color==usrtc_black) { /*black*/
/*implementation specific deletion*/
savecolor = node->color;
node->color = swap->color;
swap->color = savecolor;
if(node->color == usrtc_black) { /*black*/
usrtc_node_t *parent;
usrtc_node_t *sister;
tree_root_priv(us)->color=usrtc_red;
tree_root_priv(us)->color = usrtc_red;
while(child->color==usrtc_black) {
parent=child->parent;
if(child==parent->left) {
sister=parent->right;
if(sister==tree_null_priv(us))
return;
while(child->color == usrtc_black) {
parent = child->parent;
if(child == parent->left) {
sister = parent->right;
if(sister == tree_null_priv(us))
return;
if(sister->color==usrtc_red) {
sister->color=usrtc_black;
parent->color=usrtc_red;
usrtc_tree_rotate_left(sister,parent);
sister=parent->right;
if(sister->color == usrtc_red) {
sister->color = usrtc_black;
parent->color = usrtc_red;
usrtc_tree_rotate_left(sister, parent);
sister = parent->right;
if(sister==tree_null_priv(us))
return;
}
if(sister->left->color==usrtc_black && sister->right->color==usrtc_black) {
sister->color=usrtc_red;
child=parent;
} else {
if(sister->right->color==usrtc_black) {
if(sister->left->color!=usrtc_red)
return;
if(sister == tree_null_priv(us))
return;
}
if((sister->left->color == usrtc_black) &&
(sister->right->color == usrtc_black)) {
sister->color = usrtc_red;
child = parent;
} else {
if(sister->right->color == usrtc_black) {
if(sister->left->color != usrtc_red)
return;
sister->left->color=usrtc_black;
sister->color=usrtc_red;
usrtc_tree_rotate_right(sister->left,sister);
sister=parent->right;
sister->left->color = usrtc_black;
sister->color = usrtc_red;
usrtc_tree_rotate_right(sister->left, sister);
sister = parent->right;
if(sister==tree_null_priv(us))
return;
}
sister->color=parent->color;
sister->right->color=usrtc_black;
parent->color=usrtc_black;
usrtc_tree_rotate_left(sister,parent);
break;
}
if(sister == tree_null_priv(us))
return;
}
sister->color = parent->color;
sister->right->color = usrtc_black;
parent->color = usrtc_black;
usrtc_tree_rotate_left(sister, parent);
break;
}
} else { /*!child == child->parent->right*/
if(child!=parent->right)
return;
if(child != parent->right)
return;
sister=parent->left;
sister = parent->left;
if(sister==tree_null_priv(us))
return;
if(sister == tree_null_priv(us))
return;
if(sister->color==usrtc_red) {
sister->color=usrtc_black;
parent->color=usrtc_red;
usrtc_tree_rotate_right(sister,parent);
sister = parent->left;
if(sister->color == usrtc_red) {
sister->color = usrtc_black;
parent->color = usrtc_red;
usrtc_tree_rotate_right(sister, parent);
sister = parent->left;
if(sister==tree_null_priv(us))
return;
}
if(sister->right->color==usrtc_black && sister->left->color==usrtc_black) {
sister->color=usrtc_red;
child=parent;
} else {
if(sister->left->color == usrtc_black) {
if(sister->right->color!=usrtc_red)
return;
if(sister == tree_null_priv(us))
return;
}
if((sister->right->color == usrtc_black) &&
(sister->left->color == usrtc_black)) {
sister->color = usrtc_red;
child = parent;
} else {
if(sister->left->color == usrtc_black) {
if(sister->right->color != usrtc_red)
return;
sister->right->color=usrtc_black;
sister->color=usrtc_red;
usrtc_tree_rotate_left(sister->right, sister);
sister=parent->left;
sister->right->color = usrtc_black;
sister->color = usrtc_red;
usrtc_tree_rotate_left(sister->right, sister);
sister = parent->left;
if(sister==tree_null_priv(us))
return;
}
sister->color=parent->color;
sister->left->color=usrtc_black;
parent->color=usrtc_black;
usrtc_tree_rotate_right(sister,parent);
break;
}
if(sister == tree_null_priv(us))
return;
}
sister->color = parent->color;
sister->left->color = usrtc_black;
parent->color = usrtc_black;
usrtc_tree_rotate_right(sister, parent);
break;
}
}
}
child->color=usrtc_black;
tree_root_priv(us)->color=usrtc_black;
child->color = usrtc_black;
tree_root_priv(us)->color = usrtc_black;
}
return;
}
static void redblack_convert_from_list(usrtc_t *us)
{
usrtc_node_t *tree[TREE_DEPTH_MAX] = { NULL };
usrtc_node_t *curr;
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *next;
usrtc_node_t *complete=NULL;
usrtc_count_t fullcount=(usrtc_count_t)USRTC_COUNT_T_MAX;
usrtc_count_t nodecount=us->nodecount;
usrtc_node_t *complete = NULL;
usrtc_count_t fullcount = (usrtc_count_t) USRTC_COUNT_T_MAX;
usrtc_count_t nodecount = us->nodecount;
usrtc_count_t botrowcount;
unsigned int baselevel=0;
unsigned int level=0;
unsigned int baselevel = 0;
unsigned int level = 0;
unsigned int i;
if(usrtc_red!=0 && usrtc_black!=1)
if((usrtc_red!=0) && (usrtc_black != 1))
return;
while(fullcount>=nodecount && fullcount) /*calc*/
while((fullcount >= nodecount) && fullcount) /*calc*/
fullcount >>= 1;
botrowcount=nodecount-fullcount;
botrowcount = nodecount-fullcount;
for(curr=nil->next;curr!=nil;curr=next) {
for(curr = nil->next; curr!=nil; curr=next) {
next=curr->next;
if(complete==NULL && botrowcount--==0) {
baselevel=level=1;
complete=tree[0];
if((complete == NULL) && (botrowcount-- == 0)) {
baselevel = level = 1;
complete = tree[0];
if(complete!=NULL) {
tree[0]=NULL;
complete->right=nil;
while(tree[level]!=0) {
tree[level]->right=complete;
complete->parent=tree[level];
complete=tree[level];
tree[level++]=NULL;
}
if(complete != NULL) {
tree[0] = NULL;
complete->right = nil;
while(tree[level] != 0) {
tree[level]->right = complete;
complete->parent = tree[level];
complete = tree[level];
tree[level++] = NULL;
}
}
}
if(complete==NULL) {
curr->left=nil;
curr->right=nil;
curr->color=level%2;
complete=curr;
if(complete == NULL) {
curr->left = nil;
curr->right = nil;
curr->color = level%2;
complete = curr;
if(level!=baselevel)
return;
if(level != baselevel)
return;
while(tree[level]!=NULL) {
tree[level]->right=complete;
complete->parent=tree[level];
complete=tree[level];
tree[level++]=NULL;
while(tree[level] != NULL) {
tree[level]->right = complete;
complete->parent = tree[level];
complete = tree[level];
tree[level++] = NULL;
}
} else {
curr->left=complete;
curr->color=(level+1)%2;
complete->parent=curr;
tree[level]=curr;
complete=NULL;
level=baselevel;
curr->left = complete;
curr->color = (level + 1)%2;
complete->parent = curr;
tree[level] = curr;
complete = NULL;
level = baselevel;
}
}
if(complete==NULL)
complete=nil;
if(complete == NULL)
complete = nil;
for (i=0;i<TREE_DEPTH_MAX;i++) {
if (tree[i]!=NULL) {
tree[i]->right=complete;
complete->parent=tree[i];
complete=tree[i];
for (i = 0; i < TREE_DEPTH_MAX; i++) {
if (tree[i] != NULL) {
tree[i]->right = complete;
complete->parent = tree[i];
complete = tree[i];
}
}
nil->right=nil;
nil->left=complete;
nil->color=usrtc_black;
complete->parent=nil;
complete->color=usrtc_black;
nil->right = nil;
nil->left = complete;
nil->color = usrtc_black;
complete->parent = nil;
complete->color = usrtc_black;
return;
}

View File

@ -22,121 +22,132 @@
#include <tdata/tree.h>
/*prototypes*/
static void splay_insert(usrtc_t *,usrtc_node_t *,const void *);
static void splay_delete(usrtc_t *,usrtc_node_t *);
static usrtc_node_t *splay_lookup(usrtc_t *,const void *);
static void splay_insert(usrtc_t *, usrtc_node_t *, const void *);
static void splay_delete(usrtc_t *, usrtc_node_t *);
static usrtc_node_t *splay_lookup(usrtc_t *, const void *);
usrtc_functions_t usrtc_splay_fu = {
usrtc_tree_init,
splay_insert,
splay_delete,
splay_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
usrtc_tree_convert_from_list,
usrtc_bst
usrtc_tree_init,
splay_insert,
splay_delete,
splay_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
usrtc_tree_convert_from_list,
usrtc_bst
};
static void right_zig_zig(usrtc_node_t *,usrtc_node_t *,usrtc_node_t *);
static void left_zig_zig(usrtc_node_t *,usrtc_node_t *,usrtc_node_t *);
static void right_zig_zag(usrtc_node_t *,usrtc_node_t *,usrtc_node_t *);
static void left_zig_zag(usrtc_node_t *,usrtc_node_t *,usrtc_node_t *);
static void splay_node(usrtc_t *,usrtc_node_t *);
static void right_zig_zig(usrtc_node_t *, usrtc_node_t *, usrtc_node_t *);
static void left_zig_zig(usrtc_node_t *, usrtc_node_t *, usrtc_node_t *);
static void right_zig_zag(usrtc_node_t *, usrtc_node_t *, usrtc_node_t *);
static void left_zig_zag(usrtc_node_t *, usrtc_node_t *, usrtc_node_t *);
static void splay_node(usrtc_t *, usrtc_node_t *);
/*implementation*/
static void splay_insert(usrtc_t *us,usrtc_node_t *node,const void *key)
static void splay_insert(usrtc_t *us, usrtc_node_t *node, const void *key)
{
usrtc_tree_insert(us,node,key);
while(node!=tree_root_priv(us))
splay_node(us,node);
usrtc_tree_insert(us, node, key);
while(node != tree_root_priv(us))
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_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)
{
usrtc_node_t *node=usrtc_tree_lookup(us,key);
usrtc_node_t *node=usrtc_tree_lookup(us, key);
if(node)
while(node!=tree_root_priv(us))
splay_node(us,node);
while(node != tree_root_priv(us))
splay_node(us, 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(child,parent);
usrtc_tree_rotate_right(parent, grandpa);
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(child,parent);
usrtc_tree_rotate_left(parent, grandpa);
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_left(child,grandpa);
usrtc_tree_rotate_right(child, parent);
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_right(child,grandpa);
usrtc_tree_rotate_left(child, parent);
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)
{
usrtc_node_t *root=tree_root_priv(us);
usrtc_node_t *parent=node->parent;
if(parent->left==node) {
if(parent==root) {
usrtc_tree_rotate_right(node,parent);
usrtc_node_t *root = tree_root_priv(us);
usrtc_node_t *parent = node->parent;
if(parent->left == node) {
if(parent == root) {
usrtc_tree_rotate_right(node, parent);
} else {
usrtc_node_t *grandpa=parent->parent;
if(grandpa->left==parent)
right_zig_zig(node,parent,grandpa);
else {
if(grandpa->right!=parent)
return;
usrtc_node_t *grandpa = parent->parent;
right_zig_zag(node,parent,grandpa);
if(grandpa->left == parent)
right_zig_zig(node, parent, grandpa);
else {
if(grandpa->right != parent)
return;
right_zig_zag(node, parent, grandpa);
}
}
} else {
if(parent->right!=node)
if(parent->right != node)
return;
if(parent==root) {
usrtc_tree_rotate_left(node,parent);
} else {
usrtc_node_t *grandpa=parent->parent;
if(grandpa->right==parent) {
left_zig_zig(node,parent,grandpa);
} else {
if(grandpa->left!=parent)
return;
left_zig_zag(node,parent,grandpa);
if(parent == root) {
usrtc_tree_rotate_left(node, parent);
} else {
usrtc_node_t *grandpa = parent->parent;
if(grandpa->right == parent) {
left_zig_zig(node, parent, grandpa);
} else {
if(grandpa->left != parent)
return;
left_zig_zag(node, parent, grandpa);
}
}
}
return;
}

View File

@ -27,104 +27,107 @@
static void tree_delete(usrtc_t *, usrtc_node_t *);
usrtc_functions_t usrtc_tree_fu = {
usrtc_tree_init,
usrtc_tree_insert,
tree_delete,
usrtc_tree_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
usrtc_tree_convert_from_list,
usrtc_bst
usrtc_tree_init,
usrtc_tree_insert,
tree_delete,
usrtc_tree_lookup,
usrtc_tree_lower_bound,
usrtc_tree_upper_bound,
usrtc_tree_first,
usrtc_tree_last,
usrtc_tree_next,
usrtc_tree_prev,
usrtc_tree_convert_to_list,
usrtc_tree_convert_from_list,
usrtc_bst
};
/*implementation*/
void usrtc_tree_init(usrtc_t *us)
{
us->sentinel.left=&us->sentinel;
us->sentinel.right=&us->sentinel;
us->sentinel.parent=&us->sentinel;
us->sentinel.left = &us->sentinel;
us->sentinel.right = &us->sentinel;
us->sentinel.parent = &us->sentinel;
us->sentinel.impl_specific.usrtc_dummy=0;
us->sentinel.data=0;
us->sentinel.key=0;
us->sentinel.impl_specific.usrtc_dummy = 0;
us->sentinel.data = 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)
{
usrtc_node_t *where=tree_root_priv(us);
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *parent=nil;
long res=-1;
usrtc_node_t *where = tree_root_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *parent = nil;
long res = -1;
node->key=key;
node->key = key;
while(where!=nil) {
parent=where;
res=us->compare(key,where->key);
while(where != nil) {
parent = where;
res = us->compare(key, where->key);
if(us->dupes_allowed && !res) /*trying to put duplicate to the disabled dupe tree*/
return;
if(res<0)
where=where->left;
where = where->left;
else
where=where->right;
where = where->right;
}
/*assert(where==nil);*/
if(res<0)
parent->left=node;
if(res < 0)
parent->left = node;
else
parent->right=node;
parent->right = node;
node->parent=parent;
node->left=nil;
node->right=nil;
node->parent = parent;
node->left = nil;
node->right = nil;
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 *delparent=node->parent;
usrtc_node_t *next=node;
usrtc_node_t *delparent = node->parent;
usrtc_node_t *next = node;
usrtc_node_t *nextparent;
if(node->left!=nil && node->right!=nil) {
next=usrtc_tree_next(us,node);
nextparent=next->parent;
if(node->left != nil && node->right != nil) {
next = usrtc_tree_next(us, node);
nextparent = next->parent;
/*if(next!=nil && next->parent!=nil && next->parent==nil)
return;*/
child=next->right;
child->parent=nextparent;
child = next->right;
child->parent = nextparent;
if(nextparent->left==next)
nextparent->left=child;
if(nextparent->left == next)
nextparent->left = child;
else {
//if(nextparent->right!=next)
//return;
nextparent->right=child;
nextparent->right = child;
}
next->parent=delparent;
next->left=node->left;
next->right=node->right;
next->left->parent=next;
next->right->parent=next;
next->parent = delparent;
next->left = node->left;
next->right = node->right;
next->left->parent = next;
next->right->parent = next;
if(delparent->left==node) {
delparent->left=next;
if(delparent->left == node) {
delparent->left = next;
} else {
//if(delparent->right!=node)
// return;
@ -134,55 +137,57 @@ void usrtc_tree_delete(usrtc_t *us,usrtc_node_t *node,usrtc_node_t **pswap,usrtc
} else {
/*if(node==nil)
return;
if(node->left!=nil && node->right!=nil)
return;*/
if(node->left!=nil && node->right!=nil)
return;*/
child=(node->left!=nil) ? node->left : node->right;
child = (node->left != nil) ? node->left : node->right;
child->parent=delparent=node->parent;
child->parent = delparent = node->parent;
if(node==delparent->left) {
delparent->left=child;
if(node == delparent->left) {
delparent->left = child;
} else {
/*if(node!=delparent->right)
return;*/
delparent->right=child;
return;*/
delparent->right = child;
}
}
node->parent=0;
node->right=0;
node->left=0;
node->parent = NULL;
node->right = NULL;
node->left = NULL;
us->nodecount--;
*pswap = next;
*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)
{
usrtc_node_t *root=tree_root_priv(us);
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *root = tree_root_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *saved;
long res;
while (root!=nil) {
res=us->compare(key,root->key);
if(res<0)
root=root->left;
else if(res>0)
root=root->right;
while (root != nil) {
res = us->compare(key, root->key);
if(res < 0)
root = root->left;
else if(res > 0)
root = root->right;
else {
if(!us->dupes_allowed)
return root; /*no duplicates*/
else { /*duplicate, then find left occurence*/
do {
saved=root;
root=root->left;
while(root!=nil && us->compare(key,root->key))
root=root->right;
} while(root!=nil);
saved = root;
root = root->left;
while(root!=nil && us->compare(key, root->key))
root = root->right;
} while(root != nil);
return saved;
}
}
@ -191,27 +196,27 @@ usrtc_node_t *usrtc_tree_lookup(usrtc_t *us,const void *key)
return NULL;
}
usrtc_node_t *usrtc_tree_lower_bound(usrtc_t *us,const void *key)
usrtc_node_t *usrtc_tree_lower_bound(usrtc_t *us, const void *key)
{
usrtc_node_t *root=tree_root_priv(us);
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *tentative=NULL;
usrtc_node_t *root = tree_root_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *tentative = NULL;
long res;
while(root!=nil) {
res=us->compare(key,root->key);
while(root != nil) {
res = us->compare(key, root->key);
if(res>0) {
root=root->right;
} else if(res<0) {
tentative=root;
root=root->left;
if(res > 0) {
root = root->right;
} else if(res < 0) {
tentative = root;
root = root->left;
} else {
if (!us->dupes_allowed)
return root;
else {
tentative=root;
root=root->left;
tentative = root;
root = root->left;
}
}
}
@ -219,27 +224,27 @@ usrtc_node_t *usrtc_tree_lower_bound(usrtc_t *us,const void *key)
return tentative;
}
usrtc_node_t *usrtc_tree_upper_bound(usrtc_t *us,const void *key)
usrtc_node_t *usrtc_tree_upper_bound(usrtc_t *us, const void *key)
{
usrtc_node_t *root=tree_root_priv(us);
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *tentative=NULL;
usrtc_node_t *root = tree_root_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *tentative = NULL;
long res;
while(root!=nil) {
res=us->compare(key,root->key);
while(root != nil) {
res = us->compare(key, root->key);
if(res>0) {
root=root->left;
} else if(res<0) {
tentative=root;
root=root->right;
if(res > 0) {
root = root->left;
} else if(res < 0) {
tentative = root;
root = root->right;
} else {
if (!us->dupes_allowed)
return root;
else {
tentative=root;
root=root->right;
tentative = root;
root = root->right;
}
}
}
@ -262,61 +267,61 @@ usrtc_node_t *usrtc_tree_first(usrtc_t *us)
usrtc_node_t *usrtc_tree_last(usrtc_t *us)
{
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *root=tree_root_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *root = tree_root_priv(us);
usrtc_node_t *right;
if(root!=nil)
while((right=root->right)!=nil)
root=right;
if(root != nil)
while((right = root->right) != nil)
root = right;
return (root==nil) ? NULL : root;
return (root == nil) ? NULL : root;
}
usrtc_node_t *usrtc_tree_next(usrtc_t *us, usrtc_node_t *curr)
{
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *parent;
usrtc_node_t *left;
if(curr->right!=nil) {
curr=curr->right;
while((left=curr->left)!=nil)
curr=left;
if(curr->right != nil) {
curr = curr->right;
while((left = curr->left) != nil)
curr = left;
return curr;
}
parent=curr->parent;
parent = curr->parent;
while(parent!=nil && curr==parent->right) {
curr=parent;
parent=curr->parent;
while((parent != nil) && (curr == parent->right)) {
curr = parent;
parent = curr->parent;
}
return (parent==nil) ? NULL : parent;
return (parent == nil) ? NULL : parent;
}
usrtc_node_t *usrtc_tree_prev(usrtc_t *us, usrtc_node_t *curr)
{
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *parent;
usrtc_node_t *right;
if(curr->left!=nil) {
curr=curr->left;
while((right=curr->right)!=nil)
curr=right;
if(curr->left != nil) {
curr = curr->left;
while((right = curr->right) != nil)
curr = right;
return curr;
}
parent=curr->parent;
parent = curr->parent;
while(parent!=nil && curr==parent->left) {
curr=parent;
parent=curr->parent;
while((parent != nil) && (curr == parent->left)) {
curr = parent;
parent = curr->parent;
}
return (parent==nil) ? NULL : parent;
return (parent == nil) ? NULL : parent;
}
/*uff, convertation between trees and lists*/
@ -324,161 +329,167 @@ void usrtc_tree_convert_to_list(usrtc_t *us)
{
usrtc_node_t *node;
usrtc_node_t tempsentinel;
usrtc_node_t *nil=&tempsentinel;
usrtc_node_t *tail,*next;
usrtc_node_t *treenil=tree_null_priv(us);
usrtc_node_t *nil = &tempsentinel;
usrtc_node_t *tail, *next;
usrtc_node_t *treenil = tree_null_priv(us);
if(us->nodecount==0) /* no nodes */
if(us->nodecount == 0) /* no nodes */
return;
tempsentinel.next=nil;
tempsentinel.prev=nil;
tempsentinel.next = nil;
tempsentinel.prev = nil;
/* two passes */
for(tail=nil,node=usrtc_tree_first(us);node!=0;tail=node,node=next) {
next=usrtc_tree_next(us,node);
node->prev=tail;
for(tail = nil, node = usrtc_tree_first(us); node != 0; tail = node,
node = next) {
next = usrtc_tree_next(us, node);
node->prev = tail;
}
nil->prev=tail;
nil->prev = tail;
for(tail=nil,node=nil->prev;node!=nil;tail=node,node=node->prev)
node->next=tail;
for(tail = nil, node = nil->prev; node != nil; tail = node,
node = node->prev)
node->next = tail;
nil->next=tail;
nil->next = tail;
us->sentinel.next=tempsentinel.next;
us->sentinel.prev=tempsentinel.prev;
us->sentinel.next->prev=treenil;
us->sentinel.prev->next=treenil;
us->sentinel.next = tempsentinel.next;
us->sentinel.prev = tempsentinel.prev;
us->sentinel.next->prev = treenil;
us->sentinel.prev->next = treenil;
return;
}
void usrtc_tree_convert_from_list(usrtc_t *us)
{
usrtc_node_t *tree[TREE_DEPTH_MAX]={ 0 };
usrtc_node_t *tree[TREE_DEPTH_MAX] = { 0 };
usrtc_node_t *curr;
usrtc_node_t *nil=tree_null_priv(us);
usrtc_node_t *nil = tree_null_priv(us);
usrtc_node_t *next;
usrtc_node_t *complete=NULL;
usrtc_count_t fullcount=(usrtc_count_t)USRTC_COUNT_T_MAX;
usrtc_count_t nodecount=us->nodecount;
usrtc_node_t *complete = NULL;
usrtc_count_t fullcount = (usrtc_count_t)USRTC_COUNT_T_MAX;
usrtc_count_t nodecount = us->nodecount;
usrtc_count_t botrowcount;
int baselevel=0;
int level=0;
int i=0;
int baselevel = 0;
int level = 0;
int i = 0;
while (fullcount>=nodecount && fullcount) /* calc */
fullcount>>=1;
while ((fullcount >= nodecount) && fullcount) /* calc */
fullcount >>= 1;
botrowcount=nodecount-fullcount;
botrowcount = nodecount - fullcount;
for(curr=nil->next;curr!=nil;curr=next) {
next=curr->next;
for(curr = nil->next; curr != nil; curr = next) {
next = curr->next;
if(complete==NULL && botrowcount-- ==0) {
baselevel=level=1;
complete=tree[0];
if((complete == NULL) && (botrowcount-- == 0)) {
baselevel = level = 1;
complete = tree[0];
if(complete!=NULL) {
tree[0]=0;
complete->right=nil;
while(tree[level]!=NULL) {
tree[level]->right=complete;
complete->parent=tree[level];
complete=tree[level];
tree[level++]=0;
if(complete != NULL) {
tree[0] = 0;
complete->right = nil;
while(tree[level] != NULL) {
tree[level]->right = complete;
complete->parent = tree[level];
complete = tree[level];
tree[level++] = 0;
}
}
}
if(complete==NULL) {
curr->left=nil;
curr->right=nil;
complete=curr;
if(complete == NULL) {
curr->left = nil;
curr->right = nil;
complete = curr;
if(level!=baselevel)
if(level != baselevel)
return;
while(tree[level]!=NULL) {
tree[level]->right=complete;
complete->parent=tree[level];
complete=tree[level];
tree[level++]=0;
while(tree[level] != NULL) {
tree[level]->right = complete;
complete->parent = tree[level];
complete = tree[level];
tree[level++] = 0;
}
} else {
curr->left=complete;
complete->parent=curr;
tree[level]=curr;
complete=NULL;
level=baselevel;
curr->left = complete;
complete->parent = curr;
tree[level] = curr;
complete = NULL;
level = baselevel;
}
}
if(complete==NULL)
complete=nil;
if(complete == NULL)
complete = nil;
for(i=0;i<TREE_DEPTH_MAX;i++) {
if(tree[i]!=NULL) {
tree[i]->right=complete;
complete->parent=tree[i];
complete=tree[i];
for(i = 0; i < TREE_DEPTH_MAX; i++) {
if(tree[i] != NULL) {
tree[i]->right = complete;
complete->parent = tree[i];
complete = tree[i];
}
}
nil->right=nil;
nil->left=complete;
complete->parent=nil;
nil->right = nil;
nil->left = complete;
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)
{
usrtc_node_t *leftgrandchild;
usrtc_node_t *grandpa;
if(parent->right!=child)
if(parent->right != child)
return;
child=parent->right;
parent->right=leftgrandchild=child->left;
leftgrandchild->parent=parent;
child = parent->right;
parent->right = leftgrandchild = child->left;
leftgrandchild->parent = parent;
child->parent=grandpa=parent->parent;
child->parent = grandpa = parent->parent;
if(parent==grandpa->left) {
if(parent == grandpa->left) {
grandpa->left=child;
} else {
if(parent!=grandpa->right)
if(parent != grandpa->right)
return;
grandpa->right=child;
grandpa->right = child;
}
child->left=parent;
parent->parent=child;
child->left = parent;
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)
{
usrtc_node_t *rightgrandchild;
usrtc_node_t *grandpa;
if(parent->left!=child)
if(parent->left != child)
return;
parent->left=rightgrandchild=child->right;
rightgrandchild->parent=parent;
parent->left = rightgrandchild = child->right;
rightgrandchild->parent = parent;
child->parent=grandpa=parent->parent;
child->parent = grandpa = parent->parent;
if(parent==grandpa->right) {
grandpa->right=child;
if(parent == grandpa->right) {
grandpa->right = child;
} else {
if(parent!=grandpa->left)
if(parent != grandpa->left)
return;
grandpa->left=child;
grandpa->left = child;
}
child->right=parent;
parent->parent=child;
child->right = parent;
parent->parent = child;
return;
}
/* local functions */

View File

@ -46,36 +46,40 @@ static usrtc_node_t *default_node_alloc(void *context)
return malloc(sizeof *default_node_alloc(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);
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)
return;
if(impl>MAX_IMPL)
return;
us->nodecount=0;
us->maxcount=maxcount;
us->dupes_allowed=0;
us->compare=compare;
us->node_alloc=default_node_alloc;
us->node_free=default_node_free;
us->context=0;
us->futable=impl_table[impl];
us->nodecount = 0;
us->maxcount = maxcount;
us->dupes_allowed = 0;
us->compare = compare;
us->node_alloc = default_node_alloc;
us->node_free = default_node_free;
us->context = 0;
us->futable = impl_table[impl];
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);
if(newrtc)
usrtc_init(newrtc,impl,maxcount,compare);
usrtc_init(newrtc, impl, maxcount, compare);
return newrtc;
}
@ -86,25 +90,28 @@ void usrtc_destroy(usrtc_t *us)
return;
free(us);
return;
}
void usrtc_convert_to(usrtc_t *us,int impl)
{
if(impl_table[impl]==us->futable)
if(impl_table[impl] == us->futable)
return;
if(us->futable->usrtc_type==usrtc_bst && (impl==USRTC_BST || impl==USRTC_SPLAY)) {
us->futable=impl_table[impl];
if((us->futable->usrtc_type == usrtc_bst) &&
(impl == USRTC_BST || impl == USRTC_SPLAY)) {
us->futable = impl_table[impl];
return;
}
us->futable->usrtc_convert_to_list(us);
us->futable=impl_table[impl];
us->futable = impl_table[impl];
if(impl_table[impl]->usrtc_type==usrtc_lst)
if(impl_table[impl]->usrtc_type == usrtc_lst)
return;
us->futable->usrtc_convert_from_list(us);
return;
}
usrtc_count_t usrtc_count(usrtc_t *us)
@ -122,29 +129,32 @@ int usrtc_isfull(usrtc_t *us)
return us->nodecount == us->maxcount;
}
int usrtc_alloc_insert(usrtc_t *us,const void *key,void *data)
int usrtc_alloc_insert(usrtc_t *us, const void *key, void *data)
{
usrtc_node_t *newnode=us->node_alloc(us->context);
if(newnode!=NULL) {
newnode->data=data;
us->futable->usrtc_insert(us,newnode,key);
usrtc_node_t *newnode = us->node_alloc(us->context);
if(newnode != NULL) {
newnode->data = data;
us->futable->usrtc_insert(us, newnode, key);
}
return newnode!=NULL;
return newnode != NULL;
}
void usrtc_delete_free(usrtc_t *us,usrtc_node_t *node)
void usrtc_delete_free(usrtc_t *us, usrtc_node_t *node)
{
us->futable->usrtc_delete(us,node);
us->node_free(us->context,node);
us->futable->usrtc_delete(us, 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_free=n_free;
us->context=context;
us->node_alloc = alloc;
us->node_free = n_free;
us->context = context;
return;
}
void usrtc_allow_dupes(usrtc_t *us)
@ -153,31 +163,33 @@ void usrtc_allow_dupes(usrtc_t *us)
if(!us->nodecount)
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)
{
node->data=data;
node->impl_specific.usrtc_dummy=0;
node->left=NULL;
node->right=NULL;
node->parent=NULL;
node->data = data;
node->impl_specific.usrtc_dummy = 0;
node->left = NULL;
node->right = NULL;
node->parent = NULL;
}
usrtc_node_t *usrtc_node_create(void *data)
{
usrtc_node_t *newnode=(usrtc_node_t*)malloc(sizeof *newnode);
if(newnode!=NULL)
newnode->data=data;
usrtc_node_t *newnode = (usrtc_node_t *) malloc(sizeof *newnode);
if(newnode != NULL)
newnode->data = data;
return newnode;
}
void usrtc_node_destroy(usrtc_node_t *node)
{
free(node);
return;
}
void *usrtc_node_getdata(usrtc_node_t *node)
@ -185,9 +197,10 @@ void *usrtc_node_getdata(usrtc_node_t *node)
return node->data;
}
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)
@ -195,29 +208,31 @@ const void *usrtc_node_getkey(usrtc_node_t *node)
return node->key;
}
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)
{
return us->futable->usrtc_lookup(us,key);
return us->futable->usrtc_lookup(us, key);
}
usrtc_node_t *usrtc_lower_bound(usrtc_t *us,const void *key)
usrtc_node_t *usrtc_lower_bound(usrtc_t *us, const void *key)
{
return us->futable->usrtc_lower_bound(us,key);
return us->futable->usrtc_lower_bound(us, key);
}
usrtc_node_t *usrtc_upper_bound(usrtc_t *us,const void *key)
usrtc_node_t *usrtc_upper_bound(usrtc_t *us, const void *key)
{
return us->futable->usrtc_upper_bound(us,key);
return us->futable->usrtc_upper_bound(us, key);
}
usrtc_node_t *usrtc_first(usrtc_t *us)
@ -230,14 +245,13 @@ usrtc_node_t *usrtc_last(usrtc_t *us)
return us->futable->usrtc_last(us);
}
usrtc_node_t *usrtc_next(usrtc_t *us,usrtc_node_t *node)
usrtc_node_t *usrtc_next(usrtc_t *us, usrtc_node_t *node)
{
return us->futable->usrtc_next(us,node);
return us->futable->usrtc_next(us, node);
}
usrtc_node_t *usrtc_prev(usrtc_t *us,usrtc_node_t *node)
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);
}

2
man/Makefile.am Normal file
View File

@ -0,0 +1,2 @@
man_MANS = usrtc_init.3 usrtc_create.3 usrtc_destroy.3

24
man/reference-template.3 Normal file
View File

@ -0,0 +1,24 @@
.TH @F_BLOCK@ 3 "@DoM@ @MONTH@ @YEAR@" "LIBTDATA" "Portable data structures C library manual"
.SH NAME
.br
.SH SYNOPSYS
.br
.SH DESCRIPTION
.br
.SH RETURN VALUE
.br
.SH BUGS
.br
.SH EXAMPLE
.br
.SH RATIONALE
.br
.SH SEE ALSO
.br
.SH COPYRIGHT
This software licensed under GNU LGPL v2.1 or later. See COPYING for further details.
.br
(c) Authors of libtdata. See AUTHORS for further details.
.SH AUTHOR
@GIT_NAME@ (@GIT_EMAIL@)
.br

1
man/usrtc_create.3 Symbolic link
View File

@ -0,0 +1 @@
usrtc_init.3

1
man/usrtc_destroy.3 Symbolic link
View File

@ -0,0 +1 @@
usrtc_init.3

87
man/usrtc_init.3 Normal file
View File

@ -0,0 +1,87 @@
.TH USRTC_INIT 3 "21 May 2019" "LIBTDATA" "Portable data structures C library manual"
.SH NAME
usrtc_init \- Initialize usrtc core structure
.br
usrtc_create \- Allocate and initialize usrtc core structure
.br
usrtc_destroy \- Destroy (free) usrtc core structure
.br
.SH SYNOPSYS
.B #include <tdata/usrtc.h>
.sp
void usrtc_init(usrtc_t *us, int impl, usrtc_count_t maxcount, usrtc_compare_t compare);
usrtc_t *usrtc_create(int impl, usrtc_count_t maxcount, usrtc_compare_t compare);
void usrtc_destroy(usrtc_t *us);
typedef long (*usrtc_compare_t)(const void*, const void*);
.br
.sp
.SH DESCRIPTION
.B usrtc_init
and
.B usrtc_create
are used to initialize a new usrtc core structure. The difference is
.B usrtc_create
will allocate
.B usrtc_t
structure via
.B malloc()
function, but
.B usrtc_init
expect already allocated structure. Argument
.B impl
is used to point the type of search data structure used for this particular usrtc core structure. Possible values are:
.br
.B * USRTC_LIST:
Linked list
.br
.B * USRTC_BST:
Binary search tree
.br
.B * USRTC_REDBLACK:
Redblack tree
.br
.B * USRTC_SPLAY:
Splay tree
.br
.B * USRTC_AVL:
AVL tree
.br
.B maxcount
argument is pointing to a max amount of the nodes within a search data structure.
.B compare
is a pointer to a compare function.
.br
.B usrtc_destroy
is used to destroy (free) usrtc core structure. This function must be used only for structures allocated via
.B usrtc_create
function.
.br
.SH RETURN VALUE
Valid pointer to a newly allocated and initialized core structure, otherwise
.B NULL.
.br
.SH BUGS
Not known yet.
.br
.SH EXAMPLE
.br
.SH RATIONALE
Using functions
.B usrtc_create
and
.B usrtc_destroy
is deprecating.
.br
.SH SEE ALSO
.br
.SH COPYRIGHT
This software licensed under GNU LGPL v2.1 or later. See COPYING for further details.
.br
(c) Authors of libtdata. See AUTHORS for further details.
.SH AUTHOR
Alexander Vdolainen (alex@vapaa.xyz)
.br