Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
2759f0da87 | |||
|
dfc1b90513 | ||
|
70072351a2 | ||
|
5a60edd6ef | ||
|
4ab3fc2b3d |
@ -7,7 +7,7 @@ if BUILD_TESTS
|
|||||||
EXTRA += tests
|
EXTRA += tests
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SUBDIRS = include lib $(EXTRA)
|
SUBDIRS = include lib man $(EXTRA)
|
||||||
|
|
||||||
libtdatadocdir = ${prefix}/doc/libtdata
|
libtdatadocdir = ${prefix}/doc/libtdata
|
||||||
libtdatadoc_DATA = \
|
libtdatadoc_DATA = \
|
||||||
|
@ -62,4 +62,5 @@ 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
Normal file
1
debian/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.debhelper
|
6
debian/README.Debian
vendored
Normal file
6
debian/README.Debian
vendored
Normal 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
9
debian/README.source
vendored
Normal 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
6
debian/changelog
vendored
Normal 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
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
8
|
23
debian/control
vendored
Normal file
23
debian/control
vendored
Normal 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
38
debian/copyright
vendored
Normal 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
2
debian/docs
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
NEWS
|
||||||
|
README
|
13
debian/rules
vendored
Executable file
13
debian/rules
vendored
Executable 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
|
@ -26,10 +26,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
/* implementations ids,
|
/* implementation's typedefs */
|
||||||
* 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
|
||||||
@ -102,9 +99,14 @@ typedef struct __usrtc_functions_t {
|
|||||||
usrtc_impltype_t usrtc_type;
|
usrtc_impltype_t usrtc_type;
|
||||||
} usrtc_functions_t;
|
} usrtc_functions_t;
|
||||||
|
|
||||||
/*basic rtc functions*/
|
/* basic usrtc functions */
|
||||||
void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t compare);
|
/* initialize usrtc core structure */
|
||||||
usrtc_t *usrtc_create(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);
|
||||||
|
/* 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 { /*ooh,parent == parent->parent->right*/
|
} else { /* 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,7 +151,8 @@ 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 && sister->right->color==usrtc_black) {
|
if((sister->left->color == usrtc_black) &&
|
||||||
|
(sister->right->color == usrtc_black)) {
|
||||||
sister->color = usrtc_red;
|
sister->color = usrtc_red;
|
||||||
child = parent;
|
child = parent;
|
||||||
} else {
|
} else {
|
||||||
@ -191,7 +192,8 @@ 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 && sister->left->color==usrtc_black) {
|
if((sister->right->color == usrtc_black) &&
|
||||||
|
(sister->left->color == usrtc_black)) {
|
||||||
sister->color = usrtc_red;
|
sister->color = usrtc_red;
|
||||||
child = parent;
|
child = parent;
|
||||||
} else {
|
} else {
|
||||||
@ -219,7 +221,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)
|
||||||
@ -236,10 +238,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;
|
||||||
@ -247,7 +249,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];
|
||||||
|
|
||||||
@ -305,5 +307,6 @@ 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,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;
|
||||||
}
|
}
|
||||||
|
31
lib/tree.c
31
lib/tree.c
@ -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 */
|
||||||
|
24
lib/usrtc.c
24
lib/usrtc.c
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
man/Makefile.am
Normal file
2
man/Makefile.am
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
man_MANS = usrtc_init.3 usrtc_create.3 usrtc_destroy.3
|
||||||
|
|
24
man/reference-template.3
Normal file
24
man/reference-template.3
Normal 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
1
man/usrtc_create.3
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
usrtc_init.3
|
1
man/usrtc_destroy.3
Symbolic link
1
man/usrtc_destroy.3
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
usrtc_init.3
|
87
man/usrtc_init.3
Normal file
87
man/usrtc_init.3
Normal 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
|
Loading…
x
Reference in New Issue
Block a user