The linked list library provides a set of functions for manipulating linked lists.
A linked list is made up of elements where the first element must be a pointer. This pointer is used by the linked list library to form lists of the elements.
Lists are declared with the LIST() macro. The declaration specifies the name of the list that later is used with all list functions.
Lists can be manipulated by inserting or removing elements from either sides of the list (list_push(), list_add(), list_pop(), list_chop()). A specified element can also be removed from inside a list with list_remove(). The head and tail of a list can be extracted using list_head() and list_tail(), respectively.
Data Structures | |
struct | list |
Files | |
file | wireless/SmartConnect_6LoWPAN/core/lib/list.c |
Linked list library implementation. | |
file | wireless/SmartConnect_6LoWPAN/core/lib/list.h |
Linked list manipulation routines. | |
Macros | |
#define | LIST(name) |
Declare a linked list. More... | |
#define | LIST_CONCAT(s1, s2) LIST_CONCAT2(s1, s2) |
#define | LIST_CONCAT2(s1, s2) s1##s2 |
#define | LIST_STRUCT(name) |
Declare a linked list inside a structure declaraction. More... | |
#define | LIST_STRUCT_INIT(struct_ptr, name) |
Initialize a linked list that is part of a structure. More... | |
#define | NULL 0 |
Typedefs | |
typedef void ** | list_t |
The linked list type. More... | |
Functions | |
void | list_add (list_t list, void *item) |
Add an item at the end of a list. More... | |
void * | list_chop (list_t list) |
Remove the last object on the list. More... | |
void | list_copy (list_t dest, list_t src) |
Duplicate a list. More... | |
void * | list_head (list_t list) |
Get a pointer to the first element of a list. More... | |
void | list_init (list_t list) |
Initialize a list. More... | |
void | list_insert (list_t list, void *previtem, void *newitem) |
Insert an item after a specified item on the list. More... | |
void * | list_item_next (void *item) |
Get the next item following this item. More... | |
int | list_length (list_t list) |
Get the length of a list. More... | |
void * | list_pop (list_t list) |
Remove the first object on a list. More... | |
void | list_push (list_t list, void *item) |
Add an item to the start of the list. More... | |
void | list_remove (list_t list, void *item) |
Remove a specific element from a list. More... | |
void * | list_tail (list_t list) |
Get the tail of a list. More... | |
#define LIST | ( | name | ) |
Declare a linked list.
This macro declares a linked list with the specified type
. The type must be a structure (struct
) with its first element being a pointer. This pointer is used by the linked list library to form the linked lists.
The list variable is declared as static to make it easy to use in a single C module without unnecessarily exporting the name to other modules.
name | The name of the list. |
#define LIST_CONCAT | ( | s1, | |
s2 | |||
) | LIST_CONCAT2(s1, s2) |
#define LIST_CONCAT2 | ( | s1, | |
s2 | |||
) | s1##s2 |
#define LIST_STRUCT | ( | name | ) |
Declare a linked list inside a structure declaraction.
This macro declares a linked list with the specified type
. The type must be a structure (struct
) with its first element being a pointer. This pointer is used by the linked list library to form the linked lists.
Internally, the list is defined as two items: the list itself and a pointer to the list. The pointer has the name of the parameter to the macro and the name of the list is a concatenation of the name and the suffix "_list". The pointer must point to the list for the list to work. Thus the list must be initialized before using.
The list is initialized with the LIST_STRUCT_INIT() macro.
name | The name of the list. |
#define LIST_STRUCT_INIT | ( | struct_ptr, | |
name | |||
) |
Initialize a linked list that is part of a structure.
This macro sets up the internal pointers in a list that has been defined as part of a struct. This macro must be called before using the list.
struct_ptr | A pointer to the struct |
name | The name of the list. |
Referenced by send_packet(), and uip_ds6_route_add().
#define NULL 0 |
Referenced by list_add(), list_chop(), list_init(), list_insert(), list_item_next(), list_length(), list_pop(), list_remove(), and list_tail().
typedef void** list_t |
The linked list type.
void list_add | ( | list_t | list, |
void * | item | ||
) |
Add an item at the end of a list.
This function adds an item to the end of the list.
list | The list. |
item | A pointer to the item to be added. |
References list_remove(), list_tail(), next, and NULL.
Referenced by ctimer_reset(), ctimer_restart(), ctimer_set(), handle_incoming_reg(), http_socket_get(), http_socket_post(), if(), ip64_addrmap_create(), mmem_alloc(), nbr_table_add_lladdr(), packetqueue_enqueue_packetbuf(), send_packet(), tcp_socket_register(), uip_ds6_route_add(), uip_ds6_route_lookup(), uip_icmp6_echo_reply_callback_add(), uip_icmp6_register_input_handler(), and websocket_open().
void * list_chop | ( | list_t | list | ) |
Remove the last object on the list.
This function removes the last object on the list and returns it.
list | The list |
Referenced by uaodv_rt_add().
Duplicate a list.
This function duplicates a list by copying the list reference, but not the elements.
dest | The destination list. |
src | The source list. |
void * list_head | ( | list_t | list | ) |
Get a pointer to the first element of a list.
This function returns a pointer to the first element of the list. The element will not be removed from the list.
list | The list. |
Referenced by appcall(), check_age(), ctimer_expired(), echo_reply_input(), free_packet(), http_socket_close(), index_from_lladdr(), input_handler_lookup(), ip64_addrmap_create(), ip64_addrmap_list(), ip64_addrmap_lookup(), ip64_addrmap_lookup_port(), nbr_table_allocate(), nbr_table_head(), neighbor_queue_from_addr(), packet_sent(), packetqueue_dequeue(), packetqueue_first(), PROCESS_THREAD(), purge_registrations(), queuebuf_debug_print(), recycle(), rm_routelist(), send_packet(), send_udp_packet(), servreg_hack_list_head(), servreg_hack_register(), transmit_packet_list(), uaodv_rt_lookup_any(), uaodv_rt_lru(), uip_ds6_defrt_choose(), uip_ds6_defrt_lookup(), uip_ds6_defrt_periodic(), uip_ds6_defrt_rm(), uip_ds6_route_head(), and uip_ds6_route_rm().
void list_init | ( | list_t | list | ) |
Initialize a list.
This function initalizes a list. The list will be empty after this function has been called.
list | The list to be initialized. |
References NULL.
Referenced by ctimer_init(), init(), ip64_addrmap_init(), mmem_init(), packetqueue_init(), servreg_hack_init(), uaodv_rt_init(), uip_ds6_route_init(), and websocket_init().
void list_insert | ( | list_t | list, |
void * | previtem, | ||
void * | newitem | ||
) |
Insert an item after a specified item on the list.
list | The list |
previtem | The item after which the new item should be inserted |
newitem | The new item that is to be inserted |
References list_push(), and NULL.
void * list_item_next | ( | void * | item | ) |
Get the next item following this item.
item | A list item |
This function takes a list item and returns the next item on the list, or NULL if there are no more items on the list. This function is used when iterating through lists.
References NULL.
Referenced by appcall(), check_age(), echo_reply_input(), handle_dao_timer(), handle_incoming_reg(), http_socket_close(), index_from_lladdr(), input_handler_lookup(), ip64_addrmap_create(), ip64_addrmap_lookup(), ip64_addrmap_lookup_port(), nbr_table_allocate(), nbr_table_next(), neighbor_queue_from_addr(), packet_sent(), PROCESS_THREAD(), purge_registrations(), qsend_list(), queuebuf_debug_print(), recycle(), rpl_purge_routes(), rpl_remove_routes(), send_udp_packet(), servreg_hack_lookup(), servreg_hack_register(), uip_ds6_defrt_choose(), uip_ds6_defrt_lookup(), uip_ds6_defrt_periodic(), uip_ds6_defrt_rm(), uip_ds6_route_next(), and uip_ds6_route_rm().
int list_length | ( | list_t | list | ) |
Get the length of a list.
This function counts the number of elements on a specified list.
list | The list. |
Referenced by free_packet(), packetqueue_len(), send_packet(), and transmit_packet_list().
void * list_pop | ( | list_t | list | ) |
Remove the first object on a list.
This function removes the first object on the list and returns a pointer to it.
list | The list. |
Referenced by uaodv_rt_flush_all().
void list_push | ( | list_t | list, |
void * | item | ||
) |
Add an item to the start of the list.
References list_remove().
Referenced by handle_incoming_reg(), list_insert(), send_packet(), servreg_hack_register(), uaodv_rt_add(), uaodv_rt_lru(), and uip_ds6_defrt_add().
void list_remove | ( | list_t | list, |
void * | item | ||
) |
Remove a specific element from a list.
This function removes a specified element from the list.
list | The list. |
item | The item that is to be removed from the list. |
Referenced by check_age(), ctimer_reset(), ctimer_restart(), ctimer_set(), ctimer_stop(), free_packet(), handle_incoming_reg(), list_add(), list_push(), mmem_free(), nbr_table_allocate(), packetqueue_dequeue(), PROCESS_THREAD(), purge_registrations(), queuebuf_free(), recycle(), remove_queued_packet(), removesocket(), send_packet(), tcp_socket_unregister(), uaodv_rt_add(), uaodv_rt_lru(), uip_ds6_defrt_rm(), uip_ds6_route_lookup(), uip_ds6_route_rm(), and uip_icmp6_echo_reply_callback_rm().
void * list_tail | ( | list_t | list | ) |
Get the tail of a list.
This function returns a pointer to the elements following the first element of a list. No elements are removed by this function.
list | The list |
Referenced by list_add().