Jari Project: Libdata dev
Home|Documentation|Get the source|Download|Development Team|SDK|Joining|Contacts
Author: Alfeiks KaƤnoken
Sub-part: Ikernel arch independent/libs
Location: ikernel/datas ikernel/include/datas
CVS module: ikernel
Contents:
1. Introduction
2. Structures and functions
3. Using example
4. Adding your implementation
/*------------------------------------------------*/




1. Introduction
Libdata is a part of the Jari microkernel (ikernel). It's designed for all other sub-parts that uses data structures like linked list, binary trees.
The main reason for this is a code reusing and of couse if we're found a bug within it - we just need to fix in at one place.
All components *must* use this libruary if cans (i.e. exclude too low level parts).
This lib was written with the following features:
* Simple API
* Default implementation for
** Linked list
** B Tree
** Red&black tree
** Splay tree
** AVL tree
* Easy to expand
* A good level of abstraction
It's mean that if you don't happy and wants to add a new implementation you're already allowed to do this by standart methods without ugly hacks.
You have one unitified structure and set of the function that doesn't depends on the concrete implementation.


2. Structures and functions
The main abstraction is the two strcutures usrtc_t and usrtc_node_t. You can find theirs here ikernel/include/datas/usrtc.h .
So, let's look for it:
typedef struct __usrtc_t {
struct usrtc_functions *usrtc_futable;
usrtc_count_t usrtc_nodecount;
usrtc_count_t usrtc_maxcount;
int usrtc_dupes_allowed;
usrtc_node_t usrtc_sentinel;
usrtc_compare_t usrtc_compare;
usrtc_node_alloc_t usrtc_node_alloc;
usrtc_node_free_t usrtc_node_free;
void *usrtc_context;
} usrtc_t;
*usrtc_futable - This pointer to the structure that contains all functions to operate with the current implementation.
usrtc_nodecount - It's a counter of the node in the current structure.
usrtc_maxcount - Maximal nodes in the structure, so by default you can use USRTC_COUNTMAX_T that mean maximal value of the unsigned long.
usrtc_dupes_allowed - Indicate do we allow to store a duplicates.
*usrtc_context - The pointer to the data of the context.
All other don't intresting now.


Basic functions for the USRTC.
void usrtc_init(usrtc_t *us,int impl,usrtc_count_t maxcount,usrtc_compare_t compare);
This function initializate usrtc_t structure.
*us is a pointer to the *already* allocated structure
impl referce to the using implemenation type, the possible values can be:
USRTC_LIST
USRTC_BST
USRTC_REDBLACK
USRTC_SPLAY
USRTC_AVL
maxcount maximal nodes on the structure, you can use USRTC_COUNTMAX_T
compare function for the compare by key. (*)

usrtc_t *usrtc_create(int impl,usrtc_count_t maxcount,usrtc_compare_t compare) ;
This function initializate usrtc_t structure. And return a pointer to the newly allocated structure.
impl referce to the using implemenation type, the possible values can be:
USRTC_LIST
USRTC_BST
USRTC_REDBLACK
USRTC_SPLAY
USRTC_AVL
maxcount maximal nodes on the structure, you can use USRTC_COUNTMAX_T
compare function for the compare by key. (*)

void usrtc_destroy(usrtc_t *us) ;
This function destroy and freeing usrtc_t structure.
*us a pointer to the structure

void usrtc_convert_to(usrtc_t *us,int impl) ;
This function converting usrtc to the another avialable implementation type.
*us a pointer to the structure
impl referce to the using implemenation type, the possible values can be:
USRTC_LIST
USRTC_BST
USRTC_REDBLACK
USRTC_SPLAY
USRTC_AVL