This document describes version 2.0d2 of Useless Containers Library, a C language library implementing a set of containers.
The package is distributed under the terms of the GNU General Public License (GPL).
The latest release can be downloaded from:
development takes place at:
and as backup at:
Copyright © 2001-2010, 2013, 2015 by Marco Maggi marco.maggi-ipsu@poste.it
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being “GNU Free Documentation License” and “GNU General Public License”, no Front–Cover Texts, and no Back–Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.
Appendices
This container library may be thought of as “low level”. Methods are provided to handle collected data, but no container can be used without wrapping it in a module whose functions “know” how to deal with the type of collected data.
Useless Containers Library installs the single header file ucl.h. All the
function names in the API are prefixed with ucl_; all the
constant names are prefixed with UCL_; all the type names are
prefixed with ucl_ and suffixed with _t.
There is no error reporting system: it is our responsibility to validate function's arguments using the appropriate UCL functions. With the single exception of the vector module: UCL does no memory allocation.
The library is developed and tested under the GNU+Linux system and
officially it supports only the GNU infrastructure: requires the
GNU C library and compiles fine with the GNU C compiler
(-std=c99 -pedantic switches).
The library makes use of inline functions and it is designed to be used only by C libraries and programs; it is probably impossible to interface it with other languages, unless through a C language wrapper library.
This package installs a data file for pkg-config, so when searching for the installed library with the GNU Autotools, we can:
m4_include(meta/autoconf/pkg.m4)
PKG_CHECK_MODULES([UCL],[ucl >= 2.0])
which will set the variables UCL_LIBS and UCL_CFLAGS.
Alternatively we can use the raw GNU Autoconf macros:
AC_CHECK_LIB([ucl],[cct_version_string],,
[AC_MSG_FAILURE([test for UCL library failed])])
AC_CHECK_HEADERS([ucl.h],,
[AC_MSG_FAILURE([test for UCL header failed])])
The design of methods tries to be the one that maximises the number of functions that cannot fail. This sometimes leads to “strange” or “dangerous” methods: functions that will cause the application to crash if an argument is incorrect. But, in these cases, the library provides a function to test the argument separately: to assert the precondition.
For example: if a vector index is out of range, we have to make sure not to hand it to an insertion/extraction method; we have to test it first and make use of it only if the test result is good.
Under the examples directory of the source tree there is a small
program that links to the library and prints the size of the UCL data
structures; it can be built and run with the examples makefile
rule. On a i686-pc-linux-gnu the output is:
Size of common data types:
char 1 :)
void * 4
int 4
short int 2
long int 4
long long 8
float 4
double 8
long double 12
size_t 4
ptrdiff_t 4
ucl_value_t 4
Limits:
short int (SHRT_MIN, SHRT_MAX) -32768 32767
integer (INT_MIN, INT_MAX) -2147483648 2147483647
unsigned short int (USHRT_MAX) 65535
unsigned (UINT_MAX) 4294967295
Size of UCL structures:
ucl_circular_t 16
ucl_hash_table_t 36
ucl_heap_t 32
ucl_iterator_t 20
ucl_map_t 28
ucl_vector_t 48
Size of UCL link structures:
ucl_node_tag_t 16
ucl_graph_node_tag_t 24
ucl_graph_link_tag_t 28
This library has the need to write functions, conceptually, like this one:
void data_type_t *
the_function (data_type_t * p)
{
return p;
}
that is: functions that do not modify the arguments, but whose return value must be modifiable. To write them like this:
void data_type_t *
the_function (const data_type_t * p)
{
return p;
}
would be useful because:
p is not
modified;
but a warning is issued because the return statement discards the
const qualifier.
The adopted solution is to avoid the -Wcast-qual flag of the
GNU C compiler, which is responsible to issue a warning if we discard
a qualifier with a cast; so the following implementation does not raise
warnings:
void data_type_t *
the_function (const data_type_t * p)
{
return (data_type_t *)p;
}
It is not beautiful. But the ugliness is only in the UCL code, the user does not see it.
The installed libraries follow version numbering as established by the GNU Autotools. For an explanation of interface numbers as managed by GNU Libtool See interface.
Return a pointer to a statically allocated ASCIIZ string representing the interface version number.
Return an integer representing the library interface current number.
Return an integer representing the library interface current revision number.
Return an integer representing the library interface current age.
UCL tries to avoid as much as possible the responsibility to allocate and release memory. Dynamic structures based on trees or linked lists do not call any memory allocation function: the responsibility to allocate UCL data structures is delegated to the user's code.
This makes the library a little more complex to use, but it also makes the code simpler by reducing the error cases that have to be dealt with. Also, user's code can implement a custom allocator and feed memory blocks to UCL's functions. This behaviour can be leveraged to improve performance, because the UCL makes use of a lot of little data structures.
When needed: the library makes use of a default allocator that reverts
to the standard malloc(), realloc() and
free() functions.
The following API has two main purposes:
Type of the memory allocator. We may build structures of this type to select a memory allocation policy. Fields description follows.
void * data- Pointer to an allocator data structure holding the state of the allocator; it is used as first argument to the allocator function, it can be
NULL.ucl_memory_alloc_fun_t * alloc- Pointer to a function used to allocate/reallocate/free a memory block.
Allocate, reallocate or free memory blocks.
- data
- The value of the
datafield in the allocator data structure.- pp
- Internally cast to
void **, it is a pointer to the variable that holds the pointer to handle.- dim
- The dimension of the memory block. It is expressed in bytes for the UCL functions.
The protocol:
- if dim is zero:
- if
*pp isNULL: nothing happens,- else
*pp is notNULL: the referenced memory is freed;- else dim is positive:
- if
*pp isNULL: a new block of memory is allocated and a pointer to it stored in*pp;- else
*pp is notNULL: the block of memory referenced by*pp is reallocated and a pointer to the new block is stored in*pp.This function must work like
malloc(),realloc()andfree()with the fundamental difference that: in case of error it must not return. What it does instead of returning is not the business of UCL; the default allocator will terminate the process with an invocation toexit()with codeEXIT_FAILURE. The UCL guarantees that an error allocating memory will not corrupt any container (so theallocfunction canlongjump()to somewhere in case of error).
Example of new memory block allocation:
ucl_memory_allocator_t allocator;
void * p = NULL;
allocator.alloc(allocator.data, &p, 4096);
example of memory block reallocation:
ucl_memory_allocator_t allocator;
void * p = ...;
allocator.alloc(allocator.data, &p, 4096);
example of memory release:
ucl_memory_allocator_t allocator;
void * p = ...;
allocator.alloc(allocator.data, &p, 0);
Predefined memory allocator. Selects
ucl_memory_alloc()as allocation function.
Allocate, reallocate or free a block of memory using the standard
calloc(),realloc()andfree()functions. data is ignored: it is perfectly correct to invoke this function with data set toNULL.This function can be used as
allocfunction in aucl_memory_allocator_t.The implementation is:
void ucl_memory_alloc (void * dummy, void * qq, size_t dim) { void ** pp = qq; void * p; if (0 == dim) { if (NULL != *pp) { free(*pp); *pp = NULL; } } else { p = (NULL == *pp)? calloc(1, dim) : realloc(*pp, dim); if (NULL == p) { perror(strerror(errno)); exit(EXIT_FAILURE); } *pp = p; } }
These functions implement the classic alloc, realloc and free operations using the selected allocator.
This module offers a set of functions to handle memory blocks; its
purpose is to provide a small data structure (ucl_block_t) which
can be used directly as argument to function and return value from
function, instead of the couple: pointer to memory block, block length
in bytes. All the functions are defined in the header ucl.h and
declared as __inline__.
The type of memory block; fields description follows:
size_t len- The number of bytes in the block; can be zero.
uint8_t * ptr- Pointer to the memory block or
NULL.To initialise a block to empty state do this:
ucl_block_t B = { .ptr = NULL, .len = 0 };or this:
ucl_block_t B; ucl_block_reset(&B);
Allocate or reallocate a memory block using the allocator and return the resulting block.
If the
ptrfield of block is notNULL: free the referenced memory block using allocator.
Set the fields of the block structure.
Return true if the
ptrfield of block isNULL.
Reset to zero all the bytes in the memory block.
Shift the memory reference in block by offset slots each of dim bytes. offset can be zero, positive or negative.
Like
ucl_block_shift_x(), but produce a new block.
This function assumes that b is contiguous to or included in a; return a new block c referencing the first portion of a not in b.
c.len b.len |.........................|.................| c.ptr b.ptr v v |-------------------------|---------------------| ^ a.ptr |...............................................| a.len
This module offers a set of functions to handle ASCII coded, zero
terminated strings; its purpose is to provide a small data structure
(ucl_ascii_t) which can be used directly as argument to function
and return value from function, instead of the couple: pointer to memory
block, block length in bytes. All the functions are defined in the
header ucl.h and declared as __inline__.
The type of zero–terminated ASCII strings; fields description follows:
size_t len- The number of characters in the block; can be zero; it does not include the terminating null character.
char * ptr- Pointer to the memory block or
NULL; the lastcharmust be zero.To initialise an ascii to empty state do this:
ucl_ascii_t A = { .ptr = NULL, .len = 0 };or this:
ucl_ascii_t A; ucl_ascii_reset(&A);or this:
ucl_ascii_t A = ucl_ascii_empty;
Holds an array of
char *. Fields:
size_t len- the number of strings;
char ** ptr- the array of pointers.
Represent an empty string. It is a statically allocated structure, referencing a zero–terminated empty string.
Initialise the fields of a structure.
Build and return a structure initialised with string. The length is determined with the standard
strlen()function.
Return true if the pointer field is set to
NULL.
Return true if the string referenced by ascii is zero–terminated.
Reset the block of memory to zero bytes.
Make sure that the string referenced by ascii is zero–terminated.
Return a block initialised with the fields of an ASCII block.
Return an ASCII block initialised with the fields of a block.
Allocate or reallocate an ASCII block using allocator; dim and new_dim are the number of characters to be stored in the block, with the exclusion of the terminating zero.
If the
ptrfield of ascii is notNULL: free the referenced memory block using allocator.
Reset to zero, using
memset(), the structure of type pointed to by struct_p.
Allocate a new structure of type using allocator and store a pointer to it in p. Example:
typedef struct a_t { int i; } a_t; a_t * p; ucl_struct_alloc(allocator, p, a_t);
The types of container structures and links/nodes are described in the sections dedicated to containers. Here common data types are described.
The data type of objects that can be stored in the containers; it's a
unionwith the following members:
char t_charunsigned char t_unsigned_charint t_intunsigned int t_unsigned_intlong t_longunsigned long t_unsigned_longint8_t t_int8uint8_t t_uint8int16_t t_int16uint16_t t_uint16int32_t t_int32uint32_t t_uint32- One field for each built in C language type.
size_t t_sizessize_t t_ssizeintptr_t t_intptruintptr_t t_uintptr- Fields for miscellaneous types.
void * ptrvoid * pointeruint8_t * byteschar * chars- Fields for miscellaneous pointer types.
Constant value representing the null
ucl_value_t; its fields are set to zero.
Alias for
_Bool, which is defined by the C99 standard. The standard defines also thetrueandfalsevalues (in the stdbool.h header).
Array of pointers. Public fields:
void ** slots- pointer to an array of pointers:
void *; this type implies no assumption upon the origin of the array memory, it can be statically or dynamically allocated, or it can be on the stack;size_t number_of_slots- the number of elements in
slots;ucl_value_t data;- custom value that can be used to store a context associated to the array; this field is useful when we need to hand a pointer to an array to some function like a callback.
Let's say that we want to preallocate a set of structures to be used
with the UCL, for example: ucl_list_link_t, the structure
representing a node in the UCL's doubly linked list. We allocate them
with code like:
#define NUMBER_OF_PREALLOCATED_STRUCTS 4096
ucl_memory_allocator allocator;
ucl_list_link_t * link_p;
for (size_t i=0; i<NUMBER_OF_PREALLOCATED_STRUCTS; ++i) {
link_p = NULL;
allocator.alloc(allocator.data, &link_p, sizeof(ucl_list_link_t));
/* here we have to put the links somewhere */
}
it can be convenient to put the links in a linked list and extract them
at usage time. We do not want to use the ucl_list_t container,
because it is overkill for this application, so we can use the following
special type.
A structure with a single field,
ucl_link_t * next_p, to be used to collect structures in a linked list.
With it the preallocation code looks like this:
#define NUMBER_OF_PREALLOCATED_STRUCTS 4096
ucl_memory_allocator allocator;
ucl_link_t * link_list_p = NULL;
{
ucl_link_t * link_p;
for (size_t i=0; i<NUMBER_OF_PREALLOCATED_STRUCTS; ++i)
{
link_p = NULL;
allocator.alloc(allocator.data, &link_p, sizeof(ucl_list_link_t));
if (link_list_p)
{
link_p->next_p = link_list_p;
link_list_p = link_p;
}
else
{
link_list_p = link_p;
link_list_p->next_p = NULL; /* just to be sure */
}
}
}
to extract the links we do:
ucl_link_t * link_p;
ucl_link_t * link_list_p;
ucl_list_link_t * list_link_p;
...
if (link_list_p)
{
link_p = link_list_p;
link_list_p = link_p->next_p;
list_link_p = (ucl_list_link_t *)link_p;
/* here we can use 'list_link_p' */
}
else
{
/* no more preallocated links */
}
and to put them back:
ucl_link_t * link_p;
ucl_link_t * link_list_p;
...
if (link_list_p)
{
link_p->next_p = link_list_p;
link_list_p = link_p;
}
else
{
link_list_p = link_p;
link_list_p->next_p = NULL;
}
With better memory allocation:
#define NUMBER_OF_PREALLOCATED_STRUCTS 4096
#define SIZE_OF_PREALLOCATED_MEMORY \
(NUMBER_OF_PREALLOCATED_STRUCTS * sizeof(ucl_list_link_t))
ucl_memory_allocator allocator;
void * preallocated_links = NULL;
ucl_link_t * link_list_p;
/* let's assume that this allocator initialises the
block to zero bytes */
allocator.alloc(allocator.data, &preallocated_links,
SIZE_OF_PREALLOCATED_MEMORY);
{
ucl_link_t * link_p;
link_p = link_list_p = preallocated_links;
for (size_t i=0; i<NUMBER_OF_PREALLOCATED_STRUCTS-1; ++i)
{
link_p->next_p = link_p + sizeof(ucl_list_link_t);
link_p = link_p->next_p;
}
}
All these macros accept as range arguments the name of a range
structure, not the name of a pointer to the structure. Range
stuff is written in macros, not __inline__ functions, so that
they work with all the type structures defined below.
Data type used to describe a range of elements in a sequence, by selecting the indexes. The fields are of type
size_t.
Ranges of values.
Initialise the min and sets the max to: min
+size-1.
Initialise the max and sets the min to: max
-size+1.
Structure holding a policy for values comparison. Fields:
ucl_value_t data- context to be used as first argument to the function;
ucl_comparison_fun_t * func- pointer to the function that compares two values of type
ucl_value_t.
The type of functions used to compare values. Functions of this type are used by the associative containers.
The behaviour of the function must be the one of the standard function
strcmp(): return-1ifa<b, return0ifa==b, return1ifa>b.The function has the responsibility to provide the comparison policy: to select a field in the
ucl_value_tunions and establish when a value is formally greater than the other.
Example:
ucl_comparison_fun_t intcmp;
ucl_comparison_t compar = {
.data = NULL, .func = intcmp
};
ucl_value_t a = ...;
ucl_value_t b = ...;
int result;
result = compar.func(compar.data, a, b);
Structure holding the hash function and its context. Fields:
ucl_value_t data- a context to be used as first argument to the function;
ucl_hash_fun_t * func- pointer to the function that computes the hash value.
Type of hash functions used by the hash table. The return value must be the “position” of the key in a vector. hash for details.
Holds a function pointer and a context value. Public fields:
ucl_callback_fun_t * func- pointer to the callback function;
ucl_value_t data- the context value.
To initialise a
ucl_callback_tstructure we can do:ucl_callback_t cb = { .func = pointer_to_function, .data = { .ptr = pointer_to_data } };to initialise to no–function and no–data:
ucl_callback_t cb = ucl_callback_null;Example of callback invocation:
ucl_callback_t cb = ...; int a = 123; int b = 456; ucl_callback_apply(cb, a, b);
Statically allocated structure representing a null callback.
Callback function. context is the value stored in the callback structure, representing the callback context. ap is the list of arguments: it is responsibility of the function to know how to interpret them.
Return true if the
funcfield of cb is notNULL.
If
ucl_callback_is_present()applied to cb evaluates to true: invoke the callback function using the callback context as first argument and ava_listas second argument; theva_listwill hold references to the arguments to this function. Return the return value of the callback function.If the callback function is not present nothing happens and the return value is a
ucl_value_twith all the bytes set to zero.
Like
ucl_callback_invoke()but theva_listargument is replaced byNULL. Return the return value of the callback function.
The UCL does not support any error reporting mechanism; this means
that ucl_callback_apply() does not expect the callback to fail.
To avoid problems all the UCL modules that need to apply a callback
to arguments, do so by invoking a customisable function and are written
in such a way that if the callback raises an exception nothing bad
happens. The following API handles this.
The prototype of functions that apply a callback to a list of arguments.
ucl_callback_apply()has this prototype.
Register in UCL a new function for the application of callbacks to arguments; it will be used by all the UCL functions that invoke a callback. The default application function is
ucl_callback_apply().
Type of function which, applied to a pointer to node, returns the key (or a reference to the key) associated to the node.
Structure holding the method used to extract the key from a node. It has the following fields:
ucl_value_t data- Custom data value.
ucl_node_getkey_fun_t * func- Pointer to the function used to extract the key.
The following is a usage example:
typedef struct link_tag_t {
ucl_node_tag_t node;
ucl_value_t key;
} link_tag_t;
typedef link_tag_t * link_t;
static ucl_value_t
link_key (ucl_value_t context UCL_UNUSED, void * L_)
{
link_t L = L_;
return L->key;
}
static const ucl_node_getkey_t getkey = {
.data = { .pointer = NULL },
.func = link_key
};
we can use the key extractor directly like this:
link_t L;
ucl_value_t K;
K = getkey.func(getkey.data, L);
This section presents an implementation of binary tree; the container is a chain of structures:
------ bro ------
| node |----->| node |
| 1 |<-----| 2 |
------ dad ------
| ^
son| |dad
v |
------
| node |
| 3 |
------
each node data structure is a collection of pointers and of metadata fields whose usage is reserved by UCL; there's no data field.
The data type of the node structure and of the pointer to the node structure; nodes must be allocated and freed by client code. Public fields:
ucl_node_t dad- pointer to the parent of this node;
NULLif this node has no parent;ucl_node_t son- pointer to the son of this node;
NULLif this node has no son;ucl_node_t bro- pointer to the bro of this node;
NULLif this node has no bro.
Let's say we want to organise a set of characters in a binary tree; we define the tree node type and allocation functions like these:
typedef struct node_tag_t {
ucl_node_tag_t node;
char c;
} node_tag_t;
typedef node_tag_t * node_t;
ucl_memory_allocator_t A = {
.data = NULL,
.alloc = ucl_memory_alloc
};
node_t
node_make (char c)
{
node_t p = NULL;
A.alloc(A.data, &p, sizeof(node_tag_t));
p->c = c;
return p;
}
void
node_final (node_t p)
{
A.alloc(A.data, &p, 0);
}
__inline__ void
node_clean (node_t p)
{
ucl_struct_clean(p, node_tag_t);
}
and we remember that the built in UCL allocation function
(ucl_memory_alloc()) sets to zero all the bytes of newly allocated
blocks.
We define the getter/setter functions in “generic” form, like these:
__inline__ void
node_set (node_t p, void * data)
{
p->c = *((char *)data);
}
__inline__ void *
node_get (node_t p)
{
return &(p->c);
}
Now if we want the following hierarchy:
--- bro ---
| a |---->| c |
--- ---
| |
son v son v
--- ---
| b | | d |
--- ---
we do it like this, taking advantage of the fact that the binary tree
functions accept void * values as arguments:
node_t a, b, c, d;
a = node_make('a');
b = node_make('b');
c = node_make('c');
d = node_make('d');
ucl_btree_dadson(a, b);
ucl_btree_dadbro(a, c);
ucl_btree_dadson(c, d);
the following expressions are true:
NULL == ucl_btree_getdad(a)
a == ucl_btree_getdad(b)
a == ucl_btree_getdad(c)
c == ucl_btree_getdad(d)
c == ucl_btree_getbro(a)
NULL == ucl_btree_getbro(b)
NULL == ucl_btree_getbro(c)
NULL == ucl_btree_getbro(d)
b == ucl_btree_getson(a)
NULL == ucl_btree_getson(b)
d == ucl_btree_getson(c)
NULL == ucl_btree_getson(d)
The correct way of building binary trees is to allocate node structures
with a function that cleans them up, like calloc(), then use
the following functions to initialise the fields. If a structure is
recycled, we must reset its fields to zero first.
All the following functions accept void * values as arguments:
internally these pointers are cast to ucl_node_t.
Select a new parent node for self.
Select a new brother node for self.
Select a new child node for self.
Link dad and son to be the parent and the son respectively.
Link dad and bro to be the parent and the bro respectively.
Link dad, son and bro to be the parent, the son and the bro respectively.
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Return a pointer to the parent of self or
NULLif the node has no parent.
Return a pointer to the brother of self or
NULLif the node has no brother.
Return a pointer to the son of self or
NULLif the node has no son.
Assuming that the first field of the memory block referenced by self is a structure of type
ucl_node_tag_t, return a pointer to the first byte after that structure. The returned pointer references the first byte of the data area of the tree node.
Return true if the node is a leaf (no brother and no son).
Return true if the node is the root of a binary tree: it has no dad.
Function with recursive implementation which computes the depth of the tree having N as root, N included. Return zero if N is
NULL.
It's a matter of setting pointers to NULL; care must be taken not to
loose references to subtrees.
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Detach the son of self and return a pointer to it. The two nodes hold references to each other no more.
Detach the bro of self and return a pointer to it. The two nodes hold references to each other no more.
Detach the dad of self and return a pointer to it. The two nodes hold references to each other no more.
The purpose of a binary tree is to organise values in a hierarchy; the functions described in this section can be used to find values.
The following function accepts void * values as arguments and
return a void * value; internally these pointers are cast to
ucl_node_t.
Interpret root as a pointer to the root node of a btree (whose dad is
NULL) and find a node equal to value according to the comparison closure. compar is invoked like this:ucl_node_t N = ...; ucl_value_t D = { .pointer = N }; compar.func(compar.data, value, D);where
Nis the current node in the search; if the return value is:
- zero
- the node is returned;
- negative
- the search goes on in the son subtree;
- positive
- the search goes on in the bro subtree;
if value is not found, the return value is
NULL.
The following function accepts void * values as arguments and
return a void * value; internally these pointers are cast to
ucl_node_t.
Given two pointers to nodes: interpret A as pointer to a node in a tree and B as pointer to a node out of any tree; store the links and meta value of A into B, then resets the links and meta value of A.
Given two pointers to nodes: swap the links and the meta value in the node structures. Take care of the fact that A and B may reference each other.
Given two pointers to nodes: swap the links but not the meta value in the node structures. Take care of the fact that A and B may reference each other.
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Find the leftmost node in the subtree of the supplied node. To do this, we traverse the tree choosing always the son of the current node.
Example:
5-------10----12 | | | 1--3--4 7--9 11 | | | 2 6 8starting from
5the selected node is1, starting from10the selected node is6.Return a pointer to the leftmost node in the self sub–hierarchy or to self itself if it has no son.
Find the rightmost node in the subtree of the supplied node. To do this, we traverse the tree choosing always the brother of the current node.
Example:
5-------10----12 | | | 1--3--4 7--9 11 | | | 2 6 8starting from
5the selected node is12, starting from7the selected node is9.Return a pointer to the rightmost node in the self sub–hierarchy or to self itself if it has no brother.
Find the deepest leftmost son in a subtree. This is different from
ucl_btree_find_leftmost().Example:
5-------10----12 | | | 1--3--4 7--9 11 | | | 2 6 8starting from
5the selected node is2, starting from10the selected node is6.Return a pointer to the deepest son in the self sub–hierarchy, or self itself if it has no son.
Find the deepest rightmost bro in a subtree. This is different from
ucl_btree_find_rightmost().Example:
5-------10----12 | | | 1--3--4 7--9 11 | | | 2 6 8starting from
5the selected node is11, starting from1the selected node is4.Return a pointer to the deepest bro in the self sub–hierarchy, or self itself if it has no son.
Step up the hierarchy, dad by dad, and return a pointer to a node that has
NULLas dad.
Forward inorder iteration: visit all the nodes from the leftmost to the rightmost. Backward inorder iteration: visit all the nodes from the rightmost to the leftmost. Example: given the tree:
5-------10----12
| | |
1--3--4 7--9 11
| | |
2 6 8
the inorder iteration is:
forward: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
backward: 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Given a pointer to the root node of a tree, return the first node of an inorder iteration. For the forward iteration: it is the leftmost node; for the backward iteration: it is the rightmost node.
Advance an inorder iteration. Given a pointer to a node in a tree: perform a single step and return a pointer to the next node, or
NULLif the iteration is over.
Initialise a whole tree iterator; root must be the root node of a btree.
Initialise a subtree iterator; node must be the a node of a btree, and will be used as root node of the subtree.
Initialise a range iterator over the range of nodes selected by range (remember that ranges are inclusive); the minimum field of range is interpreted as the starting node of the iteration, while the maximum field of range is interpreted as the ending node of the iteration.
To perform a complete forward inorder iteration, we have to start from
the leftmost node (0 in the picture above), already visited, and
begin from there. Example:
ucl_node_t cur = get_the_top_node();
for (cur = ucl_btree_find_leftmost(cur);
cur;
cur = ucl_btree_step_inorder(cur));
{
do_something_with(cur);
}
To restrict the iteration to a subtree of a tree or to a range of nodes in a tree, we have to select the first and last nodes and check when the iterator reaches the last.
Example of subtree restriction: does an inorder iteration from the top of a subtree to the rightmost node in the subtree:
ucl_node_t cur, end;
cur = get_a_node(...);
end = ucl_btree_find_rightmost(cur);
for (cur = ucl_btree_find_leftmost(cur);
cur != end;
cur = ucl_btree_step_inorder(cur))
{
do_something_with(cur);
}
/* Here "cur == end" and we visit it. */
do_something_with(cur);
cur can't be NULL because end is in the subtree of the
top node; this code will work even when cur == end at the
beginning.
Example of range restriction: does an iteration starting from a node (not the leftmost) to the rightmost one:
ucl_node_t root, cur, end;
root = get_a_node();
end = ucl_btree_find_rightmost(root);
for (cur = select_first(root, ...);
cur != end;
cur = ucl_btree_step_inorder(cur))
{
do_something_with(cur);
}
cur can't be NULL because we selected the first and last nodes
in a subtree; this code will work even when root == cur == end at
the beginning.
To perform a complete backward iteration, we have to start from the
rightmost node (12 in the picture above), already visited, and
begin from there. Example:
ucl_node_t cur = get_the_top_node();
for (cur = ucl_btree_find_rightmost(cur);
cur;
cur = ucl_btree_step_inorder_backward(cur))
{
do_something_with(cur);
}
To restrict the iteration to a subtree of a tree or to a range of nodes in a tree, we have to select the first and last nodes and check when the iterator reaches the last.
Example of subtree restriction: does an iteration from the rightmost to the leftmost nodes in a subtree:
ucl_node_t cur, end;
cur = get_a_node(...);
end = ucl_btree_find_leftmost(cur);
for (cur = ucl_btree_find_rightmost(cur);
cur != end;
cur = ucl_btree_step_inorder_backward(cur))
{
do_something_with(cur);
}
/* Here "cur == end" and we visit it. */
do_something_with(cur);
cur can't be NULL because end is in the subtree of the
top node; this code will work even when cur == end at the
beginning.
Example of range restriction:
ucl_node_t root, cur, end;
root = get_a_node();
end = ucl_btree_find_leftmost(root);
for (cur = select_first(root, ...);
cur != end;
cur = ucl_btree_step_inorder_backward(cur))
{
do_something_with(cur);
}
/* Here "cur == end" and we visit it. */
do_something_with(cur);
cur can't be NULL since we selected the first and last nodes
in a subtree; this code will work even when root == cur == end a
the beginning.
Preorder iteration: visit the current node then the son then the brother. Example:
5-------10----12
| | |
1--3--4 7--9 11
| | |
2 6 8
the preorder iteration is:
forward: 5, 1, 3, 2, 4, 10, 7, 6, 9, 8, 12, 11
backward: 5, 10, 12, 11, 7, 9, 8, 6, 1, 3, 4, 2
the forward iteration is a “worm that always turns right”, while the backward iteration is a “worm that always turns left”.
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Given a pointer to the root node of a tree, return the first node of a preorder iteration. For both the forward and backward iterations: it is the root node itself.
Advance a preorder iteration. Given a node in a btree: perform a single step and return a pointer to the next node, or
NULLif the iteration is over.
Initialise a whole tree iterator; root must be the root node of a btree.
Initialise a subtree iterator; node must be the a node of a btree, and will be used as root node of the subtree.
Initialise a range iterator over the range of nodes selected by range (remember that ranges are inclusive); the minimum field of range is interpreted as the starting node of the iteration, while the maximum field of range is interpreted as the ending node of the iteration.
To perform a complete iteration, we have to start from the top node of
the tree (5 in the picture above), already visited, and begin
from there. Example:
ucl_node_t cur;
for (cur = select_the_top_node();
cur;
cur = ucl_btree_step_pre(cur))
{
do_something_with(cur);
}
this works because the top node of a btree has a NULL value in the
dad pointer field.
To restrict the iteration to a subtree of a tree: we cannot loop until
the function returns NULL, because the top node of a subtree has a
non–NULL value in the dad pointer field. With reference to the
picture above: we select the top node (number 10) and we visit it; then
we step to the next (number 7) and visit it; then we enter the loop
until the iterator reaches the top node (number 10 again).
Example:
ucl_node_t cur, end;
end = cur = get_a_node();
do_something_with(cur);
for (cur = ucl_btree_step_preorder(cur);
cur != end;
cur = ucl_btree_step_preorder(cur))
{
do_something_with(cur);
}
Postorder iteration: visit the son, then the brother, then the parent node. Example:
5-------10----12
| | |
1--3--4 7--9 11
| | |
2 6 8
the postorder iteration is:
forward: 2, 4, 3, 1, 6, 8, 9, 7, 11, 12, 10, 5
backward: 11, 12, 8, 9, 6, 7, 10, 4, 2, 3, 1, 5
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Given a pointer to the root node of a tree, return the first node of a postorder iteration. For the forward iteration: it is the deepest son found by
ucl_btree_find_deepest_son(); for the backward iteration: it is the deepest bro found byucl_btree_find_deepest_bro().
Advance a forward postorder iteration. Given a node in a btree: perform a single step and return a pointer to the next node, or
NULLif the iteration is over.
Initialise a whole tree iterator; root must be the root node of a btree.
Initialise a subtree iterator; node must be the a node of a btree, and will be used as root node of the subtree.
Initialise a range iterator over the range of nodes selected by range (remember that ranges are inclusive); the minimum field of range is interpreted as the starting node of the iteration, while the maximum field of range is interpreted as the ending node of the iteration.
To perform a complete iteration, we have to select the deepest leftmost
son in the tree (2 in the example) and begin from there. Example:
ucl_node_t cur;
cur = get_a_node();
for (cur = ucl_btree_find_deepest_son(cur);
cur != NULL;
cur = ucl_btree_step_postorder(cur));
{
do_something_with(cur);
}
To restrict the iteration to a subtree of a tree, we have to check when the iterator reaches the top node. Example:
To restrict the iteration to a subtree of a tree: we cannot loop until
the function returns NULL, because the top node of a subtree has a
non–NULL value in the parent pointer field. With reference to the
tree in the picture above: we select the top node (number 10); then we
move to the deepest son (number 6) and we visit it; then we enter the
loop until the iterator reaches the top node (number 10 again).
Example:
ucl_node_t cur, end;
cur = end = get_a_node();
for (cur = ucl_btree_find_deepest_son(cur);
cur != end;
cur = ucl_btree_step_postorder(cur));
{
do_something_with(cur);
}
/* Here "cur == end" and we visit it. */
do_something_with(cur);
cur can't be null in the loop.
Breadth first iteration: visit the tree level by level. Example:
5-------10----12
| | |
1--3--4 7--9 11
| | |
2 6 8
the order of the forward iteration is: 5, 1, 10, 3, 7, 12, 2, 4, 6, 9, 11, 8. To do it we need a moving cursor that always “turns right” keeping the count of the level. The order of the backward iteration is: 5, 10, 1, 12, 7, 3, 11, 9, 6, 4, 2, 8.
All the following functions accept void * values as arguments and
return void * values; internally these pointers are cast to
ucl_node_t.
Given a pointer to the root node of a tree, return the first node of a levelorder iteration. For both the forward and backward iterations: it is the root node itself.
Advance a breadth first iteration. Given a node in the three: perform a single step and return a pointer to the next node, or
NULLif the iteration is over.
Initialise a whole tree iterator; root must be the root node of a btree.
To perform a complete iteration, we just call the function until it
returns NULL. Example:
ucl_node_t cur;
for (cur = get_the_top_node();
cur != NULL;
cur = ucl_btree_step_levelorder(cur));
{
do_something_with(cur);
}
To perform a complete iteration, we just call the function until it
returns NULL. Example:
ucl_node_t cur;
for (cur = get_the_top_node();
cur != NULL;
cur = ucl_btree_step_levelorder_backward(cur));
{
do_something_with(cur);
}
The following routines can be used in the implementation of raw binary search trees (BST); they are included in UCL only for completeness, because we should use balanced trees not raw ones.
All the following functions accept void * values as arguments and
return values; internally these pointers are cast to ucl_node_t.
Insert the node referenced by new in the binary search tree whose root is referenced by top; use keycmp to compare keys and getkey to extract a key from its node.
Find the node having key referenced by K in the binary search tree having root referenced by top; use keycmp to compare keys and getkey to extract a key from its node. Return a pointer to the first found node, or
NULLif none was found.
Remove the node referenced by cur from the binary search tree whose root is root. Return the root node after the deletion, which may be root or not.
The following routines are used in the implementation of the AVL binary search tree; they are not meant to be used directly. map for the UCL implementation of AVL search trees.
All the following functions accept void * values as arguments and
return values; internally these pointers are cast to ucl_node_t.
The meta field of the ucl_node_tag_t structure is used to
store an AVL status integer which is: -1 when the son
subtree is higher than the bro subtree; +1 when the bro subtree
is higher than the son subtree; 0 when the son subtree and the
bro subtree have equal depth. In a balanced AVL tree the difference
in depth between a son subtree and a bro subtree is always at most
1; so we can say that the AVL status is the bro's subtree
depth minus the son's subtree depth, such difference is called
balance factor.
Perform a clockwise rotation (or son rotation or left rotation) which balances a son deeper subtree:
cur son / => \ son curreturn a pointer to the node that has replaced cur in the tree, which is always the son of cur.
This function must be called only when ‘cur’ has balance factor -2 and ‘son’ has balance factor -1 or 0; these are the useful cases and also the cases for which computing the AVL statuses after the rotation is not costly.
Example with cur being ‘11’ and having son being son deeper (balance factors in parentheses):
(top) (top) | | 11(-2) 9(0) / \ -----+----- 9(-1) 12 7 11(0) / \ => / \ / \ 7 10 6 8 10 12 / \ 6 8Example with cur being 12 and having son being equal depth (balance factors in parentheses):
(top) (top) | | 12(-2) 9(+1) / \ -----+----- 9(0) 13 7 12(-1) / \ => / \ / \ 7 10 6 8 10 13 / \ \ \ 6 8 11 11
Perform a counterclockwise rotation (or right rotation or bro rotation) which balances a right–right–higher subtree:
cur bro \ => / bro curreturn a pointer to the node that has replaced cur in the tree, which is always the bro of cur.
This function must be called only when ‘cur’ has balance factor +2 and its bro has balance factor +1 or 0; these are the useful cases and also the cases for which computing the AVL statuses after the rotation is not costly.
Example with cur being ‘7’ and having bro being bro deeper (balance factors in parentheses):
(top) (top) | | 7(+2) 9(0) / \ -----+----- 6 9(+1) => 7(0) 11 / \ / \ / \ 8 11 6 8 10 12 / \ 10 12Example with cur being ‘6’ and having bro being equal depth (balance factors in parentheses):
(top) (top) | | 6(+2) 9(-1) / \ -----+----- 5 9(0) => 6(+1) 11 / \ / \ / \ 8 11 5= 8 10 12 / / \ / 7 10 12 7
Perform a left/right rotation (or son/bro rotation) which balances a left–right–higher subtree:
cur son_bro / / \ son => son cur \ son_broit can be seen as the sequence of a counterclockwise rotation for ‘son’ and a clockwise rotation for ‘cur’:
cur cur son_bro / / / \ son => son => son cur \ / son_bro son_broreturn a pointer to the node that has replaced cur in the tree, which is always the bro of the son of cur.
This function must be called only when ‘cur’ has balance factor -2 and ‘son’ has balance factor +1.
Example:
(top) (top) | | 10 (old_cur) 8 (new_cur) / \ ----------+---------- (son) 5 13 (son) 5 (old_cur) 10 / \ => / \ / \ 3 8 (new_cur) 3 7 9 13 / \ (deep_son) (deep_bro) 7 9 (deep_son) (deep_bro)
Perform a right/left rotation (or bro/son rotation) which balances a right–left–higher subtree:
cur bro_son \ / \ bro => cur bro / bro_sonit can be seen as the sequence of a clockwise rotation for ‘bro’ and a counterclockwise rotation for ‘cur’:
cur cur bro_son \ \ / \ bro => bro_son => cur bro / \ bro_son broreturn a pointer to the node that has replaced cur in the tree, which is always the bro of the bro of cur.
This function must be called only when ‘cur’ has balance factor +2 and ‘son’ has balance factor -1.
Example:
(top) (top) | | (old_cur) 9(+2) 11 (0) (new_cur) / \ ----------+--------- 8 13(-1) (bro) 9(0) (old_cur) 13(0) (bro) / \ => / \ / \ (new_cur) 11 14 8 10 12 14 / \ (deep_son) (deep_bro) 10 12 (deep_son) (deep_bro)
Return the depth of the tree of which N is the root; if N is
NULLthe return value is zero. For this function to return the correct result: the tree must have nodes with correct status. This function is faster thanucl_btree_depth().
Return the balance factor of N: the depth of the bro subtree minus the depth of the son subtree. If N is
NULLthe return value is zero.
Return true if the tree of which N is the root is balanced; if N is
NULLthe return value is true. This function only checks that the left and right subtrees of each node have depth at most different by 1, it does not validate the AVL status of the nodes.
Return true if the tree of which N is the root is balanced and all the statuses are correct; if N is
NULLthe return value is true. This function checks that the left and right subtrees of each node have depth at most different by 1, and also verifies that the AVL status of each node is coherent with the difference between depths.
The implementation is a binary tree with nodes of type
ucl_node_t; the only difference between the btree and the tree is
the interpretation of the bro nodes. This means that all the functions
in the btree module can be used on a tree, and the tree module adds
functions to establish the interpretation policy.
In the following picture: the nodes B, C, D and
E are all “children” of the node A; the node A is
the father of the nodes B, C, D and E. So
in a tree a node can have and indefinite number of children.
-----
| A |
-----
^ |son
dad| v
----- bro ----- bro ----- bro ----- bro
| B |----->| C |----->| D |----->| E |----->NULL
----- <----- ----- <----- ----- <----- -----
^ | dad ^ | dad dad
dad| vson dad| vson
----- -----
| F | | G |
----- -----
Pointers condition meaning:
node.dad == NULLnode.bro == NULLnode.son == NULLA.dad == B && B.son == AA.dad == B && B.bro == AThe node structures must be allocated by the client code and all the bytes set to zero before usage. The btree functions can be used directly, but UCL provides aliases for them when they must be used for a tree.
All the following functions accept void * values as arguments:
internally these pointers are cast ucl_node_t.
Mutate node so that next becomes the new right brother of node. The old reference to the right brother of node is lost.
Mutate node so that prev becomes the new left brother of node. The old reference to the left brother of node is lost.
Mutate prev and next so that the two become left and right brothers. The old references to the left and right brothers are lost.
Mutate prev and next so that the two become left and right brothers. The old references to the left and right brothers are lost.
The following functions are used to insert subtrees in a tree. None of the nodes in the target tree are detached. The links in the new subtrees that are not interested by the relations in these functions, are left untouched.
All the following functions accept void * values as arguments:
internally these pointers are cast ucl_node_t.
Inserts a new dad for a node. The dad node becomes the father of the node and the first son of the old dad (if any).
--- --- | A | | A | --- --- | | --- --- |nod| -> |dad| --- --- | --- |nod| ---
Example of dad insertion:
ucl_tree_insert_dad( 1, A )
0 D 0
| | |
1--2--3--4 + A--C = A--C
| | | |
5 6 B 1--2--3--4
| |
5 6
the D and B nodes are detached and will be lost if we
don't keep a reference to them.
Insert a new child for a node. The node referenced by son becomes the last between the children of the node referenced by node.
--- --- |nod| |nod| --- --- | -> | --- --- --- | A | | A |-->|son| --- --- ---
Example of son insertion:
ucl_tree_insert_son( 0, A )
0 D 0
| | |
1--2--3--4 + A--C = 1--2--3--4--A--C
| | | | | |
5 6 B 5 6 B
the node D is detached and will be lost if we don't keep a
reference to it.
Insert a new brother for a node. The node referenced by bro becomes the left brother of the node referenced by node.
--- --- --- --- --- | A |--|nod| -> | A |--|bro|--|nod| --- --- --- --- ---
Example of prev node insertion:
ucl_tree_insert_prev( 2, A )
0 D 0
| | |
1--2--3--4 + A--C = 1--A--2--3--4
| | | | | |
5 6 B 5 B 6
the D and C nodes are detached and will be lost if we
don't keep a reference to them.
Insert a new brother for a node. The node referenced by bro becomes the right brother of the node referenced by node.
--- --- --- --- --- |nod|--| A | -> |nod|--|bro|--| A | --- --- --- --- ---
Example of next brother insertion:
ucl_tree_insert_next( 2, A )
0 D 0
| | |
1--2--3--4 + A--C = 1--2--A--3--4
| | | | |
5 6 B 5 6
the D, B and C nodes are detached and will be lost
if we don't keep a reference to them.
All the following functions accept void * values as arguments:
internally these pointers are cast to ucl_node_t.
Return true if the node referenced by dad is the father of the node referenced by cld_p, otherwise return false.
Return true if the node referenced by node is a brother of the node referenced by bro, otherwise return false.
Return true if the node referenced by self has a parent, otherwise return false.
Return true if the node referenced by self has a brother to the left, otherwise return false.
Return true if the node referenced by self has a brother to the right, otherwise return false.
Return true if the node referenced by self has a son, otherwise return false.
All the following functions accept void * values as arguments:
internally these pointers are cast to ucl_node_t.
Return a pointer to the father of the node referenced by self; if the node has no parent: return
NULL.
Return a pointer to the left brother of the node referenced by self; if the node has no left brother: return
NULL.
Return a pointer to the right brother of the node referenced by self; if the node has no right brother: return
NULL.
Return a pointer to the son of the node referenced by self; if the node has no child: return
NULL.
Return a pointer to the first between the brothers of the node referenced by self; it can be a pointer to self itself, if self is the first.
Return a pointer to the last between the brothers of the node referenced by self; it can be a pointer to self itself, if self is the last.
These functions will extract a node from a tree, returning a pointer to
the extracted node. All the following functions accept void *
values as arguments and return void * values: internally these
pointers are cast to ucl_node_t.
Extract the dad of the node referenced by node from the tree. The referenced node and all its brothers are inserted in place of the extracted dad.
Returns a pointer to the extracted node, or
NULLif the selected node has no dad. All the pointers in the extracted node structure are reset toNULL.--- --- --- --- --- --- --- | A |--|dad|--| B | | A |--|nod|--| C |--| B | --- --- --- --- --- --- --- | -> --- --- --- |nod|--| C | |dad| --- --- ---
Extract the son of the node referenced by node from the tree. The son of the selected node is extracted from the hierarchy. All of its children become children of the selected node.
Return a pointer to the extracted node or
NULLif the selected node has no son. All the pointers in the extracted node structure are reset toNULL.--- --- |nod| |nod| --- --- | | --- --- --- --- --- |son|--| C | -> | A |--| B |--| C | --- --- --- --- --- | --- --- --- | A |--| B | |son| --- --- ---
Extract the left brother of the node referenced by node. The left brother of the selected node is extracted from the hierarchy. Its children become left brothers of the selected node.
Return a pointer to the extracted node, or
NULLif the selected node has no left brother. All the pointers in the extracted node structure are reset toNULL.--- --- | A | | A | --- --- | | --- --- --- --- |prv|--|nod| -> | B |--|nod| --- --- --- --- | --- --- | B | |prv| --- ---
Extract the right brother of the node referenced by node. The right brother of the selected node is extracted from the hierarchy. Its children become right brothers of the selected node.
Return a pointer to the extracted node, or
NULLif the selected node has no right brother. All the pointers in the extracted node structure are reset toNULL.--- --- --- --- --- --- |nod|--|nxt|--| A | |nod|--| B |--| A | --- --- --- --- --- --- | -> --- --- | B | |nxt| --- ---
For the tree iterators, the return value of ucl_iterator_ptr()
is a pointer to the current node. All the following functions accept
void * values as arguments: internally these pointers are cast to
ucl_node_t.
Initialises an in–order iteration.
Initialises a pre–order iteration.
Initialises a post–order iteration.
The heap container allows us to collect a bunch of values and extract
them sorted, from the lesser to the greater, according to a custom
comparison function. The UCL heap is implemented as a binary tree,
with nodes of type ucl_node_tag_t; the current implementation is
probably inefficient, especially because of the cost of finding the next
node under which append new nodes; but even without that, it would not
be an efficient implementation anyway.
The heap is implemented as binary tree in which we keep track of the root node and of the “next dad” node; new nodes are appended as children of the next dad, first as son then as bro; if a new node has key lesser than its dad we raise it in the tree.
Let's see an example of heap construction. Let's say the heap already has ‘5’ as root node; being the only one, the root node is also the next dad (marked with ‘n’ in the pictures). Let's append ‘8’ as son of the next dad:
n5
|
8
now let's append ‘10’ as bro of next dad; the next dad becomes full so we do a breadth first step from ‘5’ to update it:
n5--10 5--10
| => |
8 n8
now let's append ‘3’ as son of next dad, then raise it in the tree while it is lesser than its dad:
5--10 5--10 3--10
| | |
n8 => n3 => n5
| | |
3 8 8
now let's append ‘4’ as bro of next dad, then raise it in the tree while it is lesser than its dad; finally, since the next dad has become full, we do a breadth first step from ‘4’ to update it:
3--10 3--10 3--n10
| | |
n5--4 => n4--5 => 4--5
| | |
8 8 8
we understand how to add ‘12’:
3--n10 3----n10
| | |
4--5 => 4--5 12
| |
8 8
and how to add ‘14’ updating the next dad with a breadth first step from ‘10’:
3----n10--14 3-----10--14
| | | |
4--5 12 => 4--5 12
| |
8 n8
further nodes will be appended to ‘8’.
Let's see some examples of node extraction. Extracting a node from the heap means to extract its root, which is the lesser one; we replace it with the lesser among its children, then recursively descend the tree always replacing with the lesser. So first we extract ‘3’:
3-----10--14 4-----10--14 4-----10--14
| | | | | |
4--5 12 => *--5 12 => 5 12
| | |
n8 n8 n8
then we extract ‘4’:
4-----10--14 5-----10--14 5-----10--14
| | | | | |
5 12 => * 12 => n8 12
| |
n8 n8
and so on.
The base structure of the heap container. The base structure stores the context associated to a heap such as the comparison function for the nodes.
The UCL heap container collects nodes of type ucl_node_tag_t,
which hold no custom data; we have to at least associate a key to each
node, doing something like this:
typedef struct link_tag_t {
ucl_node_tag_t node;
ucl_value_t key;
} link_tag_t;
typedef link_tag_t * link_t;
static ucl_value_t
link_key (ucl_value_t context UCL_UNUSED, void * L_)
{
link_t L = L_;
return L->key;
}
static const ucl_node_getkey_t getkey = {
.data = { .pointer = NULL },
.func = link_key
};
and then use getkey as last argument to
ucl_heap_initialise(); we can use the key extractor directly like
this:
link_t L;
ucl_value_t K;
K = getkey.func(getkey.data, L);
Initialise an already allocated heap structure. keycmp is the function+context used to compare keys; getkey is the function+context used to extract the key from nodes.
When a heap must be destroyed: all its nodes must be extracted and released with the appropriate function.
Insert a new node in the heap. N is internally cast to
ucl_node_t.
Extract a node from the heap; return a pointer to it, or
NULLif the heap is empty. The extracted node is the one with the smallest value; the returned value can be safely cast toucl_node_t.
Return a value of type
size_trepresenting the number of nodes in the heap.
Merge two heaps: nodes from other are extracted and inserted into H. When the function returns other is empty.
Return a pointer to the top node in the heap, without extracting it.
The circular container provides a circular doubly linked list; it is
implemented as a chain of ucl_node_t structures; a pointer to the
current position is stored in a base structure. The current
position marker can be moved forward and backward as a cursor.
The handling of list links is derived from the handling of elements in the TCL (Tool Command Language) hash table by John Ousterhout and others (http://www.tcl.tk for more about TCL).
Base structure of the container. It must be allocated by the user's code.
Initialise an already allocated structure. Set all the fields of self so that the structure represents an empty circular list.
Destroys the structure. Set all the fields of self so that the structure represents an empty circular list. Before calling this function the user's code has to make sure that all the links are extracted from the list.
To extract all the links from a circular list, we can do:
ucl_circular_t circ;
ucl_node_t link;
ucl_value_t val;
while (ucl_circular_size(circ))
{
link = ucl_circular_extract(circ);
/* insert here the code to destroy the value */
/* insert here the code to free the link memory */
}
if the value needs no destructor and we are using a memory allocator as implemented by UCL, we can do:
ucl_memory_allocator_t A;
ucl_circular_t circ;
ucl_node_t link;
while (ucl_circular_size(circ))
{
link = ucl_circular_extract(circ);
A.alloc(A.data, &link, 0);
}
Insert an element at the current position. To do this the user's code has to allocate a new circular link structure, store the value into it and hand a pointer to the node to this function.
The old current link becomes the next link.
Example of link insertion (the link has no value):
ucl_memory_allocator_t A;
ucl_circular_t circ;
ucl_node_t link = NULL;
A.alloc(A.data, &link, sizeof(ucl_node_tag_t));
ucl_circular_insert(circ, link);
Extract the current link and return a pointer to it, or
NULLif the list is empty. The new current element is the next in the forward direction.
Example of link deletion and memory release:
ucl_memory_allocator_t A;
ucl_circular_t circ;
ucl_node_t link;
link = ucl_circular_extract(circ);
if (NULL != link)
A.alloc(A.data, &link, 0);
Move forwards the current position, times is the forward offset: it can be a positive or negative integer. If the container is empty, or the offset is zero, nothing happens.
A wrapper for
ucl_circular_forward(): move backwards the current position, times is the backward offset. If the container is empty, or the offset is zero, nothing happens.
Register the function to be used to compare elements.
Move the current position to the first forward element whose value is equal to val; return a pointer to the link, or
NULLif the value was not found.While performing the search, the selected comparison function is invoked with val as second argument and a pointer to the current link as third argument:
ucl_comparison_t compar = self.compar; ucl_node_t link = ...; ucl_value_t inner = { .pointer = link }; compar.func(compar.data, val, inner);
Return the number of elements in the container.
Return a pointer to the current link, or
NULLif the container is empty.
A UCL graph is a network of (not so) little data structures; the elements of the graph are nodes and links.
UCL does not enforce the use of a container to collect graph node structures: it is responsibility of the user to put nodes somewhere. For convenience: the node structure has a “next node” field that allows us to put nodes into a simply linked list, but it is not mandatory to use it.
Each node references two doubly linked lists of links: one for outgoing links and one for incoming links.
------
NULL ------| node |----- NULL
^ | ------ | ^
| v v |
----------- ------------
| in link 0 | | out link 0 |
----------- ------------
|^ |^
v| v|
----------- ------------
| in link 1 | | out link 1 |
----------- ------------
|^ |^
v| v|
----------- ------------
| in link 2 | | out link 2 |
----------- ------------
| |
v v
NULL NULL
Each link has references of both the source and destination nodes and is part of two doubly linked lists: one of outgoing links of the source node, one of incoming links of the destination node.
------------------ -----------------
| prev output link | | prev input link |
------------------ -----------------
|^ ^|
|| ||
| --- --- |
--- | | ---
|| ||
v| |v
------------- ------------ -----------
| source node |<----| link |---->| dest node |
------------- ------------ -----------
|^ ^|
|| ||
--- | | ---
| --- --- |
|| ||
v| |v
------------------ -----------------
| next output link | | next input link |
------------------ -----------------
Both node and link structures should be allocated using an equivalent of
calloc(), or reset to zero before being inserted in a graph.
Structure type and pointer to structure type for nodes. They should be treated as opaque even if it is not.
Structure type and pointer to structure type for links. They should be treated as opaque even if it is not.
Insert a link between two nodes. The source and destination node structures cannot be exchanged: the link is directed. Arguments:
ucl_graph_node_tsrc_node- pointer to the source node structure;
ucl_graph_link_tlink- pointer to the link structure;
ucl_graph_node_tdst_node- pointer to the destination node structure.
Usage example:
ucl_memory_allocator_t A; ucl_graph_node_t src = NULL, dst = NULL; ucl_graph_link_t lnk = NULL; A.alloc(A.data, &src, sizeof(ucl_graph_node_tag_t)); A.alloc(A.data, &dst, sizeof(ucl_graph_node_tag_t)); A.alloc(A.data, &lnk, sizeof(ucl_graph_link_tag_t)); ucl_graph_link(src, lnk, dst);
Return true if there is a link between src and dst, with source src and destination dst.
Return true if there are two links between A and B, one from A to B and one from B to A.
Return true if there is a link between A and B, no matter the direction.
Remove a link from the graph. After this function has been called, it is safe to free the memory of the link.
To erase a node from a graph we have to remove all the links between it and the other nodes. To do it in the case of structures allocated with a UCL memory allocator:
ucl_memory_allocator_t A;
ucl_graph_node_t N;
ucl_graph_link_t L;
for (L = ucl_graph_output_link(N); L;
L = ucl_graph_output_link(N))
{
ucl_graph_unlink(L);
A.alloc(A.data, &L, 0);
}
for (L = ucl_graph_input_link(N); L;
L = ucl_graph_input_link(N))
{
ucl_graph_unlink(L);
A.alloc(A.data, &L, 0);
}
A.alloc(A.data, &N, 0);
Loop over the first input or output link until it is
NULL. These macros do the same loops described above; with them the extraction code looks like this:ucl_memory_allocator_t A; ucl_graph_node_t N; ucl_graph_link_t L; UCL_GRAPH_FIRST_INPUT_LINK_LOOP(N, L) { ucl_graph_unlink(L); A.alloc(A.data, &L, 0); } UCL_GRAPH_FIRST_OUTPUT_LINK_LOOP(N, L) { ucl_graph_unlink(L); A.alloc(A.data, &L, 0); } A.alloc(A.data, &N, 0);
Erase a node from a graph finalising all the links; the erasure code looks like this:
ucl_graph_node_t N; ucl_callback_t destructor; ucl_graph_erase_node_destroy_links(N, destructor); A.alloc(A.data, &N, 0);and we can implement:
ucl_value_t destructor_fun (ucl_value_t dummy, ucl_graph_link_t L) { A.alloc(A.data, &L, 0); } ucl_callback_t destructor = { .data = ucl_value_null, .func = destructor_fun };The node structure itself is not finalised: its link fields are set to
NULL, the value field is left untouched, the structure memory is not freed.
Merging means to replace two links with one that represents the whole path; before merging the scenario is:
-------- --------- -------- ---------- ------
| source |<--| in link |-->| middle |<--| out link |-->| dest |
| node | --------- | node | ---------- | node |
-------- -------- ------
merging can be done upon the input or the output link; after merging upon the input link:
-------- --------- ------
| source |<--| in link |-->| dest |
| node | --------- | node |
-------- ------
after merging upon the output link:
-------- ---------- ------
| source |<--| out link |-->| dest |
| node | ---------- | node |
-------- ------
Merge two links; in references the link incoming to the middle node; out references the link outgoing from the middle node.
Merging is meaningful if in and out are connected to the same node, but these functions do not check for this.
The middle node is excluded from the path: if other links connect the node to the graph nothing needs to be done, but if merging the links removes the last links between the node and the graph: the node must be finalised.
Store a new value in the structure.
Return the current value in the structure.
Set/get the mark value, a field of
ucl_value_ttype.
Iterate over the outgoing or ingoing links of node using link as iterator in a
for ()loop.Example of iteration over outgoing links:
ucl_graph_node_t N; ucl_graph_link_t L; UCL_GRAPH_OUTPUT_LINKS_LOOP(N, L) { do_something_with(L); }example of iteration over incoming links:
ucl_graph_node_t N; ucl_graph_link_t L; UCL_GRAPH_INPUT_LINKS_LOOP(N, L) { do_something_with(L); }
Return a pointer to the first incoming or outgoing link of N.
Traverse toward the end the list of incoming or outgoing links, starting at L. Return the last link.
Traverse toward the beginning the list of incoming or outgoing links, starting at L. Return the first link.
Return a pointer to the previous link in the chain. The return value is
NULLif L is the first link.
Return a pointer to the next link in the chain. The return value is
NULLif L is the last link.
Return the number of incoming or outgoing links.
Depth first search (DFS) is an iteration over the nodes of a graph that starts from a selected node and visits a node only once; the result of the iteration is a string of nodes. The iteration is analogous to the preorder iteration in trees (the worm that always turns right in the labyrinth).
The iteration may not touch all the nodes:
UCL implements two types of DFS: one that honors the direction of the links; one that does not.
Given the following connected graph:
-- A ---> B ---> C
| | |
| | ------
| | |
| | v
| ----> D <--- E
| ^
v |
F ---------
we see that we can partition the nodes in two sets:
one = { A, F } two = { B, C, E, D }
there are no links going from partition two to partition
one; the directed DFS starting at node B is:
B, C, E, D
nodes in partition one are not touched; while the undirected
DFS starting at node B is:
B, C, E, D, F, A
all the nodes are touched.
We note that:
The DFS is implemented as a recursive process that puts touched nodes
on a stack. The stack is the result of the iteration. A DFS is not
reentrant because nodes are marked by setting a field in
ucl_graph_node_t structures: while a DFS is performed the
graph must be locked for mutual exclusion.
Also, do not modify a graph while a DFS is running: the result is undefined.
Hold the result of a DFS, both directed and not. This structure must be handled as opaque.
Represent a node touched by the iteration. Public fields:
ucl_graph_node_t node- pointer to the node;
size_t in_counter- the value of the counter when the node was entered;
size_t out_counter- the value of the counter when the node was left.
The initial value of the counters is zero; the root node of the DFS is recognisable because it has
in_counter = 0.
Initialise an already allocated search handle.
Finalise a search handle. All the memory is released. A DFS must always be finalised with a call to this function.
Perform a directed DFS over a graph starting from
root; store the result into S.
Perform a non–directed DFS over a graph starting from
root; store the result into S.
Example:
ucl_graph_dfs_t S;
ucl_vector_t visited_nodes;
ucl_graph_initialise_dfs_handle(S, visited_nodes);
{
ucl_iterator_t I;
ucl_graph_node_t * root;
ucl_graph_dfs_directed(S, root);
for (ucl_vector_iterator_forward(visited_nodes, I);
ucl_iterator_more(I); ucl_iterator_next(I))
{
ucl_graph_dfs_item_t * item;
item = ucl_iterator_ptr(I);
do_something_with(item);
}
}
ucl_graph_dfs_finalise_handle(S);
A hash table is a structure that maps keys to values in a way that allows the search operation to be performed with constant time for all the keys.
The hash was inspired by the book on C++ by Bjarne Stroustrup and the hash structure in the TCL (Tool Command Language) source code, by John Ousterhout and others (http://www.tcl.tk/ for more about TCL). However, no code comes from TCL.
A UCL vector of pointers is allocated by the constructor; each
pointer, called “bucket” in this document, can be NULL (empty
bucket) or referencing an entry structure. Entry structures are chained
in a linked list.
buckets
---- ----- -----
| o-+------>|entry|-->|entry|
|----| ----- -----
empty .....|NULL|
buckets . |----| -----
. | o-+------>|entry|
. |----| ----- -----
. | o-+--------------->|entry|
. |----| -----
..|NULL|
----
The UCL way of managing a vector is to allocate a block of memory,
with hysteresis, and consider a sub–block of it as “in use”, that is:
as holding the collected data. When the hash table is constructed all
the slots are marked as used, even when the bucket is set to
NULL. Reallocations can cause some of the slots to be unused, but if
we never reallocate the vector all the memory is used to hold buckets.
When inserting a new entry in the table, the hash function converts the
keys to integers in the range [0, number_of_buckets), selecting a
bucket; then the bucket is examined:
NULL, it's set to the entry pointer:
before the insertion after the insertion
---- ----
| | | |
---- ----- ---- -----
|NULL| |entry| | o-+-->|entry|
---- ----- ---- -----
| | | |
---- ----
NULL, the referenced entry is appended to the new entry
and the bucket is set to a pointer to the new entry:
---
--- ...|new| ---
| | . --- | |
--- v --- --- --- --- --- ---
| o-+-->|en1|-->|en2| -> | o-+-->|new|-->|en1|-->|en2|
--- --- --- --- --- --- ---
| | | |
--- ---
It's obvious how the extraction operation works.
If the keys are such that the hash function distributes entries uniformly over all the buckets, the time spent to find an entry is (more or less) constant.
Enlarging or restricting the hash table means enlarging or restricting
the vector of buckets. This happens with rules similar, but not equal,
to the ones for the ucl_vector_t structure; the differences are:
UCL_HASH_MINIMUM_SIZE,
which defaults to 13.
Enlarging and restricting changes the number of buckets, so it requires a rehashing of all the entries in the table: this is expensive.
The base structure. The vector of buckets is available as the field
ucl_vector_t buckets.
The UCL hash container collects entries of type
ucl_node_tag_t, which hold no custom data; we have to at least
associate a key to each node, doing something like this:
typedef struct entry_tag_t {
ucl_node_tag_t node;
ucl_value_t key;
} entry_tag_t;
typedef entry_tag_t * entry_t;
static ucl_value_t
entry_key (ucl_value_t context UCL_UNUSED, void * L_)
{
entry_t L = L_;
return L->key;
}
static const ucl_node_getkey_t getkey = {
.data = { .pointer = NULL },
.func = entry_key
};
and then use getkey as last argument to
ucl_hash_initialise(); we can use the key extractor directly like
this:
entry_t L;
ucl_value_t K;
K = getkey.func(getkey.data, L);
The construction of a hash table is split in two steps, to allow custom configuration of the vector of buckets. A simple construction, using the default values, for a table using strings as keys goes like this:
ucl_vector_config_t C;
ucl_vector_t V;
ucl_hash_table_t H;
ucl_node_getkey_t getkey;
ucl_vector_initialise_config_hash(C);
ucl_vector_alloc(V, C);
ucl_hash_initialise(H, V, ucl_compare_string, ucl_hash_string,
getkey);
when finalising a hash table we have to release the UCL vector explicitly, but only after having extracted and released all the table entries; when using a UCL memory allocator, it goes like this:
ucl_memory_allocator_t A;
ucl_vector_t V;
ucl_hash_table_t H;
entry_t E;
while ((E = ucl_hash_first(H)))
{
ucl_hash_extract(H, E);
A.alloc(A.data, &E, 0);
}
ucl_vector_free(V);
the hash table structure does not need finalisation.
Initialise the hash table referenced by self. The UCL vector of buckets, already initialised, becomes part of the hash table state.
compar is the function+context used to compare keys.
hash is the function+context used to compute the hash value of keys; typedefs hash for details.
getkey is the function+context used to extract the key from an entry structures; typedefs nodes for details.
Insert a new entry in the table. The entry structure must be allocated and filled with key and value by the user's code; the pointer E is internally cast to
ucl_node_t.Inserting an entry with a key that already exists in the table will work, but future invocations of
ucl_hash_find()will return one or the other: nobody knows which one. To avoid collision of keys, we have to check the existence of a key withucl_hash_find()before attempting to insert a new entry.Example:
ucl_memory_allocator_t A; ucl_hash_table_t H; entry_t E; ucl_value_t K; K = ... E = ucl_hash_find(H, K); if (NULL == E) { A.alloc(A.data, &E, sizeof(entry_t)); E->key = K; ucl_hash_insert(H, E); }
Extract an entry from the table. E, a pointer to the entry to be removed, must be the return value of a previous invocation to
ucl_hash_find(); the pointer E is internally cast toucl_node_t. The entry structure is neither destroyed nor freed, just extracted.Example:
ucl_memory_allocator_t A; ucl_hash_t H; entry_t E; ucl_value_t K; E = ucl_hash_find(H, K); if (NULL != E) { ucl_hash_extract(H, E); A.alloc(A.data, &E, 0); }
Search in the table an entry associated with the selected key. Return a pointer to the entry or
NULLif the key was not found; the returned pointer can be safely cast toucl_node_t.
Return a pointer to the first entry in the table: the first link in the list of the first non–
NULLbucket. If the table is empty: returnNULL; the returned pointer can be safely cast toucl_node_t.
Return the number of entries in the table.
Return the number of buckets.
Return the number of used buckets.
Return the number of entries in the chain refereces by bucket at position. position must be a valid bucket index: a non–negative integer in the range
[0, ucl_hash_number_of_buckets(this)).
Return the average number of entries per bucket.
At present the hash table is not enlarged automatically. The decision is delegated to the user's code.
Enlarge the table using the underlying UCL vector module. This is an expensive operation because it requires rehashing all the entries. If an error occurs reallocating the vector: the table is not corrupted.
Restrict the table using the underlying UCL vector module. This is an expensive operation because it requires rehashing all the entries. If an error occurs reallocating the vector: the table is not corrupted.
Initialise the table iterator. The iterator pointer references the entries in the table. The order in which the entries are visited is unknown.
Example:
ucl_hash_table_t H; ucl_iterator_t I; entry_t E; for (ucl_hash_iterator(H, I); ucl_iterator_more(I); ucl_iterator_next(I)) { E = ucl_iterator_ptr(I); }
Function and context required to hash strings. The function is
ucl_hash_string_fun().
Return an unsigned integer representing the hash value for the string in K; the
charsmember of K must be a pointer to aNULL–terminated string of characters, typedefs value for details.The hashing algorithm comes from a C++ book by Bjarne Stroustrup (references).
The UCL list is a way of chaining ucl_node_tag_t structures in
a doubly linked list; all the functions from the btree and
tree modules can be used upon lists.
A UCL list is a chain of ucl_node_tag_t structures in which
the bro and dad fields are involved:
---- bro ---- bro ---- bro
NULL <----| N1 |----->| N2 |----->| N3 |----> NULL
dad ---- <---- ---- <---- ----
dad dad
it is equivalent to a level of brothers in the UCL tree module; the
son field can be set to NULL, or used to reference a nested
list, or used to reference some other value. The brother of a node is
called cdr, the son of a node is called car.
NOTE We use the terms car and cdr to refer to the son and bro of a node, but notice that their meaning in the context of the UCL is different from their meaning in the context of Lisp languages.
Going forwards in a list chain means to follow the bro
pointers; going backwards in a list chain means to follow the
dad pointers.
Structures of type ucl_node_tag_t must be allocated and released
by the user code. The fields of a node structure must be set to
NULL when they are not used as reference for another node.
All the following functions return and accept as arguments void *
values; they are internally cast to ucl_node_t.
If N is non–
NULL: set M assonof N; if M is non–NULL: set N asdadof M. btree typedefs for the meaning of this.
If N is non–
NULL: set M asbroof N; if M is non–NULL: set N asdadof M. btree typedefs for the meaning of this.
For example, to build the hierarchy:
----- ----- -------
| one |--| two |--| three |-- NULL
----- ----- -------
using the UCL memory allocator:
ucl_memory_allocator_t A;
ucl_node_t one, two, three;
one = ucl_malloc(ucl_memory_allocator, UCL_NODE_SIZE);
two = ucl_malloc(ucl_memory_allocator, UCL_NODE_SIZE);
three = ucl_malloc(ucl_memory_allocator, UCL_NODE_SIZE);
ucl_list_set_cdr(one, two);
ucl_list_set_cdr(two, three);
remember that the UCL default allocator sets to zero every newly
allocated block, so the fields in the allocated nodes are automatically
set to NULL.
All the following functions return and accept as arguments void *
values; they are internally cast to ucl_node_t. btree typedefs for the meaning of the fields of ucl_node_tag_t.
Assuming N references the first node in a list: return a pointer to the link at position (zero based), or
NULLif the index is out of range.
When using the following operations, it is impossible to distinguish
between a NULL representing a legitimate return value and a NULL
representing a return from an invalid operation; we have to take care of
applying these operations only when they are legitimate.
Apply twice the car operator. Return
NULLif the operation is invalid.
Apply the cdr operator, then the car operator. Return
NULLif the operation is invalid.
Apply the car operator, then the cdr operator. Return
NULLif the operation is invalid.
Apply twice the cdr operator. Return
NULLif the operation is invalid.
Apply the car operator three times. Return
NULLif the operation is invalid.
Apply the cdr operator, then the car operator twice. Return
NULLif the operation is invalid.
Apply the car operator, then the cdr operator, then the car operator. Return
NULLif the operation is invalid.
Apply the cdr operator twice, then the car operator. Return
NULLif the operation is invalid.
Apply the car operator twice, then the cdr operator. Return
NULLif the operation is invalid.
Apply the cdr operator, then the car operator, then the cdr operator. Return
NULLif the operation is invalid.
Apply the car operator, then the cdr operator twice. Return
NULLif the operation is invalid.
Apply the cdr operator three times. Return
NULLif the operation is invalid.
All the following functions return and accept as arguments void *
values; they are internally cast to ucl_node_t. btree typedefs for the meaning of the fields of ucl_node_tag_t.
Remove an element at the beginning of the list of which N is an element. Return a pointer to the removed element; store in new_first a pointer to the new first element of the list.
Remove an element at the end of the list of which N is an element.
All the following functions return and accept as arguments void *
values; they are internally cast to ucl_node_t. btree typedefs for the meaning of the fields of ucl_node_tag_t.
Return the count of elements in the list from N towards the end.
Apply the callback to N and all its brothers up to the end of the list.
Apply the callback to P and Q, and all their brothers up to the end of the P list. Q is meant to be the source value and P the destination value.
Assuming N is the first element of a list: reverse the list and return it new first element.
Example of forward iteration:
ucl_node_t N;
while (N) {
/* do something with N */
N = ucl_list_cdr(N);
}
example of backward iteration:
ucl_node_t N;
while (N) {
/* do something with N */
N = ucl_list_prev(N);
}
The map container is an AVL tree; it can be used to implement an associative array.
The map/multimap idea was inspired by the book on C++ by Bjarne Stroustrup and by the STL C++ (Standard Template Library) by Stepanov and Lee.The handling of nodes is influenced by the handling of elements in the TCL (Tool Command Language) hash table by John Ousterhout and others (http://www.tcl.tk/ for more about TCL).
Maps are often used as associative arrays, that is: as collections of key/value pairs. The operations we want to do on a map are:
Clearly there are two sub–types of map container: the one that allows multiple values to be associated to the same key, and the one that does not. We call the first a multimap and the second a simple map.
Base structure for the container. It must be allocated by the user's code.
The UCL map container collects nodes of type ucl_node_tag_t,
which hold no custom data; we have to at least associate a key to each
node, doing something like this:
typedef struct link_tag_t {
ucl_node_tag_t node;
ucl_value_t key;
} link_tag_t;
typedef link_tag_t * link_t;
static ucl_value_t
link_key (ucl_value_t context UCL_UNUSED, void * L_)
{
link_t L = L_;
return L->key;
}
static const ucl_node_getkey_t getkey = {
.data = { .pointer = NULL },
.func = link_key
};
and then use getkey as last argument to
ucl_map_initialise(); we can use the key extractor directly like
this:
link_t L;
ucl_value_t K;
K = getkey.func(getkey.data, L);
Initialise an already allocated map structure. flags configures the map behaviour; keycmp is the function+context used to compare keys; getkey is the function+context used to extract the key from nodes.
Map configuration flags can be zero or an ORed combination of:
UCL_ALLOW_MULTIPLE_OBJECTS- Allows more than one object to be associated to the same key, with this the map behaves like a multimap.
The map structure needs no destructor, but before releasing its memory block the user code has to extract all the nodes from the map.
The following functions accept void * as arguments and return
values; internally these pointers are cast to ucl_node_t.
Given an already allocated and constructed map link, insert it in the map.
An invocation to this function always inserts L into M if M is a multimap. If M is a simple map: L is inserted only if there is no link in M having key equal to the key of L.
The return value is true if the link has been inserted, or false if the link was not inserted.
The following functions accept void * as arguments and return
values; internally these pointers are cast to ucl_node_t.
Remove the node L from the referenced map. L must be the return value of a previous invocation to
ucl_map_find(). This function only removes the link from the map, it's our responsibility to free the memory and resources associated to it.
The following functions accept void * as arguments and return
values; internally these pointers are cast to ucl_node_t.
Return the number of elements with key; this is always 0 or 1 for simple maps.
Return a pointer to the (first found) element associated with key. The return value is
NULLif such an element does not exist.For a multimap, this function returns a pointer to the first element with the selected key, so that the others can be found with repeated invocations of
ucl_map_next().
Return true if N is the pointer to a node in M, return false otherwise.
Return a pointer to the element with lesser key in the map, or
NULLif the map is empty.
Return a pointer to the element with greater key in the map, or
NULLif the map is empty.
Return a pointer to the element adjacent to the one referenced by L with greater key, or
NULLif L has the greater key in the map.
Return a pointer to the element adjacent to the one referenced by L with lesser key, or
NULLif L has the lesser key in the map.
Given a key find the element in the map associated with it, or the element with the lesser key greater than the selected one; if there are multiple links having key equal to key, select the rightmost one. Return a pointer to the requested link or
NULLif all the keys in the map are lesser than the selected one.
Given a key find the element in the map associated with it, or the element with the greater key lesser than the selected one; if there are multiple links having key equal to key, select the leftmost one. Return a pointer to the requested link or
NULLif all the keys in the map are greater than the selected one.
The iteration is over the map links: ucl_iterator_ptr() returns a
pointer to the current map link.
Initalise an inorder, preorder, postorder or breadth first iteration. btree iteration for details.
Initialise an iteration over the elements with the selected key, starting with the first element.
Initialise an iteration over the elements with the selected key, starting with the last element.
It's possible to compose map iterators to implement set operations: the keys from a map are used as set elements. A set operation is implemented as an iterator that visits one by one the result of the operation itself.
The key values must be of the same data type. That means that the compare function used by both the maps must accept the same type of values and return the same values when called with the same arguments.
For all the set iterators, the arguments are:
ucl_iterator_t it1ucl_iterator_t it2ucl_iterator_t iterThe input map iterators must be of in–order type: if the sequences are visited from the lesser to the greater key, the minimum amount of key comparison is performed.
If the sequences are not visited with the in–order iterator, the result is not defined.
The set iterators are used in the same fashion of all the other
iterators in the UCL (iterators). The value retrieved
with ucl_iterator_ptr() is the pointer to the referenced map
link.
Initialise the iteration over all the elements from both the sequences. Elements present in both sequences are included twice.
Initialise the iteration over all the elements present in both the sequences. Elements included in only one sequence are discarded.
Initialise the iteration over all the elements present in only one of the two sequences.
Initialise the iteration over all the elements from sequence 1 that are not present in sequence 2.
Example:
Sequence 1: 0 1 2 3 4 5 6
Sequence 2: 4 5 6 7 8 9
Union: 0 1 2 3 4 4 5 5 6 6 7 8 9
Intersection: 4 5 6
Complementary intersection: 0 1 2 3 7 8 9
Subtraction: 0 1 2 3
The vector container is an implementation of array, with hysteresis in memory allocation.
NOTE This module was inspired by the book on C++ by Bjarne Stroustrup and by the STL C++ (Standard Template Library).
NOTE In the following documentation, when describing valid values for vector indexes, we denote a range of values with[min, max), where[means inclusive bound and(means exclusive bound.
This container is heavyweight: its complexity is overkill for simple arrays with fixed size.
The vector structure can be allocated anywhere; the data area is always
dynamically allocated and it is described by four pointers of type
uint8_t *:
first_allocated_slot first_used_slot
last_allocated_slot last_used_slot
A slot is a section of the allocated memory that can hold an element; the dimension of the slots is configured at vector initialisation time. A free slot is a slot that does not contain an element; free slots can be present at the beginning and end of the allocated memory. A used slot is a slot that holds an element; used slots are always contiguous in the allocated memory.
Pointers when some slot is used:
free used slots free
|'''''|.................|''''''''''''''''''''|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^ ^
| | | last_allocated_slot
| | |
| | last_used_slot
| |
| first_used_slot
|
first_allocated_slot
pointers when the used area is attached to the beginning of the allocated memory:
used slots free
|.................|''''''''''''''''''''''''''|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^
| | last_allocated_slot
| |
| last_used_slot
|
first_allocated_slot == first_used_slot
pointers when the used area is attached to the end of the allocated memory:
free slots used slots
|''''''''''''''|.............................|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^
| | last_allocated_slot == last_used_slot
| |
| first_used_slot
|
first_allocated_slot
pointers when the allocated memory is full (all the slots are used):
used slots
|............................................|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^
| last_allocated_slot == last_used_slot
|
|
|
first_allocated_slot == first_used_slot
pointers when only one slot is used:
used
free slot free
|'''''|..|'''''''''''''''''''''''''''''''''''|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^
| | last_allocated_slot
| |
| first_used_slot == last_used_slot
|
first_allocated_slot
pointers when the vector is empty and a non-zero pad area was configured:
free pad free slots
area
|'''''''''''|''''''''''''''''''''''''''''''''|
|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^ ^
| | | last_allocated_slot
| | first_used_slot
| |
| last_used_slot
|
first_allocated_slot
pointers when the vector is empty and a zero pad area was configured:
free slots
|''''''''''''''''''''''''''''''''''''''''''''|
|__|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
^ ^ ^
| | last_allocated_slot
| |
| first_allocated_slot == first_used_slot
|
last_used_slot
first_allocated_slot references the first byte/slot of the
allocated memory; its value is modified only when the memory is
reallocated.
It represents the mimimum allowed value of first_used_slot; when
the two are equal: it means that the used area is attached to the
beginning of the allocated block.
last_allocated_slot references the last slot of the allocated
memory (not the last byte, unless the size of the slot is one); its
value is modified only when the memory is reallocated and is always:
last_allocated_slot == first_allocated_slot
+ slot_dimension * allocated_slot_number
It represents the maximum allowed value for last_used_slot; when
the two are equal: it means that the used area is attached to the end of
the allocated block.
first_used_slot references the first slot
that holds data and it can be casted to the type of contained elements,
to reference the first element in the array.
When the vector is empty: first_used_slot references the first
byte after a (dynamic and configurable) padding area; if the size of the
padding area is zero: its value is equal to first_allocated_slot.
first_used_slot can be accessed to start a forward iteration over
all the elements in the array.
last_used_slot references the first byte
of the last used slot.
When the array is empty: last_used_slot has the value of
first_used_slot minus the slot dimension.
last_used_slot can be accessed to start a backward iteration over
all the elements in the array.
first_used_slot <= last_used_slot
the two are equal when only one slot is used; it must always be:
number_of_used_slots * slot_dimension ==
last_used_slot - first_used_slot + slot_dimension
first_used_slot == last_used_slot + slot_dimension
and first_used_slot is set to reference the beginning of the
padding area. We use this definition of empty vector so that it is
possible to iterate with:
uint8_t * p;
for (p = vector->first_used_slot;
p <= vector->last_used_slot;
p += vector->slot_dimension) { ... }
for (p = vector->last_used_slot;
p >= vector->first_used_slot;
p -= vector->slot_dimension) { ... }
The padding area, whose starting size can be configured, has the purpose of allowing fast insertion of elements at the beginning, with no reallocation of the memory block.
The data type of the base structure; it must be allocated by the user code. vector memory for deatils on (re)allocation.
Data structure used to configure a vector; it must be allocated by the user code; public fields description follows.
size_t slot_dimension- This is the array stride, which, in simple cases, is the size, in bytes, of the elements the vector will hold; it should be the result of the
sizeof()operator applied to the data type, possibly normalised to a multiple of 4 or something.size_t number_of_slots- The number of slots to allocate.
ucl_index_t step_up- The number of slots to add when reallocating the array to enlarge it, it must be a non–zero positive integer.
ucl_index_t step_down- The number of free slots that will trigger the reallocation of he array for restriction, it must be a non–zero positive integer.
ucl_index_t size_of_padding_area- The numer of slots to keep free, if possible, at the beginning of the array when moving elements (during insertion, deletion and reallocation), it must be non–negative integer.
ucl_comparison_t compar- Function and context used to compare elements; this function is used only by the sort operations, so this field can be left blank if no sort operations are required; typedefs compar for details.
ucl_memory_allocator_t allocator- The memory allocator to use for the data area; memory typedefs for details.
Holds an array of vectors. Public slots:
size_t number_of_vectors- the number of vectors in the array;
ucl_vector_tag_t ** vectors- array of pointers to vectors; this type implies no assumption upon the origin of the array memory, it can be statically or dynamically allocated, or it can be on the stack.
To declare an array of vectors we can do:
#define NUMBER 1000 ucl_vector_tag_t * vectors[NUMBER]; ucl_vector_array_t array = { .number_of_vectors = NUMBER, .vectors = vectors };
The construction of a new vector is a 3–step sequence: declaration, configuration, allocation:
ucl_vector_config_t C;
ucl_vector_t V;
size_t slot_dimension = ...;
size_t number_of_slots = ...;
ucl_vector_initialise_config(C, slot_dimension, number_of_slots);
ucl_vector_alloc(V, C);
if we want to set custom values:
ucl_vector_config_t C;
ucl_vector_t V;
size_t slot_dimension = 16;
size_t number_of_slots = 1024;
ucl_vector_initialise_config(C, slot_dimension, number_of_slots);
C->step_up = 128;
C->step_down = 264;
C->size_of_padding_area = 32;
ucl_vector_alloc(V, C);
After the invocation to the configuration functions, the user's code may
override the default values by explicitly setting them before invoking
the allocator function. All the functions select
ucl_memory_alloc() as allocation function and set to zero the
comparison structure.
Initialise a vector configuration structure with default values.
Initialise a vector configuration structure for a vector used as byte buffer.
Initialise a vector configuration structure for a vector used as hash table buckets collector.
Initialise a vector configuration structure for a vector used as depth–first search data for the graph container.
The following are the default values
ucl_vector_initialise_config() puts into the
ucl_vector_config_t structure: a set of preprocessor symbols
declared in ucl.h. The declarations allow overriding, they are
in the form:
#ifndef UCL_VECTOR_DEFAULT_STEP_UP
# define UCL_VECTOR_DEFAULT_STEP_UP 8
#endif
Allocate memory with the selected UCL allocator and initialise the fields of V.
If the
step_upfield holds a value greater than thestep_downfield: thestep_downfield is changed tostep_up+1. vector memory for details.
Release the memory allocate in V and set to zero all its fields.
Return true if the vector has been constructed.
Return the number of stup up slots.
Return the number of step down slots.
Return the number of padding slots.
The following functions can be applied to an already constructed vector.
Update the number of the step up slots.
Update the number of the step down slots.
Update the number of the padding slots.
Register the function+context used to compare elements.
Set the fields of V to describe a vector that uses all the allocated memory. This is for special vector usage.
Mark a range of slots as used. This destroys the previous concept of used slots. Notice that range is relative to the allocated slots, not to the previously used slots.
Reset the internal fields so that the vector appears to be empty. The allocated slots memory is not touched.
Set all the allocated memory to null bytes, without touching anything else.
A replacement for
ucl_vector_alloc()that takes an already allocated block as data area; it is mandatory for the size of the block to be an integer multiple of the slot's dimension. The vector is initialised to be full: all the slots are marked as used.The responsibility of the block memory is transferred to the vector, so the block must be freed only by calling
ucl_vector_free(); this means that the memory will be freed by the allocator registered in C.
Convert index into the corresponding pointer to a slot in the vector. Return a pointer to the selected slot, or
NULLif the selected index is out of range. The range of valid values for index is[0,size), where size is the return value ofucl_vector_size().Applying
ucl_vector_enlarge()orucl_vector_restrict()to V invalidates the return value of this function.Example:
ucl_vector_config_t C; ucl_vector_t V; int * P; int D; ucl_vector_initialise_config(C, sizeof(int), 1024); ucl_vector_alloc(V, C); fill_with_values(V); P = ucl_vector_index_to_slot(V, 13); if (P) D = *P; else error();
Convert index into the corresponding pointer to a slot in the vector. This is different from
ucl_vector_index_to_slot()in that the requested position can be one unit greater than the last position in the vector: that way the returned value can be used withucl_vector_insert()to append an element to the end of the vector.Return a pointer to the selected slot, or
NULLif the selected index is out of range. The range of valid values for index is[0,size], where size is the return value ofucl_vector_size().Applying
ucl_vector_enlarge()orucl_vector_restrict()to V invalidates the return value of this function. When adding a new slot: we have to make room for the new slot before attempting to convert the index to the slot's pointer.Example:
ucl_vector_config_t C; ucl_vector_t V; int * P; int D; ucl_vector_initialise_config(C, sizeof(int), 1024); ucl_vector_alloc(V, C); fill_with_values(V); ucl_vector_enlarge(V); P = ucl_vector_index_to_new_slot(V, 13); if (P) D = *P; else error();
A wrapper for
ucl_vector_index_to_slot()that returns a pointer to the first element in the array.
A wrapper for
ucl_vector_index_to_slot()that returns a pointer to the last element in the array.
Return the index of the last element.
Return the index corresponding to a pointer to slot. It is the inverse of
ucl_vector_index_to_slot().
Return true if the pointer is a valid slot pointer, else return false.
Return true if index is a valid index for the vector.
Return true if index is a valid index for a new slot of the vector.
Return true if R, interpreted as inclusive range of indexes, is valid for V.
Return the inclusive range of indexes representing the whole vector.
Return the inclusive range of indexes from position to the end of the vector. position must be a valid index for V.
Notice that to build the range of indexes from the beginning of a vector to a selected position we just need to do:
ucl_range_t range;
ucl_range_set_min_max(range, 0, position);
Return the inclusive range of indexes from the end of the vector to position. position must be greater or equal to the size of V.
The returned range of indexes is invalid for V, but it can be used to append new elements to it; to add slots from the end to index 15 included:
ucl_vector_config_t C; ucl_vector_t V; int * P; ucl_range_t R; ucl_index_t i; ucl_vector_initialise_config(C, sizeof(int), 10); ucl_vector_alloc(V, C); fill_with_10_values(V); R = ucl_vector_range_from_end_to_position(V, 15); for (i=ucl_range_min(T); i<=ucl_range_max(R); ++i) { ucl_vector_enlarge(V); P = ucl_vector_index_to_new_slot(V, i); ... }
Return the inclusive range of indexes from the end of the vector with span.
The returned range of indexes is invalid for V, but it can be used to append new elements to it; to add 5 slots to the end:
ucl_vector_config_t C; ucl_vector_t V; int * P; ucl_range_t R; ucl_index_t i; ucl_vector_initialise_config(C, sizeof(int), 10); ucl_vector_alloc(V, C); fill_with_values(V); R = ucl_vector_range_from_end_with_span(V, 5); for (i=ucl_range_min(R); i<=ucl_range_max(R); ++i) { ucl_vector_enlarge(V); P = ucl_vector_index_to_new_slot(V, i); }of course this is just an example, because it is much easiear to use
ucl_vector_push_back().
Return a block referencing the slots selected by a range.
Return the range of slots referenced by a block.
Insert an empty slot at a selected position. This function assumes that the array has a free slot to hold the new element: to make sure that this is true, a call to this function must be preceeded by a call to
ucl_vector_enlarge().The pointer to the slot must be the return value of a previous invocation to
ucl_vector_index_to_new_slot().This function tries to move less elements as possible to create an empty slot at the selected position. The return value is a pointer to the empty slot: it can be different from the value of the target argument.
Find the position in the vector in which an element must be inserted to keep the array sorted and create a new slot there; the return value is a pointer to the empty slot.
This function assumes that:
- there's room in the vector to insert a new element;
- the array is sorted;
- a comparison function has been registered in V to be used to compare elements.
data must represent the element to be inserted, it's used as first argument to the comparison function. When a sequence of elements equal to data is present: the new slot is appended at its end.
The correct sequence of function calls required to insert a new element is: enlarge the vector, acquire the pointer, make a free slot, copy the value. Example of insertion:
ucl_vector_t vector;
ucl_index_t index;
data_type_t data;
data_type_t * ptr;
...
data = ...;
index = ...;
ucl_vector_enlarge(vector);
ptr = ucl_vector_index_to_new_slot(vector, index);
ptr = ucl_vector_insert(vector, ptr);
*ptr = data;
example of insert sort operation:
ucl_vector_t vector;
ucl_index_t index;
data_type_t data;
data_type_t * ptr;
...
data = ...;
index = ...;
ucl_vector_enlarge(vector);
ptr = ucl_vector_insert_sort(vector, &data);
*ptr = data;
Erase an element at a selected position: the slot is overwritten by moving less elements as possible. After the invocation: the pointer represented by slot is not guaranteed to be a pointer to a valid slot in the vector.
After the invocation of this function, it's possible to attempt a
reallocation of the array to free some unused memory with a call to
ucl_vector_restrict().
Example of data erasure:
ucl_vector_t V;
ucl_index_t index;
data_type_t * ptr;
...
index = ...
ptr = ucl_vector_index_to_slot(V, index);
ucl_vector_erase(V, ptr);
ucl_vector_restrict(V);
example of data extraction:
ucl_vector_t V;
ucl_index_t index;
data_type_t * ptr;
data_type_t data;
...
index = ...
ptr = ucl_vector_index_to_slot(V, index);
data = *ptr;
ucl_vector_erase(V, ptr);
ucl_vector_restrict(V);
Return a value representing the number of elements in the container.
Return a value representing the size of the elements.
Interpret slot as a pointer to a slot of V and increment it so that it references the next element. This function does no bounds checking.
Interpret slot as a pointer to a slot of V and decrement it so that it references the previous element. This function does no bounds checking.
Return a block referencing the allocated memory block.
Return a block referencing the data block: the used slots.
Return a block referencing count free slots at the end of the vector; the slots are still marked as free.
This function may haul the used slots inside the allocated memory, so slot pointers requested early will become invalid.
This function has to be called only if there are at least count free slots already allocated, see
ucl_vector_enlarge_for_slots()(vector memory for details).At present, blocks returned by this function cannot be converted to a range with
ucl_vector_range_from_block().
Return a block referencing count free slots at the beginning of the vector; the slots are still marked as free.
This function may haul the used slots inside the allocated memory, so slot pointers requested early will become invalid.
This function has to be called only if there are at least count free slots already allocated, see
ucl_vector_enlarge_for_slots()(vector memory for details).At present, blocks returned by this function cannot be converted to a range with
ucl_vector_range_from_block().
Mark the range of free slots referenced by B as used. This function is meant to commit usage of blocks requested with
ucl_vector_get_free_block_at_beginning()anducl_vector_get_free_block_at_end().B must be adjacent to the used slots inside the vector, its size must be an integer multiple of the slot dimension, its memory must be completely contained in the allocated vector memory.
Quick sort the vector using the C library function
ucl_quicksort().
Return true if the vector is sorted. This function scans the whole vector, so it is slow.
The functions described in this section search for an element in the vector, given a copy of the element to be found. The D argument represents the element to be found, it's used as first argument to the comparison function.
The return value is always a pointer to the found element in the array,
or NULL if the element is not present.
Find an element in the array with a linear search.
Find an element in the array with a binary search; this function assumes that the array is sorted.
Find an element in the array; this function assumes that the array is sorted. If there are few elements in the vector: a linear search is performed, else a binary search is used.
It's easy to iterate over all the elements of a vector. Example of forward iteration:
ucl_vector_t V;
data_type_t * P;
data_type_t * end = ucl_vector_back(V);
for (P = ucl_vector_front(V); P <= end; ++P)
{
... *P ...
}
example of backward iteration:
ucl_vector_t V;
data_type_t * P;
data_type_t * end = ucl_vector_front(V);
for (P = ucl_vector_back(V); P >= end; --P)
{
... *P ...
}
nevertheless the following iterators are provided; iterators for details on iteration.
Initialise a forward iteration.
Initialise a backward iteration.
Initialise a forward iteration over the inclusive range of elements selected by R. R must be a valid range for V, we can test this with
ucl_vector_range_is_valid().
Initialise a backward iteration over the inclusive range of elements selected by R. R must be a valid range for V, we can test this with
ucl_vector_range_is_valid().
The allocation policy for a vector container is ruled by the arguments stored into the configuration structure (vector creation). The rules are:
ucl_vector_enlarge() enlarges the array when one
of the two conditions are true:
rest = old_size % step_up
new_size = old_size + (rest)? rest : step_up
ucl_vector_restrict()
has to determine if the array has to be reallocated for restriction, the
operation is performed if there are at least that number of free slots;
the new size is computed with the following formula (in units of slot
size):
rest = old_size % step_up
new_size = old_size - step_down
new_size += (rest)? rest : step_up
example:
old_size = 20
step_up = 4
step_down = 10
rest = 20 % 4 = 0
new_size = 20 - 10 = 10
new_size = 10 + 4 = 14
notice that if step_up >= step_down it can result that
new_size >= old_size, example:
old_size = 10
step_up = 4
step_down = 2
rest = 10 % 4 = 2
new_size = 10 - 2 = 8
new_size = 8 + 2 = 10
another example:
old_size = 11
step_up = 4
step_down = 2
rest = 11 % 4 = 3
new_size = 11 - 2 = 9
new_size = 9 + 3 = 12
that is why ucl_vector_alloc() sets step_down to a value
greater than step_up.
By default the UCL allocator is used (memory functions), but it is possible to register a vector–specific allocator.
To be used to make sure that at least one free slot exists.
Check if there are free slots in the allocated memory: if there are, nothing happens; else the array is reallocated and enlarged according to the reallocation rules.
An error reallocating memory does not corrupt the vector.
Return true if the next call to
ucl_vector_enlarge()will reallocate the vector.
Return the number of allocated slots after a reallocation for enlarging. This function returns a meaningful value only when
ucl_vector_will_enlarge()returns true.
To be used to make sure that there is room for at least the selected number of free slots.
Check if there are at least required_free_slots in the allocated memory: if there are, nothing happens; else the array is reallocated and enlarged to get enough room.
An error reallocating memory does not corrupt the vector.
Make sure that there is enough memory to hold the inclusive range of indexes described by R. This works despite R being: already a valid range of indexes, completely beyond the upper index limits, across the current upper index limit.
Check if there are enough free slots in the allocated memory so that it's correct to restrict the array: if there aren't, nothing happens; else the array is reallocated and restricted according to the reallocation rules.
An error reallocating memory does not corrupt the vector.
Return true if the next call to
ucl_vector_restrict()will reallocate the vector.
Return the number of allocated slots after a reallocation for restricting. This function returns a meaningful value only when
ucl_vector_will_restrict()returns true.
Set all the slots to zero. This does not change the vector size: it is not like extracting all the elements.
Returns the number of allocated but currently unused slots. It is the number of elements that can be added without causing a memory reallocation.
Register a new allocator.
The vector structure provides all the functions required to implement a priority queue. This is a structure in which elements are associated with keys: when an element is added and the structure is kept sorted comparing its key with the keys of the elements already in the container.
Let's say we have declared a structure like this:
typedef struct pair_t {
key_t key;
val_t val;
} pair_t;
and a ucl_comparison_t function+context to compare keys.
If any time a pair_t must be inserted in the vector we use the
ucl_vector_insert_sort() function to determine the insertion
position, the elements will be kept sorted according to the key values
and comparison algorithm.
Then ucl_vector_front() or ucl_vector_back() can be
used to extract the element with lesser or greater key.
The functions described in this section are built upon the basic ones; some of them invoke the enlarge/restrict memory functions.
Add a slot to the front of the vector and return a pointer to it.
This function invokes
ucl_vector_enlarge().
Add a slot to the tail of the vector and return a pointer to it.
This function invokes
ucl_vector_enlarge().
If the vector is not empty: erase the first slot, else do nothing.
This function invokes
ucl_vector_restrict().
If the vector is not empty: erase the last slot, else do nothing.
This function invokes
ucl_vector_restrict().
Notice that the “top” operations of the stack and queue are already
implemented by ucl_vector_front() and ucl_vector_back().
In the following functions the dst vector must be an already allocated vector.
Append a block to the vector by copying data from B with
memcpy(). The size of the block must be an integer multiple of the destination vector's slot dimension.This function invokes
ucl_vector_enlarge_for_slots().
Append all the elements of src to the end of dst by copying data with
memcpy(). If dst is empty: this operation is equivalent to duplicating src.This function invokes
ucl_vector_enlarge_for_slots().
Append the elements of src referenced by R to the end of dst by copying data with
memcpy().This function invokes
ucl_vector_enlarge_for_slots().
Append elements from a set of vectors to the end of dst. The
...arguments are a list ofucl_vector_tvalues terminated by aNULL.This function invokes
ucl_vector_enlarge_for_slots().Example:
ucl_vector_t dst, a, b, c, d; ... ucl_vector_append_more(dst, a, b, c, d, NULL);
Like
ucl_vector_append_more()but takes source vectors from an array rather than from application parameters.
Insert all the elements of src into dst at offset.
offset must be a valid value for
ucl_vector_index_to_new_slot().This function invokes
ucl_vector_enlarge_for_slots().
Insert the data referenced by B into dst at offset.
The size of B must be an integer multiple of the slot's dimension of dst. offset must be a valid value for
ucl_vector_index_to_new_slot().This function invokes
ucl_vector_enlarge_for_slots().
Insert the data referenced by the inclusive R of indexes from src into dst at offset.
The size of B must be an integer multiple of the slot's dimension of dst. offset must be a valid value for
ucl_vector_index_to_new_slot().This function invokes
ucl_vector_enlarge_for_slots().
Erase all the elements in the selected range.
This function invokes
ucl_vector_restrict().
Copy slots referenced by src_range in src to position in dst; data in dst is overwritten.
position must be a valid index for dst. src_range must be valid for src. There must be enough slots after position in dst to hold the whole range from src.
Copy data from src into dst at position; data in dst is overwritten.
position must be a valid index for dst and enough slots must exist after it to accept the whole src block. The length of src must be an integer multiple of the slot's dimension in dst.
Copy data from src at position into dst, overwriting data.
position must be a valid index for dst and there must be enough slots in dst to fill the block. The length of src must be an integer multiple of the slot's dimension in dst.
Compare two ranges of elements in two vectors, element by element, using the comparison function of a. If the size of the ranges is not equal: only a number of elements equal to the lesser size is compared. The comparison stops at the first pair of elements for which the comparison function returns non–zero.
Works somewhat like
strcmp(). Return:
0- if all the compared elements are equal;
+1- if, for the last compared pair, the element from a is greater than the last element from b;
-1- if, for the last compared pair, the element from a is lesser than the last element from b.
a can be equal to b.
Wrapper for
ucl_vector_compare_range()that returns true if the two ranges are equal.
Wrapper for
ucl_vector_compare_range()that compares the whole vectors.
Wrapper for
ucl_vector_compare(): return true if the vectors are equal.
The functions described in this section allow us to apply a function, in the form of a callback (typedefs callback), to each element in a vector or to each element in a range over a vector. The “for each” kind leaves to the callback the responsibility to produce a result, while the “map” kind produces a vector holding processed elements.
Apply the callback cb to each element in the vector V. The callback function is invoked with a pointer to the element's slot as custom value.
Example of callback that sums the values in a vector:
void callback (ucl_value_t state, ucl_value_t custom) { int * accumulator_p = state.ptr; int * slot = custom.ptr; *accumulator_p += *slot; } int accumulator = 0; ucl_callback_t cb = { .func = callback, .data = { .ptr = &accumulator } }; ucl_vector_t V; ucl_vector_for_each(cb, V);with this setup the operation is like a “fold”.
Like
ucl_vector_for_each(), but apply the callback only to the elements selected by the inclusive R.Example of callback that sums the values in a vector's range:
void callback (ucl_value_t state, ucl_value_t custom) { int * accumulator_p = state.ptr; int * slot = custom.ptr; *accumulator_p += *slot; } int accumulator = 0; ucl_callback_t cb = { .func = callback, .data = { .ptr = &accumulator } }; ucl_range_t range; ucl_vector_t V; ucl_range_set_min_max(range, 3, 8); ucl_vector_for_each_in_range(cb, range, V);
Like
ucl_vector_for_each(), but apply the callback to an array of pointers to slots from the vectors used as arguments.This function must be invoked with a list of
ucl_vector_targuments ended by aNULL.The callback function is invoked with a pointer to a
ucl_array_of_pointers_tstructure as custom value:
ucl_value_t data- the
t_unsigned_intfield is set to the index of the slot currently visited;size_t number_of_slots- the number of slots which is equal to the number of vectors used as arguments;
void ** slots- a pointer to an array of pointers to the slots.
The iteration stops when the end of the shortest vector is found.
Example:
static void callback (ucl_value_t state, ucl_value_t custom) { int * sums = state.ptr; ucl_array_of_pointers_t * slots = custom.ptr; int ** values = (int **)slots->slots; for (size_t i=0; i<slots->number_of_slots; ++i) sums[slots->data.unum] += *values[i]; } int sums[5] = { 0, 0, 0, 0, 0 }; ucl_callback_t cb = { .func = callback, .data = { .ptr = &sums } }; ucl_vector_t A, B, C; ucl_vector_for_each_multiple(cb, A, B, C, NULL);
Like
ucl_vector_for_each_multiple()but the vectors are given in an array rather than a list of arguments.
Apply the callback cb to each element in the vector V and store the result in the vector R. New slots are added to R using
ucl_vector_push_back().The callback function is invoked with a pointer to a
ucl_array_of_pointers_tstructure as custom value:
ucl_value_t data- the
t_unsigned_intfield is set to the index of the slot currently visited;size_t number_of_slots- the number of slots: always
2for this function;void ** slots- a pointer to an array of pointers to the slots; the first element (
slots[0]) references the result slot, while the second element (slots[1]) references the operand slot.Example of callback that negates the values:
void callback (ucl_value_t state UCL_UNUSED, ucl_value_t custom) { ucl_array_of_pointers_t * slots = custom.ptr; int * result = slots.slots[0]; int * operand = slots.slots[1]; *result = - *operand; } ucl_callback_t cb = { .func = callback, .data = { .ptr = NULL } }; ucl_vector_t result, operand; ucl_vector_map(result, cb, operand);
Like
ucl_vector_map(), but apply the callback only to the elements selected by the inclusive R.
Like
ucl_vector_map(), but apply the callback to an array of pointers to slots from the vectors used as arguments.The function must be invoked with a list of
ucl_vector_targuments ended byNULL.The callback function is invoked with a pointer to a
ucl_array_of_pointers_tstructure as custom value:
ucl_value_t data- the
t_unsigned_intfield is set to the index of the slot currently visited;size_t number_of_slots- the number of slots which is equal to 1 plus the number of vectors used as arguments;
void ** slots- a pointer to an array of pointers to the slots; the first element (
slots[0]) references the result slots, while the following elements (slots[1],slots[2], ...) reference the operands.The iteration stops when the end of the shortest operand vector is found.
Example of callback that computes the sum of vectors:
static void callback (ucl_value_t state UCL_UNUSED, ucl_value_t custom) { ucl_array_of_pointers_t * slots = custom.ptr; int ** values = (int **)slots->slots; *values[0] = 0; for (size_t i=1; i<slots->number_of_slots; ++i) *values[0] += *values[i]; } ucl_callback_t cb = { .func = callback, .data = { .ptr = NULL } }; ucl_vector_t R, A, B, C; ucl_vector_map_multiple(R, cb, A, B, C, NULL);
Like
ucl_vector_map_multiple()but the vectors are given in an array rather than a list of arguments.
Each container has its iteration constructors that must be invoked explicitly, but the functions used to do the actual iterations and to access the objects are accessed through a set of macros.
Base structure for all the iterators.
Return true if there are more elements to iterate, false if the iteration is over.
Return a pointer referencing the current value. If the iteration is already over: return
NULL.
Example of iterator usage:
ucl_value_t val;
ucl_iterator_t iterator;
ucl_map_link_t * link_p;
...
for (ucl_map_iterator_inorder(this, iterator);
ucl_iterator_more(iterator);
ucl_iterator_next(iterator))
{
link_p = ucl_iterator_ptr(iterator);
val = ucl_map_getval(link_p);
}
Return a pointer to a string representing the version number.
Return a number representing the library interface major version number.
Return a number representing the library interface minor version number.
All the following function have prototype matching
ucl_comparison_fun_t; for all of them data is unused and
the return value is: 0 if a equals b; 1 if
a is greater than b; -1 if a is lesser than
b.
Compare the
t_intfields of two values.
Compare the
unumfields of two values.
Wrapper for
strcmp().
Interpret the
ptrfields of a and b as pointers of typeint: compare the two referenced numbers by invokingucl_compare_int().
Statically allocated comparison structures which use the comparison functions described above.
Like the standard
qsort(), but makes use of the comparison function and context in compar. array is an array of count elements of size.NOTE This is indeed theqsort()function from the GNU C Library version 2.4, modified to use compar.
Ellis Horowitz, Sartaj Sahni and Susan Anderson–Freed. Strutture dati in C. McGraw–Hill, 1993.
Bjarne Stroustroup. C++. Addison-Wesley, 1997.
Copyright © 2007 Free Software Foundation, Inc. http://fsf.org/
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
The GNU General Public License is a free, copyleft license for software and other kinds of works.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program—to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and modification follow.
“This License” refers to version 3 of the GNU General Public License.
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
A “covered work” means either the unmodified Program or a work based on the Program.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The Corresponding Source for a work in source code form is that same work.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
one line to give the program's name and a brief idea of what it does.
Copyright (C) year name of author
This program 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 3 of the License, or (at
your option) any later version.
This program 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/.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
program Copyright (C) year name of author
This program comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’.
This is free software, and you are welcome to redistribute it
under certain conditions; type ‘show c’ for details.
The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see http://www.gnu.org/licenses/.
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read http://www.gnu.org/philosophy/why-not-lgpl.html.
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
http://fsf.org/
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
The purpose of this License is to make a manual, textbook, or other functional and useful document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.
This License is a kind of “copyleft”, which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.
This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The “Document”, below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as “you”. You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.
A “Modified Version” of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.
A “Secondary Section” is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.
The “Invariant Sections” are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.
The “Cover Texts” are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.
A “Transparent” copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not “Transparent” is called “Opaque”.
Examples of suitable formats for Transparent copies include plain ascii without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.
The “Title Page” means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, “Title Page” means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.
The “publisher” means any person or entity that distributes copies of the Document to the public.
A section “Entitled XYZ” means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.) To “Preserve the Title” of such a section when you modify the Document means that it remains a section “Entitled XYZ” according to this definition.
The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.
You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly display copies.
If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.
It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.
You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:
If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.
You may add a section Entitled “Endorsements”, provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.
You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled “History” in the various original documents, forming one section Entitled “History”; likewise combine any sections Entitled “Acknowledgements”, and any sections Entitled “Dedications”. You must delete all sections Entitled “Endorsements.”
You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.
A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an “aggregate” if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.
Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.
If a section in the Document is Entitled “Acknowledgements”, “Dedications”, or “History”, the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.
You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.
The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License “or any later version” applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document.
“Massive Multiauthor Collaboration Site” (or “MMC Site”) means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A “Massive Multiauthor Collaboration” (or “MMC”) contained in the site means any set of copyrightable works thus published on the MMC site.
“CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.
“Incorporate” means to publish or republish a Document, in whole or in part, as part of another Document.
An MMC is “eligible for relicensing” if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing.
To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:
Copyright (C) year your name.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the “with...Texts.” line with this:
with the Invariant Sections being list their titles, with
the Front-Cover Texts being list, and with the Back-Cover Texts
being list.
If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation.
If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
*: map opsucl_ascii_alloc: memory asciiucl_ascii_clean_memory: memory asciiucl_ascii_const: memory asciiucl_ascii_free: memory asciiucl_ascii_from_block: memory asciiucl_ascii_is_null: memory asciiucl_ascii_is_terminated: memory asciiucl_ascii_realloc: memory asciiucl_ascii_reset: memory asciiucl_ascii_set: memory asciiucl_ascii_terminate: memory asciiucl_block_alloc: memory blocksucl_block_clean_memory: memory blocksucl_block_difference: memory blocksucl_block_free: memory blocksucl_block_from_ascii: memory asciiucl_block_is_null: memory blocksucl_block_realloc: memory blocksucl_block_reset: memory blocksucl_block_set: memory blocksucl_block_shift: memory blocksucl_block_shift_x: memory blocksucl_bst_delete: btree bstucl_bst_find: btree bstucl_bst_insert: btree bstucl_btree_avl_depth: btree avlucl_btree_avl_factor: btree avlucl_btree_avl_is_balanced: btree avlucl_btree_avl_is_correct: btree avlucl_btree_avl_rot_left: btree avlucl_btree_avl_rot_left_right: btree avlucl_btree_avl_rot_right: btree avlucl_btree_avl_rot_right_left: btree avlucl_btree_clean: btree removingucl_btree_data: btree inspectionucl_btree_depth: btree inspectionucl_btree_detach_bro: btree removingucl_btree_detach_dad: btree removingucl_btree_detach_son: btree removingucl_btree_find_deepest_bro: btree visitorsucl_btree_find_deepest_son: btree visitorsucl_btree_find_leftmost: btree visitorsucl_btree_find_rightmost: btree visitorsucl_btree_find_root: btree visitorsucl_btree_find_value: btree finducl_btree_first_inorder: btree inorder iterationucl_btree_first_inorder_backward: btree inorder iterationucl_btree_first_levelorder: btree breadth firstucl_btree_first_levelorder_backward: btree breadth firstucl_btree_first_postorder: btree postorder iterationucl_btree_first_postorder_backward: btree postorder iterationucl_btree_first_preorder: btree preorder iterationucl_btree_first_preorder_backward: btree preorder iterationucl_btree_is_leaf: btree inspectionucl_btree_is_root: btree inspectionucl_btree_iterator_inorder: btree inorder iterationucl_btree_iterator_inorder_backward: btree inorder iterationucl_btree_iterator_levelorder: btree breadth firstucl_btree_iterator_levelorder_backward: btree breadth firstucl_btree_iterator_postorder: btree postorder iterationucl_btree_iterator_postorder_backward: btree postorder iterationucl_btree_iterator_preorder: btree preorder iterationucl_btree_iterator_preorder_backward: btree preorder iterationucl_btree_range_iterator_inorder: btree inorder iterationucl_btree_range_iterator_inorder_backward: btree inorder iterationucl_btree_range_iterator_postorder: btree postorder iterationucl_btree_range_iterator_postorder_backward: btree postorder iterationucl_btree_range_iterator_preorder: btree preorder iterationucl_btree_range_iterator_preorder_backward: btree preorder iterationucl_btree_ref_bro: btree inspectionucl_btree_ref_dad: btree inspectionucl_btree_ref_son: btree inspectionucl_btree_set_bro: btree creationucl_btree_set_dad: btree creationucl_btree_set_dadbro: btree creationucl_btree_set_dadson: btree creationucl_btree_set_dadsonbro: btree creationucl_btree_set_son: btree creationucl_btree_step_inorder: btree inorder iterationucl_btree_step_inorder_backward: btree inorder iterationucl_btree_step_levelorder: btree breadth firstucl_btree_step_levelorder_backward: btree breadth firstucl_btree_step_postorder: btree postorder iterationucl_btree_step_postorder_backward: btree postorder iterationucl_btree_step_preorder: btree preorder iterationucl_btree_step_preorder_backward: btree preorder iterationucl_btree_subtree_iterator_inorder: btree inorder iterationucl_btree_subtree_iterator_inorder_backward: btree inorder iterationucl_btree_subtree_iterator_postorder: btree postorder iterationucl_btree_subtree_iterator_postorder_backward: btree postorder iterationucl_btree_subtree_iterator_preorder: btree preorder iterationucl_btree_subtree_iterator_preorder_backward: btree preorder iterationucl_btree_swap: btree swapucl_btree_swap_no_meta: btree swapucl_btree_swap_out: btree swapucl_callback_apply: typedefs callbackucl_callback_apply_fun_t: typedefs callbackucl_callback_eval_thunk: typedefs callbackucl_callback_fun_t: typedefs callbackucl_callback_is_present: typedefs callbackucl_callback_set_application_function: typedefs callbackucl_circular_backward: circular movingucl_circular_constructor: circular creationucl_circular_current: circular opsucl_circular_destructor: circular creationucl_circular_extract: circular removingucl_circular_find: circular searchucl_circular_forward: circular movingucl_circular_insert: circular addingucl_circular_set_compar: circular searchucl_circular_size: circular opsucl_compare_int_fun: misc comparucl_compare_int_pointer_fun: misc comparucl_compare_string_fun: misc comparucl_compare_unsigned_int_fun: misc comparucl_comparison_fun_t: typedefs comparucl_free: memory functionsucl_graph_dfs: graph dfs apiucl_graph_dfs_directed: graph dfs apiucl_graph_dfs_finalise_handle: graph dfs apiucl_graph_dfs_initialise_handle: graph dfs apiucl_graph_erase_node_destroy_links: graph extractucl_graph_first_input_link: graph link iterUCL_GRAPH_FIRST_INPUT_LINK_LOOP: graph extractucl_graph_first_output_link: graph link iterUCL_GRAPH_FIRST_OUTPUT_LINK_LOOP: graph extractucl_graph_input_link: graph link iterUCL_GRAPH_INPUT_LINKS_LOOP: graph link iterucl_graph_last_input_link: graph link iterucl_graph_last_output_link: graph link iterucl_graph_link: graph insertucl_graph_link_get_value: graph valueucl_graph_link_set_value: graph valueucl_graph_merge_upon_input_link: graph mergeucl_graph_merge_upon_output_link: graph mergeucl_graph_next_input_link: graph link iterucl_graph_next_output_link: graph link iterucl_graph_node_get_mark: graph valueucl_graph_node_get_value: graph valueucl_graph_node_set_mark: graph valueucl_graph_node_set_value: graph valueucl_graph_nodes_are_connected: graph insertucl_graph_nodes_are_linked: graph insertucl_graph_nodes_doubly_linked: graph insertucl_graph_number_of_input_links: graph opsucl_graph_number_of_output_links: graph opsucl_graph_output_link: graph link iterUCL_GRAPH_OUTPUT_LINKS_LOOP: graph link iterucl_graph_prev_input_link: graph link iterucl_graph_prev_output_link: graph link iterucl_graph_unlink: graph extractucl_hash_average_search_distance: hash opsucl_hash_bucket_chain_length: hash opsucl_hash_enlarge: hash resizingucl_hash_extract: hash deletionucl_hash_find: hash opsucl_hash_first: hash opsucl_hash_fun_t: typedefs hashucl_hash_initialise: hash creationucl_hash_insert: hash insertionucl_hash_iterator: hash iteratorucl_hash_number_of_buckets: hash opsucl_hash_number_of_used_buckets: hash opsucl_hash_restrict: hash resizingucl_hash_size: hash opsucl_hash_string_fun: hash functionsucl_heap_extract: heap deletionucl_heap_initialise: heap creationucl_heap_insert: heap insertionucl_heap_merge: heap opsucl_heap_root: heap opsucl_heap_size: heap opsucl_interface_major_version: misc versionucl_interface_minor_version: misc versionucl_iterator_more: iteratorsucl_iterator_next: iteratorsucl_iterator_ptr: iteratorsucl_list_caaar: list visitucl_list_caadr: list visitucl_list_caar: list visitucl_list_cadar: list visitucl_list_caddr: list visitucl_list_cadr: list visitucl_list_car: list visitucl_list_cdaar: list visitucl_list_cdadr: list visitucl_list_cdar: list visitucl_list_cddar: list visitucl_list_cdddr: list visitucl_list_cddr: list visitucl_list_cdr: list visitucl_list_first: list visitucl_list_for_each: list opsucl_list_last: list visitucl_list_length: list opsucl_list_map: list opsucl_list_popback: list deletionucl_list_popfront: list deletionucl_list_prev: list visitucl_list_ref: list visitucl_list_remove: list deletionucl_list_reverse: list opsucl_list_set_car: list consucl_list_set_cdr: list consucl_malloc: memory functionsucl_map_count: map opsucl_map_delete: map deletionucl_map_depth: map opsucl_map_find: map opsucl_map_find_node: map opsucl_map_find_or_next: map opsucl_map_find_or_prev: map opsucl_map_first: map opsucl_map_initialise: map creationucl_map_insert: map insertionucl_map_iterator_complintersect: map setucl_map_iterator_inorder: map iteratorsucl_map_iterator_intersection: map setucl_map_iterator_levelorder: map iteratorsucl_map_iterator_postorder: map iteratorsucl_map_iterator_preorder: map iteratorsucl_map_iterator_subtraction: map setucl_map_iterator_union: map setucl_map_last: map opsucl_map_lower_bound: map iteratorsucl_map_next: map opsucl_map_prev: map opsucl_map_size: map opsucl_map_upper_bound: map iteratorsucl_memory_alloc: memory functionsucl_memory_alloc_fun_t: memory typedefsucl_node_getkey_fun_t: typedefs nodesUCL_NODE_SIZE: btree typedefsucl_quicksort: misc sortucl_range_equal: typedefs rangesucl_range_is_empty: typedefs rangesucl_range_max: typedefs rangesucl_range_min: typedefs rangesucl_range_set_max_size: typedefs rangesucl_range_set_min_max: typedefs rangesucl_range_set_min_size: typedefs rangesucl_range_set_size_on_max: typedefs rangesucl_range_set_size_on_min: typedefs rangesucl_range_size: typedefs rangesucl_range_value_is_in: typedefs rangesucl_range_value_is_out: typedefs rangesucl_realloc: memory functionsucl_struct_alloc: memory macrosucl_struct_clean: memory macrosucl_struct_reset: memory macrosucl_tree_extract_dad: tree removingucl_tree_extract_next: tree removingucl_tree_extract_prev: tree removingucl_tree_extract_son: tree removingucl_tree_has_dad: tree testingucl_tree_has_next: tree testingucl_tree_has_prev: tree testingucl_tree_has_son: tree testingucl_tree_insert_dad: tree insertionucl_tree_insert_next: tree insertionucl_tree_insert_prev: tree insertionucl_tree_insert_son: tree insertionucl_tree_is_bro: tree testingucl_tree_is_dad: tree testingucl_tree_iterator_inorder: tree iteratorsucl_tree_iterator_postorder: tree iteratorsucl_tree_iterator_preorder: tree iteratorsucl_tree_ref_dad: tree relativesucl_tree_ref_first: tree relativesucl_tree_ref_last: tree relativesucl_tree_ref_next: tree relativesucl_tree_ref_prev: tree relativesucl_tree_ref_son: tree relativesucl_tree_set_dadson: tree creationucl_tree_set_next: tree creationucl_tree_set_prev: tree creationucl_tree_set_prevnext: tree creationucl_vector_alloc: vector creationucl_vector_append: vector high appenducl_vector_append_block: vector high appenducl_vector_append_more: vector high appenducl_vector_append_more_from_array: vector high appenducl_vector_append_range: vector high appenducl_vector_back: vector indexes i2pucl_vector_binary_search: vector finducl_vector_block_from_range: vector indexes blockucl_vector_clean: vector creationucl_vector_compare: vector high compareucl_vector_compare_range: vector high compareucl_vector_copy_range: vector high accessucl_vector_decrement_slot: vector opsUCL_VECTOR_DEFAULT_PAD: vector creationUCL_VECTOR_DEFAULT_STEP_DOWN: vector creationUCL_VECTOR_DEFAULT_STEP_UP: vector creationucl_vector_enlarge: vector memory enlargeucl_vector_enlarge_for_range: vector memory enlargeucl_vector_enlarge_for_slots: vector memory enlargeucl_vector_enlarged_size: vector memory enlargeucl_vector_equal: vector high compareucl_vector_equal_range: vector high compareucl_vector_erase: vector removingucl_vector_erase_range: vector high eraseucl_vector_find: vector finducl_vector_for_each: vector high applyucl_vector_for_each_in_range: vector high applyucl_vector_for_each_multiple: vector high applyucl_vector_for_each_multiple_from_array: vector high applyucl_vector_free: vector creationucl_vector_front: vector indexes i2pucl_vector_get_block: vector high accessucl_vector_get_data_block: vector opsucl_vector_get_free_block_at_beginning: vector opsucl_vector_get_free_block_at_end: vector opsucl_vector_get_memory_block: vector opsucl_vector_increment_slot: vector opsucl_vector_index_is_valid: vector indexes validationucl_vector_index_is_valid_new: vector indexes validationucl_vector_index_to_new_slot: vector indexes i2pucl_vector_index_to_slot: vector indexes i2pucl_vector_initialise_config: vector creationucl_vector_initialise_config_buffer: vector creationucl_vector_initialise_config_dfs: vector creationucl_vector_initialise_config_hash: vector creationucl_vector_insert: vector addingucl_vector_insert_block: vector high insertucl_vector_insert_range: vector high insertucl_vector_insert_sort: vector addingucl_vector_insert_vector: vector high insertucl_vector_iterator_backward: vector iterationucl_vector_iterator_forward: vector iterationucl_vector_iterator_range_backward: vector iterationucl_vector_iterator_range_forward: vector iterationucl_vector_last_index: vector indexes p2iucl_vector_map: vector high applyucl_vector_map_multiple: vector high applyucl_vector_map_multiple_from_array: vector high applyucl_vector_map_range: vector high applyucl_vector_mark_all_slots_as_used: vector creationucl_vector_mark_allocated_range_as_used: vector creationucl_vector_mark_as_used: vector opsucl_vector_number_of_free_slots: vector memory miscucl_vector_number_of_padding_slots: vector creationucl_vector_number_of_step_down_slots: vector creationucl_vector_number_of_step_up_slots: vector creationucl_vector_pointer_is_valid_slot: vector indexes validationucl_vector_pop_back: vector high stackucl_vector_pop_front: vector high stackucl_vector_push_back: vector high stackucl_vector_push_front: vector high stackucl_vector_quick_sort: vector opsucl_vector_range: vector indexes rangeucl_vector_range_from_block: vector indexes blockucl_vector_range_from_end_to_position: vector indexes rangeucl_vector_range_from_end_with_span: vector indexes rangeucl_vector_range_from_position_to_end: vector indexes rangeucl_vector_range_is_valid: vector indexes rangeucl_vector_register_allocator: vector memory miscucl_vector_reset: vector creationucl_vector_restrict: vector memory restrictucl_vector_restricted_size: vector memory restrictucl_vector_running: vector creationucl_vector_set_block: vector high accessucl_vector_set_compar: vector creationucl_vector_set_memory_to_zero: vector memory miscucl_vector_size: vector opsucl_vector_slot_dimension: vector opsucl_vector_slot_to_index: vector indexes p2iucl_vector_sort_find: vector finducl_vector_sorted: vector opsucl_vector_swallow_block: vector creationucl_vector_update_number_of_padding_slots: vector creationucl_vector_update_number_of_step_down_slots: vector creationucl_vector_update_number_of_step_up_slots: vector creationucl_vector_will_enlarge: vector memory enlargeucl_vector_will_restrict: vector memory restrictucl_version: misc versionucl_version_interface_age: versionucl_version_interface_current: versionucl_version_interface_revision: versionucl_version_string: versionucl_array_of_pointers_t: typedefs valueucl_ascii_list_t: memory asciiucl_ascii_t: memory asciiucl_block_t: memory blocksucl_bool_t: typedefs valueucl_byte_pointer_range_t: typedefs rangesucl_callback_t: typedefs callbackucl_char_range_t: typedefs rangesucl_circular_t: circularucl_circular_tag_t: circularucl_comparison_t: typedefs comparucl_double_range_t: typedefs rangesucl_float_range_t: typedefs rangesucl_graph_dfs_item_t: graph dfs typesucl_graph_dfs_t: graph dfs typesucl_graph_dfs_tag_t: graph dfs typesucl_graph_link_t: graph typesucl_graph_link_tag_t: graph typesucl_graph_node_t: graph typesucl_graph_node_tag_t: graph typesucl_hash_t: typedefs hashucl_hash_table_t: hash typesucl_hash_table_tag_t: hash typesucl_heap_t: heap typesucl_heap_tag_t: heap typesucl_index_t: typedefs valueucl_int_range_t: typedefs rangesucl_iterator_t: iteratorsucl_iterator_tag_t: iteratorsucl_link_t: typedefs valueucl_long_range_t: typedefs rangesucl_map_t: map typesucl_map_tag_t: map typesucl_memory_allocator_t: memory typedefsucl_node_getkey_t: typedefs nodesucl_node_t: btree typedefsucl_node_tag_t: btree typedefsucl_pointer_range_t: typedefs rangesucl_range_t: typedefs rangesucl_size_t_range_t: typedefs rangesucl_unsigned_char_range_t: typedefs rangesucl_unsigned_long_range_t: typedefs rangesucl_unsigned_range_t: typedefs rangesucl_value_t: typedefs valueucl_vector_array_t: vector typedefsucl_vector_config_t: vector typedefsucl_vector_config_tag_t: vector typedefsucl_vector_t: vector typedefsucl_vector_tag_t: vector typedefsconst: memory functionsucl_ascii_empty: memory asciiucl_callback_null: typedefs callbackucl_compare_int: misc comparucl_compare_int_pointer: misc comparucl_compare_string: misc comparucl_compare_unsigned_int: misc comparucl_hash_string: hash functionsucl_value_null: typedefs value