Changeset 55b77d9 in mainline for kernel/generic/src/adt
- Timestamp:
- 2011-06-17T20:39:16Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8f164724
- Parents:
- 98caf49
- Location:
- kernel/generic/src/adt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/adt/btree.c
r98caf49 r55b77d9 108 108 void btree_create(btree_t *t) 109 109 { 110 list_initialize(&t->leaf_ head);110 list_initialize(&t->leaf_list); 111 111 t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0); 112 112 node_initialize(t->root); 113 list_append(&t->root->leaf_link, &t->leaf_ head);113 list_append(&t->root->leaf_link, &t->leaf_list); 114 114 } 115 115 … … 588 588 589 589 if (LEAF_NODE(node)) { 590 list_ prepend(&rnode->leaf_link, &node->leaf_link);590 list_insert_after(&rnode->leaf_link, &node->leaf_link); 591 591 } 592 592 … … 953 953 ASSERT(LEAF_NODE(node)); 954 954 955 if (node->leaf_link.prev != &t->leaf_ head)955 if (node->leaf_link.prev != &t->leaf_list.head) 956 956 return list_get_instance(node->leaf_link.prev, btree_node_t, leaf_link); 957 957 else … … 972 972 ASSERT(LEAF_NODE(node)); 973 973 974 if (node->leaf_link.next != &t->leaf_ head)974 if (node->leaf_link.next != &t->leaf_list.head) 975 975 return list_get_instance(node->leaf_link.next, btree_node_t, leaf_link); 976 976 else … … 987 987 size_t i; 988 988 int depth = t->root->depth; 989 li nk_t head, *cur;989 list_t list; 990 990 991 991 printf("Printing B-tree:\n"); 992 list_initialize(& head);993 list_append(&t->root->bfs_link, & head);992 list_initialize(&list); 993 list_append(&t->root->bfs_link, &list); 994 994 995 995 /* … … 997 997 * Levels are distinguished from one another by node->depth. 998 998 */ 999 while (!list_empty(& head)) {999 while (!list_empty(&list)) { 1000 1000 link_t *hlp; 1001 1001 btree_node_t *node; 1002 1002 1003 hlp = head.next;1004 ASSERT(hlp != &head);1003 hlp = list_first(&list); 1004 ASSERT(hlp != NULL); 1005 1005 node = list_get_instance(hlp, btree_node_t, bfs_link); 1006 1006 list_remove(hlp); … … 1018 1018 printf("%" PRIu64 "%s", node->key[i], i < node->keys - 1 ? "," : ""); 1019 1019 if (node->depth && node->subtree[i]) { 1020 list_append(&node->subtree[i]->bfs_link, & head);1020 list_append(&node->subtree[i]->bfs_link, &list); 1021 1021 } 1022 1022 } 1023 1023 1024 1024 if (node->depth && node->subtree[i]) 1025 list_append(&node->subtree[i]->bfs_link, & head);1025 list_append(&node->subtree[i]->bfs_link, &list); 1026 1026 1027 1027 printf(")"); … … 1031 1031 1032 1032 printf("Printing list of leaves:\n"); 1033 for (cur = t->leaf_head.next; cur != &t->leaf_head; cur = cur->next) {1033 list_foreach(t->leaf_list, cur) { 1034 1034 btree_node_t *node; 1035 1035 -
kernel/generic/src/adt/hash_table.c
r98caf49 r55b77d9 62 62 ASSERT(max_keys > 0); 63 63 64 h->entry = (li nk_t *) malloc(m * sizeof(link_t), 0);64 h->entry = (list_t *) malloc(m * sizeof(list_t), 0); 65 65 if (!h->entry) 66 66 panic("Cannot allocate memory for hash table."); 67 67 68 memsetb(h->entry, m * sizeof(li nk_t), 0);68 memsetb(h->entry, m * sizeof(list_t), 0); 69 69 70 70 for (i = 0; i < m; i++) … … 107 107 link_t *hash_table_find(hash_table_t *h, sysarg_t key[]) 108 108 { 109 link_t *cur;110 109 size_t chain; 111 110 … … 118 117 ASSERT(chain < h->entries); 119 118 120 for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) {119 list_foreach(h->entry[chain], cur) { 121 120 if (h->op->compare(key, h->max_keys, cur)) { 122 121 /* … … 141 140 { 142 141 size_t chain; 143 link_t *cur;144 142 145 143 ASSERT(h); … … 150 148 151 149 if (keys == h->max_keys) { 150 link_t *cur; 152 151 153 152 /* … … 169 168 */ 170 169 for (chain = 0; chain < h->entries; chain++) { 171 for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) {170 list_foreach(h->entry[chain], cur) { 172 171 if (h->op->compare(key, keys, cur)) { 173 172 link_t *hlp; -
kernel/generic/src/adt/list.c
r98caf49 r55b77d9 43 43 /** Check for membership 44 44 * 45 * Check whether link is contained in the list head.46 * The membership is defined as pointer equivalence.45 * Check whether link is contained in a list. 46 * Membership is defined as pointer equivalence. 47 47 * 48 * @param link 49 * @param headList to look in.48 * @param link Item to look for. 49 * @param list List to look in. 50 50 * 51 51 * @return true if link is contained in head, false otherwise. 52 52 * 53 53 */ 54 int list_member(const link_t *link, const li nk_t *head)54 int list_member(const link_t *link, const list_t *list) 55 55 { 56 56 bool found = false; 57 link_t *hlp = head->next;57 link_t *hlp = list->head.next; 58 58 59 while (hlp != head) {59 while (hlp != &list->head) { 60 60 if (hlp == link) { 61 61 found = true; … … 68 68 } 69 69 70 71 70 /** Concatenate two lists 72 71 * 73 * Concatenate lists head1 and head2, producing a single74 * list head1 containing items from both (in head1, head275 * order) and empty list head2.72 * Concatenate lists @a list1 and @a list2, producing a single 73 * list @a list1 containing items from both (in @a list1, @a list2 74 * order) and empty list @a list2. 76 75 * 77 * @param head1First list and concatenated output78 * @param head2Second list and empty output.76 * @param list1 First list and concatenated output 77 * @param list2 Second list and empty output. 79 78 * 80 79 */ 81 void list_concat(li nk_t *head1, link_t *head2)80 void list_concat(list_t *list1, list_t *list2) 82 81 { 83 if (list_empty( head2))82 if (list_empty(list2)) 84 83 return; 85 84 86 head2->next->prev = head1->prev;87 head2->prev->next = head1;88 head1->prev->next = head2->next;89 head1->prev = head2->prev;90 list_initialize( head2);85 list2->head.next->prev = list1->head.prev; 86 list2->head.prev->next = &list1->head; 87 list1->head.prev->next = list2->head.next; 88 list1->head.prev = list2->head.prev; 89 list_initialize(list2); 91 90 } 92 91
Note:
See TracChangeset
for help on using the changeset viewer.