Files | |
file | bitmap.h |
file | btree.h |
file | fifo.h |
file | hash_table.h |
file | list.h |
file | bitmap.c |
Implementation of bitmap ADT. | |
file | btree.c |
B+tree implementation. | |
file | hash_table.c |
Implementation of generic chained hash table. | |
file | list.c |
Functions completing doubly linked circular list implementaion. | |
Data Structures | |
struct | bitmap_t |
struct | btree_node |
struct | btree |
struct | hash_table |
struct | hash_table_operations |
struct | link |
Defines | |
#define | BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0) |
#define | BTREE_M 5 |
#define | BTREE_MAX_KEYS (BTREE_M - 1) |
#define | FIFO_INITIALIZE_STATIC(name, t, itms) |
#define | FIFO_INITIALIZE_DYNAMIC(name, t, itms) |
#define | fifo_pop(name) name.fifo[name.head = (name.head + 1) < name.items ? (name.head + 1) : 0] |
#define | fifo_push(name, value) name.fifo[name.tail = (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value) |
#define | fifo_create(name) name.fifo = malloc(sizeof(*name.fifo) * name.items, 0) |
#define | hash_table_get_instance(item, type, member) list_get_instance((item), type, member) |
#define | LIST_INITIALIZE(name) link_t name = { .prev = &name, .next = &name } |
#define | list_get_instance(link, type, member) (type *)(((__u8*)(link))-((__u8*)&(((type *)NULL)->member))) |
#define | ALL_ONES 0xff |
#define | ALL_ZEROES 0x00 |
#define | ROOT_NODE(n) (!(n)->parent) |
#define | INDEX_NODE(n) ((n)->subtree[0] != NULL) |
#define | LEAF_NODE(n) ((n)->subtree[0] == NULL) |
#define | FILL_FACTOR ((BTREE_M-1)/2) |
#define | MEDIAN_LOW_INDEX(n) (((n)->keys-1)/2) |
#define | MEDIAN_HIGH_INDEX(n) ((n)->keys/2) |
#define | MEDIAN_LOW(n) ((n)->key[MEDIAN_LOW_INDEX((n))]); |
#define | MEDIAN_HIGH(n) ((n)->key[MEDIAN_HIGH_INDEX((n))]); |
Typedefs | |
typedef __u64 | btree_key_t |
Functions | |
void | bitmap_initialize (bitmap_t *bitmap, __u8 *map, count_t bits) |
void | bitmap_set_range (bitmap_t *bitmap, index_t start, count_t bits) |
void | bitmap_clear_range (bitmap_t *bitmap, index_t start, count_t bits) |
void | bitmap_copy (bitmap_t *dst, bitmap_t *src, count_t bits) |
void | btree_init (void) |
void | btree_create (btree_t *t) |
void | btree_destroy (btree_t *t) |
void | btree_insert (btree_t *t, btree_key_t key, void *value, btree_node_t *leaf_node) |
void | btree_remove (btree_t *t, btree_key_t key, btree_node_t *leaf_node) |
void * | btree_search (btree_t *t, btree_key_t key, btree_node_t **leaf_node) |
btree_node_t * | btree_leaf_node_left_neighbour (btree_t *t, btree_node_t *node) |
btree_node_t * | btree_leaf_node_right_neighbour (btree_t *t, btree_node_t *node) |
void | btree_print (btree_t *t) |
void | hash_table_create (hash_table_t *h, count_t m, count_t max_keys, hash_table_operations_t *op) |
void | hash_table_insert (hash_table_t *h, __native key[], link_t *item) |
link_t * | hash_table_find (hash_table_t *h, __native key[]) |
void | hash_table_remove (hash_table_t *h, __native key[], count_t keys) |
static void | link_initialize (link_t *link) |
static void | list_initialize (link_t *head) |
static void | list_prepend (link_t *link, link_t *head) |
static void | list_append (link_t *link, link_t *head) |
static void | list_remove (link_t *link) |
static bool | list_empty (link_t *head) |
static void | headless_list_split_or_concat (link_t *part1, link_t *part2) |
static void | headless_list_split (link_t *part1, link_t *part2) |
static void | headless_list_concat (link_t *part1, link_t *part2) |
bool | list_member (const link_t *link, const link_t *head) |
void | list_concat (link_t *head1, link_t *head2) |
static void | btree_destroy_subtree (btree_node_t *root) |
static void | _btree_insert (btree_t *t, btree_key_t key, void *value, btree_node_t *rsubtree, btree_node_t *node) |
static void | _btree_remove (btree_t *t, btree_key_t key, btree_node_t *node) |
static void | node_initialize (btree_node_t *node) |
static void | node_insert_key_and_lsubtree (btree_node_t *node, btree_key_t key, void *value, btree_node_t *lsubtree) |
static void | node_insert_key_and_rsubtree (btree_node_t *node, btree_key_t key, void *value, btree_node_t *rsubtree) |
static void | node_remove_key_and_lsubtree (btree_node_t *node, btree_key_t key) |
static void | node_remove_key_and_rsubtree (btree_node_t *node, btree_key_t key) |
static btree_node_t * | node_split (btree_node_t *node, btree_key_t key, void *value, btree_node_t *rsubtree, btree_key_t *median) |
static btree_node_t * | node_combine (btree_node_t *node) |
static index_t | find_key_by_subtree (btree_node_t *node, btree_node_t *subtree, bool right) |
static void | rotate_from_right (btree_node_t *lnode, btree_node_t *rnode, index_t idx) |
static void | rotate_from_left (btree_node_t *lnode, btree_node_t *rnode, index_t idx) |
static bool | try_insert_by_rotation_to_left (btree_node_t *node, btree_key_t key, void *value, btree_node_t *rsubtree) |
static bool | try_insert_by_rotation_to_right (btree_node_t *node, btree_key_t key, void *value, btree_node_t *rsubtree) |
static bool | try_rotation_from_left (btree_node_t *rnode) |
static bool | try_rotation_from_right (btree_node_t *lnode) |
Variables | |
static slab_cache_t * | btree_node_slab |
|
Definition at line 47 of file bitmap.c. Referenced by bitmap_set_range(). |
|
Definition at line 48 of file bitmap.c. Referenced by bitmap_clear_range(). |
|
Definition at line 41 of file bitmap.h. Referenced by ddi_iospace_enable_arch(), and io_perm_bitmap_install(). |
|
|
|
Definition at line 43 of file btree.h. Referenced by _btree_insert(), node_initialize(), node_split(), try_insert_by_rotation_to_left(), and try_insert_by_rotation_to_right(). |
|
Allocate memory for dynamic FIFO.
|
|
Value: struct { \ t *fifo; \ count_t items; \ index_t head; \ index_t tail; \ } name = { \ .fifo = NULL, \ .items = (itms), \ .head = 0, \ .tail = 0 \ } FIFO is allocated dynamically. This macro is suitable for creating larger FIFOs.
|
|
Value: struct { \ t fifo[(itms)]; \ count_t items; \ index_t head; \ index_t tail; \ } name = { \ .items = (itms), \ .head = 0, \ .tail = 0 \ } FIFO is allocated statically. This macro is suitable for creating smaller FIFOs.
|
|
Pop value from head of FIFO.
|
|
Push value to tail of FIFO.
|
|
Definition at line 79 of file btree.c. Referenced by _btree_remove(), try_rotation_from_left(), and try_rotation_from_right(). |
|
Definition at line 75 of file hash_table.h. Referenced by futex_find(), futex_ht_compare(), and futex_ht_remove_callback(). |
|
Definition at line 76 of file btree.c. Referenced by node_combine(), and node_split(). |
|
Definition at line 77 of file btree.c. Referenced by _btree_insert(), btree_leaf_node_left_neighbour(), btree_leaf_node_right_neighbour(), btree_search(), rotate_from_left(), and rotate_from_right(). |
|
|
Declare and initialize statically allocated list.
|
|
Definition at line 84 of file btree.c. Referenced by node_split(). |
|
Definition at line 82 of file btree.c. Referenced by node_split(). |
|
|
|
|
|
Definition at line 75 of file btree.c. Referenced by _btree_insert(), _btree_remove(), node_combine(), try_insert_by_rotation_to_left(), try_insert_by_rotation_to_right(), try_rotation_from_left(), and try_rotation_from_right(). |
|
|
|
Recursively insert into B-tree.
Definition at line 160 of file btree.c. References BTREE_MAX_KEYS, btree_node_slab, btree_node::depth, btree_node::keys, btree_node::leaf_link, LEAF_NODE, list_prepend(), node_initialize(), node_insert_key_and_rsubtree(), node_split(), NULL, btree_node::parent, btree::root, ROOT_NODE, slab_alloc(), btree_node::subtree, try_insert_by_rotation_to_left(), and try_insert_by_rotation_to_right(). Referenced by btree_insert(). Here is the call graph for this function: ![]() |
|
Recursively remove B-tree node.
Definition at line 241 of file btree.c. References btree_node_slab, FILL_FACTOR, btree_node::key, btree_node::keys, node_remove_key_and_rsubtree(), NULL, btree_node::parent, btree::root, ROOT_NODE, slab_free(), btree_node::subtree, try_rotation_from_left(), and try_rotation_from_right(). Referenced by btree_remove(). Here is the call graph for this function: ![]() |
|
Clear range of bits.
Definition at line 120 of file bitmap.c. References ALIGN_UP, ALL_ZEROES, ASSERT, bitmap_t::map, and min. Referenced by bitmap_copy(), and ddi_iospace_enable_arch(). |
|
Copy portion of one bitmap into another bitmap.
Definition at line 172 of file bitmap.c. References ASSERT, bitmap_clear_range(), and bitmap_t::map. Referenced by ddi_iospace_enable_arch(), and io_perm_bitmap_install(). Here is the call graph for this function: ![]() |
|
Initialize bitmap. No portion of the bitmap is set or cleared by this function.
Definition at line 58 of file bitmap.c. References bitmap_t::bits, and bitmap_t::map. Referenced by ddi_iospace_enable_arch(), io_perm_bitmap_install(), and task_create_arch(). |
|
Set range of bits.
Definition at line 70 of file bitmap.c. References ALIGN_UP, ALL_ONES, ASSERT, bitmap_t::map, and min. Referenced by ddi_iospace_enable_arch(), and io_perm_bitmap_install(). |
|
Create empty B-tree.
Definition at line 98 of file btree.c. References btree_node_slab, btree::leaf_head, btree_node::leaf_link, list_append(), list_initialize(), node_initialize(), btree::root, and slab_alloc(). Referenced by as_area_create(), as_area_share(), as_create(), task_create(), task_init(), and thread_init(). Here is the call graph for this function: ![]() |
|
Destroy empty B-tree. Definition at line 107 of file btree.c. References btree_destroy_subtree(), and btree::root. Referenced by sh_info_remove_reference(), and task_destroy(). Here is the call graph for this function: ![]() |
|
Destroy subtree rooted in a node.
Definition at line 139 of file btree.c. References btree_node::keys, btree::root, and btree_node::subtree. Referenced by btree_destroy(). |
|
Initialize B-trees. Definition at line 89 of file btree.c. References btree_node_slab, NULL, slab_cache_create(), and SLAB_CACHE_MAGDEFERRED. Referenced by main_bsp_separated_stack(). Here is the call graph for this function: ![]() |
|
Insert key-value pair into B-tree.
Definition at line 119 of file btree.c. References _btree_insert(), ASSERT, btree_search(), NULL, and panic. Referenced by anon_page_fault(), anon_share(), as_area_create(), elf_share(), futex_find(), task_create(), thread_create(), and used_space_insert(). Here is the call graph for this function: ![]() |
|
Return pointer to B-tree leaf node's left neighbour.
Definition at line 383 of file btree.c. References ASSERT, btree::leaf_head, btree_node::leaf_link, LEAF_NODE, list_get_instance, NULL, and link::prev. Referenced by check_area_conflicts(), elf_share(), and used_space_insert(). |
|
Return pointer to B-tree leaf node's right neighbour.
Definition at line 399 of file btree.c. References ASSERT, btree::leaf_head, btree_node::leaf_link, LEAF_NODE, list_get_instance, link::next, and NULL. Referenced by check_area_conflicts(), and used_space_insert(). |
|
Print B-tree.
Definition at line 942 of file btree.c. References ASSERT, btree_node::bfs_link, btree_node::depth, btree_node::key, btree_node::keys, list_append(), list_empty(), list_get_instance, list_initialize(), list_remove(), link::next, printf(), btree::root, and btree_node::subtree. Here is the call graph for this function: ![]() |
|
Remove B-tree node.
Definition at line 221 of file btree.c. References _btree_remove(), btree_search(), and panic. Referenced by task_kill(), thread_destroy(), used_space_insert(), and used_space_remove(). Here is the call graph for this function: ![]() |
|
Search key in a B-tree.
Definition at line 318 of file btree.c. References btree_node::key, btree_node::keys, LEAF_NODE, NULL, btree::root, btree_node::subtree, and btree_node::value. Referenced by anon_page_fault(), btree_insert(), btree_remove(), check_area_conflicts(), elf_page_fault(), elf_share(), find_area_and_lock(), futex_find(), task_find_by_id(), thread_exists(), used_space_insert(), and used_space_remove(). |
|
Find key by its left or right subtree.
Definition at line 689 of file btree.c. References btree_node::keys, and btree_node::subtree. Referenced by node_combine(), try_insert_by_rotation_to_left(), try_insert_by_rotation_to_right(), try_rotation_from_left(), and try_rotation_from_right(). |
|
Create chained hash table.
Definition at line 55 of file hash_table.c. References ASSERT, hash_table_operations::compare, hash_table::entries, hash_table::entry, hash_table_operations::hash, list_initialize(), malloc(), hash_table::max_keys, memsetb(), hash_table::op, and panic. Referenced by futex_init(). Here is the call graph for this function: ![]() |
|
Search hash table for an item matching keys.
Definition at line 103 of file hash_table.c. References ASSERT, hash_table_operations::compare, hash_table::entry, hash_table_operations::hash, hash_table::max_keys, link::next, and hash_table::op. Referenced by futex_find(), and hash_table_remove(). |
|
Insert item into hash table.
Definition at line 83 of file hash_table.c. References ASSERT, hash_table_operations::compare, hash_table::entry, hash_table_operations::hash, list_append(), and hash_table::op. Referenced by futex_find(). Here is the call graph for this function: ![]() |
|
Remove all matching items from hash table. For each removed item, h->remove_callback() is called.
Definition at line 133 of file hash_table.c. References ASSERT, hash_table_operations::compare, hash_table::entries, hash_table::entry, hash_table_operations::hash, hash_table_find(), list_remove(), hash_table::max_keys, link::next, hash_table::op, link::prev, and hash_table_operations::remove_callback. Referenced by futex_cleanup(). Here is the call graph for this function: ![]() |
|
Concatenate two headless doubly-linked circular lists Concatenate two headless doubly-linked circular lists.
Definition at line 173 of file list.h. References headless_list_split_or_concat(). Here is the call graph for this function: ![]() |
|
Split headless doubly-linked circular list Split headless doubly-linked circular list.
Definition at line 161 of file list.h. References headless_list_split_or_concat(). Here is the call graph for this function: ![]() |
|
Split or concatenate headless doubly-linked circular list Split or concatenate headless doubly-linked circular list. Note that the algorithm works both directions: concatenates splitted lists and splits concatenated lists.
Definition at line 142 of file list.h. References link::next, and link::prev. Referenced by headless_list_concat(), and headless_list_split(). |
|
Initialize doubly-linked circular list link Initialize doubly-linked list link.
Definition at line 59 of file list.h. References link::next, NULL, and link::prev. Referenced by as_create(), cmd_initialize(), futex_initialize(), list_remove(), thr_constructor(), and timeout_reinitialize(). |
|
Add item to the end of doubly-linked circular list Add item to the end of doubly-linked circular list.
Definition at line 99 of file list.h. References link::next, and link::prev. Referenced by _ipc_answer_free_call(), _ipc_call(), _slab_cache_create(), as_switch(), btree_create(), btree_print(), buddy_system_free(), cmd_register(), hash_table_insert(), ipc_phone_connect(), ipc_wait_for_call(), send_call(), thread_create(), thread_ready(), and waitq_sleep_timeout_unsafe(). |
|
Concatenate two lists Concatenate lists head1 and head2, producing a single list head1 containing items from both (in head1, head2 order) and empty list head2.
Definition at line 81 of file list.c. References list_empty(), list_initialize(), link::next, and link::prev. Referenced by relink_rq(). Here is the call graph for this function: ![]() |
|
Query emptiness of doubly-linked circular list Query emptiness of doubly-linked circular list.
Definition at line 126 of file list.h. References link::next. Referenced by _rwlock_read_lock_timeout(), _waitq_wakeup_unsafe(), as_area_resize(), as_destroy(), btree_print(), buddy_system_alloc(), buddy_system_can_alloc(), buddy_system_structure_print(), get_mag_from_cache(), ipc_cleanup(), ipc_cleanup_call_list(), ipc_wait_for_call(), let_others_in(), list_concat(), slab_cache_destroy(), and slab_obj_create(). |
|
Initialize doubly-linked circular list Initialize doubly-linked circular list.
Definition at line 71 of file list.h. References link::next, and link::prev. Referenced by _slab_cache_create(), btree_create(), btree_print(), buddy_system_create(), cpu_init(), hash_table_create(), ipc_answerbox_init(), list_concat(), relink_rq(), task_create(), timeout_init(), and waitq_initialize(). |
|
Check for membership Check whether link is contained in the list head. The membership is defined as pointer equivalence.
Definition at line 54 of file list.c. References link::next. |
|
Add item to the beginning of doubly-linked circular list Add item to the beginning of doubly-linked circular list.
Definition at line 84 of file list.h. References link::next, and link::prev. Referenced by _btree_insert(), put_mag_to_cache(), slab_obj_create(), slab_obj_destroy(), and timeout_register(). |
|
Remove item from doubly-linked circular list Remove item from doubly-linked circular list.
Definition at line 113 of file list.h. References link_initialize(), link::next, and link::prev. Referenced by _waitq_wakeup_unsafe(), answer_preprocess(), as_destroy(), as_switch(), btree_print(), buddy_system_alloc(), buddy_system_alloc_block(), buddy_system_free(), clock(), get_mag_from_cache(), hash_table_remove(), ipc_answer(), ipc_cleanup_call_list(), ipc_forward(), ipc_phone_hangup(), ipc_wait_for_call(), kcpulb(), slab_cache_destroy(), slab_obj_create(), slab_obj_destroy(), thread_destroy(), timeout_unregister(), waitq_interrupt_sleep(), and waitq_timeouted_sleep(). Here is the call graph for this function: ![]() |
|
Combine node with any of its siblings. The siblings are required to be below the fill factor.
Definition at line 638 of file btree.c. References ASSERT, find_key_by_subtree(), INDEX_NODE, btree_node::key, btree_node::keys, btree_node::parent, ROOT_NODE, btree_node::subtree, and btree_node::value. Here is the call graph for this function: ![]() |
|
Initialize B-tree node.
Definition at line 412 of file btree.c. References BTREE_MAX_KEYS, btree_node::key, btree_node::keys, NULL, btree_node::subtree, and btree_node::value. Referenced by _btree_insert(), btree_create(), and node_split(). |
|
Insert key-value-lsubtree triplet into B-tree node. It is actually possible to have more keys than BTREE_MAX_KEYS. This feature is used during insert by right rotation.
Definition at line 444 of file btree.c. References btree_node::key, btree_node::keys, btree_node::subtree, and btree_node::value. Referenced by rotate_from_left(). |
|
Insert key-value-rsubtree triplet into B-tree node. It is actually possible to have more keys than BTREE_MAX_KEYS. This feature is used during splitting the node when the number of keys is BTREE_MAX_KEYS + 1. Insert by left rotation also makes use of this feature.
Definition at line 480 of file btree.c. References btree_node::key, btree_node::keys, btree_node::subtree, and btree_node::value. Referenced by _btree_insert(), node_split(), rotate_from_right(), try_insert_by_rotation_to_left(), and try_insert_by_rotation_to_right(). |
|
Remove key and its left subtree pointer from B-tree node. Remove the key and eliminate gaps in node->key array. Note that the value pointer and the left subtree pointer is removed from the node as well.
Definition at line 512 of file btree.c. References btree_node::key, btree_node::keys, btree_node::subtree, and btree_node::value. Referenced by rotate_from_right(). |
|
Remove key and its right subtree pointer from B-tree node. Remove the key and eliminate gaps in node->key array. Note that the value pointer and the right subtree pointer is removed from the node as well.
Definition at line 540 of file btree.c. References btree_node::key, btree_node::keys, btree_node::subtree, and btree_node::value. Referenced by _btree_remove(), and rotate_from_left(). |
|
Split full B-tree node and insert new key-value-right-subtree triplet. This function will split a node and return pointer to a newly created node containing keys greater than or equal to the greater of medians (or median) of the old keys and the newly added key. It will also write the median key to a memory address supplied by the caller. If the node being split is an index node, the median will not be included in the new node. If the node is a leaf node, the median will be copied there.
Definition at line 577 of file btree.c. References ASSERT, BTREE_MAX_KEYS, btree_node_slab, btree_node::depth, INDEX_NODE, btree_node::key, btree_node::keys, MEDIAN_HIGH, MEDIAN_HIGH_INDEX, node_initialize(), node_insert_key_and_rsubtree(), btree_node::parent, slab_alloc(), btree_node::subtree, and btree_node::value. Referenced by _btree_insert(). Here is the call graph for this function: ![]() |
|
Rotate one key-value-rsubtree triplet from the left sibling to the right sibling. The biggest key and its value and right subtree is rotated from the left node to the right. If the node is an index node, than the parent node key belonging to the left node takes part in the rotation.
Definition at line 710 of file btree.c. References btree_node::key, btree_node::keys, LEAF_NODE, node_insert_key_and_lsubtree(), node_remove_key_and_rsubtree(), NULL, btree_node::parent, btree_node::subtree, and btree_node::value. Referenced by try_insert_by_rotation_to_right(), and try_rotation_from_left(). Here is the call graph for this function: ![]() |
|
Rotate one key-value-lsubtree triplet from the right sibling to the left sibling. The smallest key and its value and left subtree is rotated from the right node to the left. If the node is an index node, than the parent node key belonging to the right node takes part in the rotation.
Definition at line 747 of file btree.c. References btree_node::key, LEAF_NODE, node_insert_key_and_rsubtree(), node_remove_key_and_lsubtree(), NULL, btree_node::parent, btree_node::subtree, and btree_node::value. Referenced by try_insert_by_rotation_to_left(), and try_rotation_from_right(). Here is the call graph for this function: ![]() |
|
Insert key-value-rsubtree triplet and rotate the node to the left, if this operation can be done. Left sibling of the node (if it exists) is checked for free space. If there is free space, the key is inserted and the smallest key of the node is moved there. The index node which is the parent of both nodes is fixed.
Definition at line 788 of file btree.c. References BTREE_MAX_KEYS, find_key_by_subtree(), btree_node::keys, node_insert_key_and_rsubtree(), btree_node::parent, ROOT_NODE, rotate_from_right(), and btree_node::subtree. Referenced by _btree_insert(). Here is the call graph for this function: ![]() |
|
Insert key-value-rsubtree triplet and rotate the node to the right, if this operation can be done. Right sibling of the node (if it exists) is checked for free space. If there is free space, the key is inserted and the biggest key of the node is moved there. The index node which is the parent of both nodes is fixed.
Definition at line 835 of file btree.c. References BTREE_MAX_KEYS, find_key_by_subtree(), btree_node::keys, node_insert_key_and_rsubtree(), btree_node::parent, ROOT_NODE, rotate_from_left(), and btree_node::subtree. Referenced by _btree_insert(). Here is the call graph for this function: ![]() |
|
Rotate in a key from the left sibling or from the index node, if this operation can be done.
Definition at line 874 of file btree.c. References FILL_FACTOR, find_key_by_subtree(), btree_node::keys, btree_node::parent, ROOT_NODE, rotate_from_left(), and btree_node::subtree. Referenced by _btree_remove(). Here is the call graph for this function: ![]() |
|
Rotate in a key from the right sibling or from the index node, if this operation can be done.
Definition at line 909 of file btree.c. References FILL_FACTOR, find_key_by_subtree(), btree_node::keys, btree_node::parent, ROOT_NODE, rotate_from_right(), and btree_node::subtree. Referenced by _btree_remove(). Here is the call graph for this function: ![]() |
|
Definition at line 86 of file btree.c. Referenced by _btree_insert(), _btree_remove(), btree_create(), btree_init(), and node_split(). |