Changeset b72efe8 in mainline for uspace/lib/c/generic/adt
- Timestamp:
- 2011-06-19T14:38:59Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74464e8
- Parents:
- 1d1bb0f
- Location:
- uspace/lib/c/generic/adt
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/hash_table.c
r1d1bb0f rb72efe8 61 61 assert(max_keys > 0); 62 62 63 h->entry = malloc(m * sizeof(li nk_t));63 h->entry = malloc(m * sizeof(list_t)); 64 64 if (!h->entry) 65 65 return false; 66 66 67 memset((void *) h->entry, 0, m * sizeof(li nk_t));67 memset((void *) h->entry, 0, m * sizeof(list_t)); 68 68 69 69 hash_count_t i; … … 123 123 assert(chain < h->entries); 124 124 125 link_t *cur; 126 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 127 cur = cur->next) { 125 list_foreach(h->entry[chain], cur) { 128 126 if (h->op->compare(key, h->max_keys, cur)) { 129 127 /* … … 153 151 assert(keys <= h->max_keys); 154 152 155 link_t *cur;156 157 153 if (keys == h->max_keys) { 154 link_t *cur; 155 158 156 /* 159 157 * All keys are known, hash_table_find() can be used to find the … … 176 174 hash_index_t chain; 177 175 for (chain = 0; chain < h->entries; chain++) { 178 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 176 link_t *cur; 177 178 for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head; 179 179 cur = cur->next) { 180 180 if (h->op->compare(key, keys, cur)) { … … 203 203 { 204 204 hash_index_t bucket; 205 link_t *cur;206 205 207 206 for (bucket = 0; bucket < h->entries; bucket++) { 208 for (cur = h->entry[bucket].next; cur != &h->entry[bucket]; 209 cur = cur->next) { 207 list_foreach(h->entry[bucket], cur) { 210 208 f(cur, arg); 211 209 } -
uspace/lib/c/generic/adt/list.c
r1d1bb0f rb72efe8 30 30 * @{ 31 31 */ 32 /** @file 32 33 /** 34 * @file 35 * @brief Functions completing doubly linked circular list implementaion. 36 * 37 * This file contains some of the functions implementing doubly linked circular lists. 38 * However, this ADT is mostly implemented in @ref list.h. 33 39 */ 34 40 35 41 #include <adt/list.h> 36 42 #include <bool.h> 37 43 38 44 /** Check for membership 39 45 * 40 * Check whether link is contained in the list head.41 * The membership is defined as pointer equivalence.46 * Check whether link is contained in a list. 47 * Membership is defined as pointer equivalence. 42 48 * 43 * @param link 44 * @param headList to look in.49 * @param link Item to look for. 50 * @param list List to look in. 45 51 * 46 52 * @return true if link is contained in head, false otherwise. 47 53 * 48 54 */ 49 int list_member(const link_t *link, const li nk_t *head)55 int list_member(const link_t *link, const list_t *list) 50 56 { 51 int found = 0;52 link_t *hlp = head->next;57 bool found = false; 58 link_t *hlp = list->head.next; 53 59 54 while (hlp != head) {60 while (hlp != &list->head) { 55 61 if (hlp == link) { 56 found = 1;62 found = true; 57 63 break; 58 64 } … … 63 69 } 64 70 65 66 71 /** Concatenate two lists 67 72 * 68 * Concatenate lists head1 and head2, producing a single69 * list head1 containing items from both (in head1, head270 * order) and empty list head2.73 * Concatenate lists @a list1 and @a list2, producing a single 74 * list @a list1 containing items from both (in @a list1, @a list2 75 * order) and empty list @a list2. 71 76 * 72 * @param head1First list and concatenated output73 * @param head2Second list and empty output.77 * @param list1 First list and concatenated output 78 * @param list2 Second list and empty output. 74 79 * 75 80 */ 76 void list_concat(li nk_t *head1, link_t *head2)81 void list_concat(list_t *list1, list_t *list2) 77 82 { 78 if (list_empty( head2))83 if (list_empty(list2)) 79 84 return; 80 81 head2->next->prev = head1->prev;82 head2->prev->next = head1;83 head1->prev->next = head2->next;84 head1->prev = head2->prev;85 list_initialize( head2);85 86 list2->head.next->prev = list1->head.prev; 87 list2->head.prev->next = &list1->head; 88 list1->head.prev->next = list2->head.next; 89 list1->head.prev = list2->head.prev; 90 list_initialize(list2); 86 91 } 87 88 92 89 93 /** Count list items … … 91 95 * Return the number of items in the list. 92 96 * 93 * @param link List to count. 94 * 95 * @return Number of items in the list. 96 * 97 * @param list List to count. 98 * @return Number of items in the list. 97 99 */ 98 unsigned int list_count(const li nk_t *link)100 unsigned int list_count(const list_t *list) 99 101 { 100 102 unsigned int count = 0; 101 link_t *hlp = link->next;102 103 103 while (hlp !=link) {104 list_foreach(*list, link) { 104 105 count++; 105 hlp = hlp->next;106 106 } 107 107 -
uspace/lib/c/generic/adt/prodcons.c
r1d1bb0f rb72efe8 61 61 fibril_condvar_wait(&pc->cv, &pc->mtx); 62 62 63 link_t *head = pc->list.next;63 link_t *head = list_first(&pc->list); 64 64 list_remove(head); 65 65
Note:
See TracChangeset
for help on using the changeset viewer.