Compare commits
No commits in common. "master" and "0.2.4" have entirely different histories.
@ -7,7 +7,7 @@ if BUILD_TESTS
|
|||||||
EXTRA += tests
|
EXTRA += tests
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SUBDIRS = include lib man $(EXTRA)
|
SUBDIRS = include lib $(EXTRA)
|
||||||
|
|
||||||
libtdatadocdir = ${prefix}/doc/libtdata
|
libtdatadocdir = ${prefix}/doc/libtdata
|
||||||
libtdatadoc_DATA = \
|
libtdatadoc_DATA = \
|
||||||
|
@ -62,5 +62,4 @@ Makefile
|
|||||||
lib/libtdata.pc
|
lib/libtdata.pc
|
||||||
lib/Makefile
|
lib/Makefile
|
||||||
tests/Makefile
|
tests/Makefile
|
||||||
include/Makefile
|
include/Makefile])
|
||||||
man/Makefile])
|
|
||||||
|
1
debian/.gitignore
vendored
1
debian/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
.debhelper
|
|
6
debian/README.Debian
vendored
6
debian/README.Debian
vendored
@ -1,6 +0,0 @@
|
|||||||
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
9
debian/README.source
vendored
@ -1,9 +0,0 @@
|
|||||||
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
6
debian/changelog
vendored
@ -1,6 +0,0 @@
|
|||||||
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
1
debian/compat
vendored
@ -1 +0,0 @@
|
|||||||
8
|
|
23
debian/control
vendored
23
debian/control
vendored
@ -1,23 +0,0 @@
|
|||||||
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
38
debian/copyright
vendored
@ -1,38 +0,0 @@
|
|||||||
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
2
debian/docs
vendored
@ -1,2 +0,0 @@
|
|||||||
NEWS
|
|
||||||
README
|
|
13
debian/rules
vendored
13
debian/rules
vendored
@ -1,13 +0,0 @@
|
|||||||
#!/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
|
|
@ -26,7 +26,10 @@
|
|||||||
typedef unsigned long usrtc_count_t;
|
typedef unsigned long usrtc_count_t;
|
||||||
typedef unsigned int usrtc_impl_id_t;
|
typedef unsigned int usrtc_impl_id_t;
|
||||||
|
|
||||||
/* implementation's typedefs */
|
/* implementations ids,
|
||||||
|
* if you want to add some
|
||||||
|
* add the id here, don't forget to do it.
|
||||||
|
*/
|
||||||
#define USRTC_LIST 0
|
#define USRTC_LIST 0
|
||||||
#define USRTC_BST 1
|
#define USRTC_BST 1
|
||||||
#define USRTC_REDBLACK 2
|
#define USRTC_REDBLACK 2
|
||||||
@ -99,14 +102,9 @@ typedef struct __usrtc_functions_t {
|
|||||||
usrtc_impltype_t usrtc_type;
|
usrtc_impltype_t usrtc_type;
|
||||||
} usrtc_functions_t;
|
} usrtc_functions_t;
|
||||||
|
|
||||||
/* basic usrtc functions */
|
/*basic rtc functions*/
|
||||||
/* initialize usrtc core structure */
|
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_t *usrtc_create(int impl,usrtc_count_t maxcount,usrtc_compare_t compare);
|
||||||
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_destroy(usrtc_t *us);
|
||||||
|
|
||||||
void usrtc_convert_to(usrtc_t *us,int impl);
|
void usrtc_convert_to(usrtc_t *us,int impl);
|
||||||
|
@ -88,7 +88,7 @@ static void redblack_insert(usrtc_t *us, usrtc_node_t *node, const void *key)
|
|||||||
usrtc_tree_rotate_right(parent,grandpa);
|
usrtc_tree_rotate_right(parent,grandpa);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else { /* parent == parent->parent->right */
|
} else { /*ooh,parent == parent->parent->right*/
|
||||||
usrtc_node_t *uncle=grandpa->left;
|
usrtc_node_t *uncle=grandpa->left;
|
||||||
if(uncle->color==usrtc_red) {
|
if(uncle->color==usrtc_red) {
|
||||||
parent->color=usrtc_black;
|
parent->color=usrtc_black;
|
||||||
@ -151,8 +151,7 @@ static void redblack_delete(usrtc_t *us, usrtc_node_t *node)
|
|||||||
if(sister==tree_null_priv(us))
|
if(sister==tree_null_priv(us))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((sister->left->color == usrtc_black) &&
|
if(sister->left->color==usrtc_black && sister->right->color==usrtc_black) {
|
||||||
(sister->right->color == usrtc_black)) {
|
|
||||||
sister->color=usrtc_red;
|
sister->color=usrtc_red;
|
||||||
child=parent;
|
child=parent;
|
||||||
} else {
|
} else {
|
||||||
@ -192,8 +191,7 @@ static void redblack_delete(usrtc_t *us, usrtc_node_t *node)
|
|||||||
if(sister==tree_null_priv(us))
|
if(sister==tree_null_priv(us))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((sister->right->color == usrtc_black) &&
|
if(sister->right->color==usrtc_black && sister->left->color==usrtc_black) {
|
||||||
(sister->left->color == usrtc_black)) {
|
|
||||||
sister->color=usrtc_red;
|
sister->color=usrtc_red;
|
||||||
child=parent;
|
child=parent;
|
||||||
} else {
|
} else {
|
||||||
@ -221,7 +219,7 @@ static void redblack_delete(usrtc_t *us, usrtc_node_t *node)
|
|||||||
child->color=usrtc_black;
|
child->color=usrtc_black;
|
||||||
tree_root_priv(us)->color=usrtc_black;
|
tree_root_priv(us)->color=usrtc_black;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void redblack_convert_from_list(usrtc_t *us)
|
static void redblack_convert_from_list(usrtc_t *us)
|
||||||
@ -238,10 +236,10 @@ static void redblack_convert_from_list(usrtc_t *us)
|
|||||||
unsigned int level=0;
|
unsigned int level=0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if((usrtc_red!=0) && (usrtc_black != 1))
|
if(usrtc_red!=0 && usrtc_black!=1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while((fullcount >= nodecount) && fullcount) /*calc*/
|
while(fullcount>=nodecount && fullcount) /*calc*/
|
||||||
fullcount >>= 1;
|
fullcount >>= 1;
|
||||||
|
|
||||||
botrowcount=nodecount-fullcount;
|
botrowcount=nodecount-fullcount;
|
||||||
@ -249,7 +247,7 @@ static void redblack_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];
|
||||||
|
|
||||||
@ -307,6 +305,5 @@ static void redblack_convert_from_list(usrtc_t *us)
|
|||||||
complete->parent=nil;
|
complete->parent=nil;
|
||||||
complete->color=usrtc_black;
|
complete->color=usrtc_black;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
lib/splay.c
19
lib/splay.c
@ -56,14 +56,12 @@ 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)
|
||||||
@ -77,36 +75,28 @@ 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,
|
static void right_zig_zig(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa)
|
||||||
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,
|
static void left_zig_zig(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa)
|
||||||
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,
|
static void right_zig_zag(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa)
|
||||||
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,
|
static void left_zig_zag(usrtc_node_t *child,usrtc_node_t *parent,usrtc_node_t *grandpa)
|
||||||
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)
|
||||||
@ -149,5 +139,4 @@ static void splay_node(usrtc_t *us, usrtc_node_t *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
31
lib/tree.c
31
lib/tree.c
@ -53,7 +53,6 @@ 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)
|
||||||
@ -90,11 +89,9 @@ 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,
|
void usrtc_tree_delete(usrtc_t *us,usrtc_node_t *node,usrtc_node_t **pswap,usrtc_node_t **pchild)
|
||||||
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;
|
||||||
@ -153,16 +150,14 @@ void usrtc_tree_delete(usrtc_t *us, usrtc_node_t *node, usrtc_node_t **pswap,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node->parent = NULL;
|
node->parent=0;
|
||||||
node->right = NULL;
|
node->right=0;
|
||||||
node->left = NULL;
|
node->left=0;
|
||||||
|
|
||||||
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)
|
||||||
@ -293,7 +288,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;
|
||||||
}
|
}
|
||||||
@ -316,7 +311,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;
|
||||||
}
|
}
|
||||||
@ -340,16 +335,14 @@ 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,
|
for(tail=nil,node=usrtc_tree_first(us);node!=0;tail=node,node=next) {
|
||||||
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,
|
for(tail=nil,node=nil->prev;node!=nil;tail=node,node=node->prev)
|
||||||
node = node->prev)
|
|
||||||
node->next=tail;
|
node->next=tail;
|
||||||
|
|
||||||
nil->next=tail;
|
nil->next=tail;
|
||||||
@ -358,7 +351,6 @@ 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)
|
||||||
@ -375,7 +367,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;
|
||||||
@ -383,7 +375,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];
|
||||||
|
|
||||||
@ -436,7 +428,6 @@ 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)
|
||||||
@ -463,7 +454,6 @@ 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)
|
||||||
@ -489,7 +479,6 @@ 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 */
|
||||||
|
24
lib/usrtc.c
24
lib/usrtc.c
@ -49,11 +49,9 @@ 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,
|
void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t compare)
|
||||||
usrtc_compare_t compare)
|
|
||||||
{
|
{
|
||||||
if(!us)
|
if(!us)
|
||||||
return;
|
return;
|
||||||
@ -69,11 +67,9 @@ void usrtc_init(usrtc_t *us, int impl, usrtc_count_t maxcount,
|
|||||||
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_t *usrtc_create(int impl,usrtc_count_t maxcount,usrtc_compare_t compare)
|
||||||
usrtc_compare_t compare)
|
|
||||||
{
|
{
|
||||||
usrtc_t *newrtc=(usrtc_t*)malloc(sizeof *newrtc);
|
usrtc_t *newrtc=(usrtc_t*)malloc(sizeof *newrtc);
|
||||||
|
|
||||||
@ -90,7 +86,6 @@ 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)
|
||||||
@ -98,8 +93,7 @@ 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) &&
|
if(us->futable->usrtc_type==usrtc_bst && (impl==USRTC_BST || impl==USRTC_SPLAY)) {
|
||||||
(impl == USRTC_BST || impl == USRTC_SPLAY)) {
|
|
||||||
us->futable=impl_table[impl];
|
us->futable=impl_table[impl];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,7 +105,6 @@ 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)
|
||||||
@ -145,16 +138,13 @@ 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,
|
void usrtc_set_allocator(usrtc_t *us,usrtc_node_alloc_t alloc,usrtc_node_free_t n_free,void *context)
|
||||||
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)
|
||||||
@ -164,7 +154,6 @@ 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)
|
||||||
@ -189,7 +178,6 @@ 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)
|
||||||
@ -200,7 +188,6 @@ 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)
|
||||||
@ -211,13 +198,11 @@ 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)
|
||||||
@ -255,3 +240,4 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
man_MANS = usrtc_init.3 usrtc_create.3 usrtc_destroy.3
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
.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 +0,0 @@
|
|||||||
usrtc_init.3
|
|
@ -1 +0,0 @@
|
|||||||
usrtc_init.3
|
|
@ -1,87 +0,0 @@
|
|||||||
.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
|
|
Loading…
x
Reference in New Issue
Block a user