mdcore  0.1.5
/home/pedro/work/mdcore/src/btree.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of mdcore.
00003  * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as published
00007  * by the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  * 
00018  ******************************************************************************/
00019 
00021 #define btree_maxnodes                          8
00022 #define btree_minnodes                          4
00023 #define btree_cache                                     256
00024 
00025 
00027 #define btree_err_ok                            0
00028 #define btree_err_null              -1
00029 #define btree_err_malloc            -2
00030 #define btree_err_map               -3
00031 
00032 
00034 #define btree_flag_freeable         1
00035 #define btree_flag_leaf             2
00036 
00037 
00039 #define btree_maptype                           int (*)( void * , void * )
00040 
00041 
00043 extern int btree_err;
00044 
00045 
00047 struct btree_node {
00048 
00049         short int fill;                                 // nr of nodes in node  (2 bytes)
00050         unsigned short int flags;               // node flags           (2 bytes)
00051         void *data[btree_maxnodes + 1]; // node content         ((N+1)*4 bytes)
00052     int keys[btree_maxnodes + 1];   // node keys            ((N+1)*4 bytes)
00053         struct btree_node *nodes[btree_maxnodes + 2];
00054                                                                         // node branches;       ((N+2)*4 bytes)
00055 
00056         };
00057         
00058     
00060 struct btree {
00061 
00062         struct btree_node *first;               // first node in tree
00063         
00064         struct btree_node *cache;       // cached nodes
00065 
00066         };
00067         
00068         
00069 int btree_init ( struct btree *b );
00070 struct btree_node *btree_getnode ( struct btree *b );
00071 int btree_insert ( struct btree *b , int key , void *data );
00072 int btree_map ( struct btree *b , int (*func)( void * , void * ) , void *data );
00073 int btree_dump ( struct btree *b , FILE *out );
00074 int btree_find ( struct btree *b , int key , void **res );
00075 int btree_releasenode ( struct btree *b , struct btree_node *n );
00076 int btree_delete ( struct btree *b , int key , void **res );
00077 
00078 struct btree *btree_new ( );
00079 int btree_flush ( struct btree *b );
00080 int btree_count ( struct btree *b );
 All Data Structures Files Functions Variables Typedefs Enumerator Defines