mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-03 23:47:08 +00:00
linked_list: add pop and get_first_item operations
This commit is contained in:
parent
43ab8f9679
commit
67711d5ef9
@ -95,11 +95,6 @@ void btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_i
|
||||
it->next = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove data_source from run loop
|
||||
*
|
||||
* @note: assumes that btstack_data_source_t.next is first element in data_source
|
||||
*/
|
||||
int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item){ // <-- remove item from list
|
||||
if (!item) return -1;
|
||||
btstack_linked_item_t *it;
|
||||
@ -124,6 +119,20 @@ int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_ite
|
||||
return counter;
|
||||
}
|
||||
|
||||
// get first element
|
||||
btstack_linked_item_t * btstack_linked_list_get_first_item(btstack_linked_list_t * list){
|
||||
return * list;
|
||||
}
|
||||
|
||||
// pop (get + remove) first element
|
||||
btstack_linked_item_t * btstack_linked_list_pop(btstack_linked_list_t * list){
|
||||
btstack_linked_item_t * item = *list;
|
||||
if (!item) return NULL;
|
||||
*list = item->next;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Linked List Iterator implementation
|
||||
//
|
||||
|
@ -64,9 +64,13 @@ int btstack_linked_list_empty(btstack_linked_list_t * list);
|
||||
// add item to list as first element
|
||||
void btstack_linked_list_add(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
// add item to list as last element
|
||||
void btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
void btstack_linked_list_add_tail(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
// pop (get + remove) first element
|
||||
btstack_linked_item_t * btstack_linked_list_pop(btstack_linked_list_t * list);
|
||||
// remove item from list
|
||||
int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_item_t *item);
|
||||
// get first element
|
||||
btstack_linked_item_t * btstack_linked_list_get_first_item(btstack_linked_list_t * list);
|
||||
// find the last item in the list
|
||||
btstack_linked_item_t * btstack_linked_list_get_last_item(btstack_linked_list_t * list);
|
||||
|
||||
|
@ -32,6 +32,19 @@ TEST(LinkedList, CountAll){
|
||||
CHECK_EQUAL(4, btstack_linked_list_count(&testList));
|
||||
}
|
||||
|
||||
TEST(LinkedList, GetFirst){
|
||||
btstack_linked_item_t * item;
|
||||
item = btstack_linked_list_get_first_item(&testList);
|
||||
CHECK_EQUAL(item, &itemA);
|
||||
}
|
||||
|
||||
TEST(LinkedList, Pop){
|
||||
btstack_linked_item_t * item;
|
||||
item = btstack_linked_list_pop(&testList);
|
||||
CHECK_EQUAL(item, &itemA);
|
||||
CHECK_EQUAL(3, btstack_linked_list_count(&testList));
|
||||
}
|
||||
|
||||
TEST(LinkedList, Iterator){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &testList);
|
||||
|
Loading…
Reference in New Issue
Block a user