source: trunk/kernel/libk/grdxt.h @ 304

Last change on this file since 304 was 1, checked in by alain, 8 years ago

First import

File size: 6.8 KB
Line 
1/*
2 * grdxt.h - Three-levels Generic Radix-tree interface
3 *
4 * Authors  Alain Greiner (2016)
5 *
6 * Copyright  UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _GRDXT_H_
25#define _GRDXT_H_
26
27#include <hal_types.h>
28
29/*******************************************************************************************
30 * This structure defines a three levels radix-tree descriptor.
31 * The key is split in three fields : ix1 (MSB) / ix2 / ix3 (LSB) to index the first,
32 * second and third level arrays respectively.
33 * The pointers on the registered items are stored in the third level arrays.
34 * The number or bits for each field are parameters for the grdxt_init() function.
35 * Memory for the first level array is allocated by the grdxt_init() function.
36 * Memory for the second and third levels arrays is dynamically allocated by the
37 * grdxt_insert() function and is only released by grdxt_destroy().
38 * - It used to by the VMM to retrieve a vseg descriptor: key is the virtual address.
39 * - It is used by the mapper to implement the file cache: key is the page index in file.
40 ******************************************************************************************/
41
42typedef struct grdxt_s
43{
44        void          ** root;           /*! pointer on first level array of pointers         */
45        uint32_t         ix1_width;      /*! number of bits for first level array index       */
46        uint32_t         ix2_width;      /*! number of bits for second level array index      */
47    uint32_t         ix3_width;      /*! number of bits for third level array index       */
48}
49grdxt_t;
50
51
52/*******************************************************************************************
53 * This function initialises the radix-tree descriptor,
54 * and allocates memory for the first level array of pointers.
55 *******************************************************************************************
56 * @ rt        : pointer on the radix-tree descriptor.
57 * @ ix1_width : number of bits in ix1 field
58 * @ ix2_width : number of bits in ix2 field
59 * @ ix3_width : number of bits in ix3 field
60 * @ returns 0 if success / returns ENOMEM if no more memory.     
61 ******************************************************************************************/
62error_t grdxt_init( grdxt_t  * rt,
63                    uint32_t   ix1_width,
64                    uint32_t   ix2_width,
65                    uint32_t   ix3_width );
66
67/*******************************************************************************************
68 * This function releases all memory allocated to the radix-tree infrastructure.
69 * The radix-tree is supposed to be empty, but this is NOT checked by this function.
70 *******************************************************************************************
71 * @ rt      : pointer on the radix-tree descriptor.
72 ******************************************************************************************/
73void grdxt_destroy( grdxt_t * rt );
74
75/*******************************************************************************************
76 * This function insert a new item in the radix-tree.
77 * It dynamically allocates memory for new second and third level arrays if required.
78 *******************************************************************************************
79 * @ rt      : pointer on the radix-tree descriptor.
80 * @ key     : key value.
81 * @ value   : pointer on item to be registered in radix-tree.
82 * @ returns 0 if success / returns ENOMEM if no memory, or EINVAL if illegal key.
83 ******************************************************************************************/
84error_t grdxt_insert( grdxt_t  * rt,
85                      uint32_t   key,
86                      void     * value );
87
88/*******************************************************************************************
89 * This function removes an item identified by its key, and returns a pointer
90 * on the removed item. No memory is released.
91 *******************************************************************************************
92 * @ rt      : pointer on the radix-tree descriptor.
93 * @ key     : key value.
94 * @ returns pointer on removed item if success / returns NULL if failure.
95 ******************************************************************************************/
96void * grdxt_remove( grdxt_t  * rt,
97                     uint32_t   key );
98
99/*******************************************************************************************
100 * This function returns the pointer on the item identified by its key.
101 *******************************************************************************************
102 * @ rt      : pointer on the radix-tree descriptor.
103 * @ key     : key value.
104 * @ returns pointer on found item if success / returns NULL if failure.
105 ******************************************************************************************/
106void * grdxt_lookup( grdxt_t  * rt, 
107                     uint32_t   key );
108
109/*******************************************************************************************
110 * This function scan all radix-tree entries in increasing key order, starting from
111 * the value defined by the <key> argument, and return a pointer on the first valid
112 * registered item, and the found item key value.
113 *******************************************************************************************
114 * @ rt         : pointer on the radix-tree descriptor.
115 * @ start_key  : key starting value for the scan.
116 * @ found_key  : [out] buffer for found key value.
117 * return pointer on first valid item if found / return NULL if not found.
118 ******************************************************************************************/
119void * grdxt_get_first( grdxt_t  * rt,
120                        uint32_t   start_key,
121                        uint32_t * found_key );
122
123/*******************************************************************************************
124 * This function displays the content of the radix_tree.
125 *******************************************************************************************
126 * @ rt      : pointer on the radix-tree descriptor.
127 * @ name    : string identifying the radix-tree.
128 ******************************************************************************************/
129void grdxt_print( grdxt_t * rt,
130                  char    * name );
131
132
133#endif  /* _GRDXT_H_ */
134
Note: See TracBrowser for help on using the repository browser.