Turnstone Operating System
|
linked list interface More...
Typedefs | |
typedef enum list_insert_delete_at_t | list_insert_delete_at_t |
linked list operation enum More... | |
typedef enum list_type_t | list_type_t |
linked list type More... | |
typedef enum list_destroy_type_t | list_destroy_type_t |
linked list destroy type | |
typedef struct list_t | list_t |
typedef struct list_item_t | list_item_t |
typedef int8_t(* | list_data_comparator_f) (const void *data1, const void *data2) |
comparing given to data More... | |
typedef int8_t(* | list_item_destroyer_callback_f) (memory_heap_t *heap, void *data) |
Enumerations | |
enum | list_insert_delete_at_t { LIST_INSERT_AT_HEAD , LIST_INSERT_AT_TAIL , LIST_INSERT_AT_POSITION , LIST_INSERT_AT_SORTED , LIST_INSERT_AT_INDEXED , LIST_DELETE_AT_HEAD , LIST_DELETE_AT_TAIL , LIST_DELETE_AT_FINDBY , LIST_DELETE_AT_POSITION } |
linked list operation enum More... | |
enum | list_type_t { LIST_TYPE_LIST = 1 << 0 , LIST_TYPE_SORTEDLIST = 1 << 1 , LIST_TYPE_QUEUE = 1 << 2 , LIST_TYPE_STACK = 1 << 3 , LIST_TYPE_INDEXEDLIST = 1 << 8 , LIST_TYPE_LINKED = 1 << 9 , LIST_TYPE_ARRAY = 1 << 10 } |
linked list type More... | |
enum | list_destroy_type_t { LIST_DESTROY_WITHOUT_DATA , LIST_DESTROY_WITH_DATA } |
linked list destroy type More... | |
Functions | |
int8_t | list_default_data_comparator (const void *data1, const void *data2) |
linked list default data comparator More... | |
int8_t | list_string_comprator (const void *data1, const void *data2) |
list_t * | list_create_with_type (memory_heap_t *heap, list_type_t type, list_data_comparator_f comparator, indexer_t indexer) |
linked list creator More... | |
memory_heap_t * | list_get_heap (list_t *list) |
returns list's heap More... | |
int8_t | list_set_capacity (list_t *list, size_t capacity) |
sets list's capacity More... | |
list_data_comparator_f | list_set_comparator (list_t *list, list_data_comparator_f comparator) |
updates list's comparator and returns the old one. More... | |
uint8_t | list_destroy_with_type (list_t *list, list_destroy_type_t type, list_item_destroyer_callback_f destroyer) |
destroys linked list More... | |
size_t | list_size (const list_t *list) |
returns item count at linked list More... | |
const void * | list_get_data_from_listitem (list_item_t *list_item) |
return data inside implicit list item type More... | |
size_t | list_insert_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position) |
general method for inserting or deleting data from list types. More... | |
const void * | list_delete_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position) |
general method for inserting or deleting data from list types. More... | |
list_item_t * | list_insert_at_head_and_get_list_item (list_t *list, const void *data) |
boolean_t | list_move_item_to_head (list_t *list, list_item_t *item) |
boolean_t | list_delete_list_item (list_t *list, list_item_t *item) |
int8_t | list_get_position (list_t *list, const void *data, size_t *position) |
returns position of given data. More... | |
const void * | list_get_data_at_position (list_t *list, size_t position) |
returns position of given data. More... | |
list_t * | list_duplicate_list_with_heap (memory_heap_t *heap, list_t *list) |
duplicates list at the given heap More... | |
iterator_t * | list_iterator_create (list_t *list) |
creates an iterator from the list More... | |
int8_t | list_set_equality_comparator (list_t *list, list_data_comparator_f comparator) |
sets equality comparator for list More... | |
int8_t | list_merge (list_t *self, list_t *list) |
merge given list into self list More... | |
linked list interface
This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.
#define ___LIST_H 0 |
prevent duplicate header error macro
#define list_create_indexedlist | ( | i | ) | list_create_with_type(memory_get_heap(NULL), LIST_TYPE_INDEXEDLIST, NULL, i) |
#define list_create_indexedlist_with_heap | ( | h, | |
i | |||
) | list_create_with_type(memory_get_heap(h), LIST_TYPE_INDEXEDLIST, NULL, i) |
creates a indexed linked list at heap
[in] | h | memory_heap_t the heap of linked list. |
[in] | i | indexer_t indexer used sorting list. |
#define list_create_list | ( | ) | list_create_with_type(memory_get_heap(NULL), LIST_TYPE_LIST, NULL, NULL) |
creates a normal linked list at default heap heap
#define list_create_list_with_heap | ( | h | ) | list_create_with_type(memory_get_heap(h), LIST_TYPE_LIST, NULL, NULL) |
creates a normal linked list at heap
[in] | h | memory_heap_t the heap of linked list. |
#define list_create_queue | ( | ) | list_create_with_type(memory_get_heap(NULL), LIST_TYPE_QUEUE, NULL, NULL) |
creates a queue at default heap heap
#define list_create_queue_with_heap | ( | h | ) | list_create_with_type(memory_get_heap(h), LIST_TYPE_QUEUE, NULL, NULL) |
#define list_create_sortedlist | ( | c | ) | list_create_with_type(memory_get_heap(NULL), LIST_TYPE_SORTEDLIST, c, NULL) |
creates a sorted linked list at default heap
[in] | c | list_data_comparator_f comparator used sorting list. |
#define list_create_sortedlist_with_heap | ( | h, | |
c | |||
) | list_create_with_type(memory_get_heap(h), LIST_TYPE_SORTEDLIST, c, NULL) |
creates a sorted linked list at heap
[in] | h | memory_heap_t the heap of linked list. |
[in] | c | list_data_comparator_f comparator used sorting list. |
#define list_create_stack | ( | ) | list_create_with_type(memory_get_heap(NULL), LIST_TYPE_STACK, NULL, NULL) |
creates a stack at default heap heap
#define list_create_stack_with_heap | ( | h | ) | list_create_with_type(memory_get_heap(h), LIST_TYPE_STACK, NULL, NULL) |
#define list_delete_at_position | ( | l, | |
p | |||
) | list_delete_at(l, NULL, LIST_DELETE_AT_POSITION, p) |
delete data with position from list
#define list_delete_at_tail | ( | l | ) | list_delete_at(l, NULL, LIST_DELETE_AT_TAIL, 0) |
delete data at tail (end) of list
#define list_destroy | ( | l | ) | list_destroy_with_type(l, LIST_DESTROY_WITHOUT_DATA, NULL) |
destroy without data macro
#define list_destroy_with_data | ( | l | ) | list_destroy_with_type(l, LIST_DESTROY_WITH_DATA, NULL) |
destroy with data macro
#define list_duplicate_list | ( | l | ) | list_duplicate_list_with_heap(NULL, l); |
duplicate linked list with same as heap at source list
#define list_indexedlist_delete | ( | l, | |
d | |||
) | list_delete_at(l, d, LIST_DELETE_AT_FINDBY, 0) |
delete and get data from indexed list
#define list_indexedlist_insert | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_INDEXED, 0) |
insert data into indexed list
#define LIST_INSERT_AT_ANYWHERE LIST_INSERT_AT_TAIL |
insert data at anywhere of list (at tail for o(1))
#define list_insert_at_head | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_HEAD, 0) |
insert data into head
#define list_insert_at_position | ( | l, | |
d, | |||
p | |||
) | list_insert_at(l, d, LIST_INSERT_AT_POSITION, p) |
insert data with position into list
#define list_list_delete | ( | l, | |
d | |||
) | list_delete_at(l, d, LIST_DELETE_AT_FINDBY, 0) |
delete and get data from normal list
#define list_list_insert | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_ANYWHERE, 0) |
insert data into normal list
#define list_queue_pop | ( | l | ) | list_delete_at(l, NULL, LIST_DELETE_AT_HEAD, 0) |
delete and get data from queue
#define list_queue_push | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_TAIL, 0) |
insert data into queue
#define list_sortedlist_delete | ( | l, | |
d | |||
) | list_delete_at(l, d, LIST_DELETE_AT_FINDBY, 0) |
delete and get data from sorted list
#define list_sortedlist_insert | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_SORTED, 0) |
insert data into sorted list
#define list_stack_pop | ( | l | ) | list_delete_at(l, NULL, LIST_DELETE_AT_HEAD, 0) |
delete and get data from stack
#define list_stack_push | ( | l, | |
d | |||
) | list_insert_at(l, d, LIST_INSERT_AT_HEAD, 0) |
insert data into stack
typedef int8_t(* list_data_comparator_f) (const void *data1, const void *data2) |
comparing given to data
[in] | data1 | |
[in] | data2 |
compares data1 and data2. this comparator used when linked list sorted.
typedef enum list_insert_delete_at_t list_insert_delete_at_t |
linked list operation enum
inserting/deleting will be performed with this values.
typedef enum list_type_t list_type_t |
linked list type
used only information
enum list_destroy_type_t |
linked list operation enum
inserting/deleting will be performed with this values.
enum list_type_t |
list_t * list_create_with_type | ( | memory_heap_t * | heap, |
list_type_t | type, | ||
list_data_comparator_f | comparator, | ||
indexer_t | indexer | ||
) |
linked list creator
[in] | heap | memory_heap_t the heap where linked list will be at. |
[in] | type | list_type_t linked list type |
[in] | comparator | list_data_comparator_f data comparator used at sorted list |
[in] | indexer | indexer_t index linked list nodes. |
creates linked list with given arguments. for each type of linked list there is a macro. do not use this method directly.
if heap is null then linked list created at default heap.
int8_t list_default_data_comparator | ( | const void * | data1, |
const void * | data2 | ||
) |
linked list default data comparator
data1 | item 1 |
data2 | item 2 |
assumes data1 and data2 is size_t pointer
const void * list_delete_at | ( | list_t * | list, |
const void * | data, | ||
list_insert_delete_at_t | where, | ||
size_t | position | ||
) |
general method for inserting or deleting data from list types.
[in] | list | the list |
[in] | data | the data |
[in] | where | where and how the data will be inserted |
[in] | position | if data will be deleted by position |
uint8_t list_destroy_with_type | ( | list_t * | list, |
list_destroy_type_t | type, | ||
list_item_destroyer_callback_f | destroyer | ||
) |
destroys linked list
[in] | list | list_t* the list to be destoyed |
[in] | type | list_destroy_type_t the type with |
[in] | destroyer | list_item_destroyer_callback_f destroyer callback, it frees list item |
this method destroys only the linked list with choice of preserving data. if you do not destroy the data a memory leak will be happened if without data destroying
list_t * list_duplicate_list_with_heap | ( | memory_heap_t * | heap, |
list_t * | list | ||
) |
duplicates list at the given heap
[in] | heap | the heap where the list will be created |
[in] | list | source list |
if heap is NULL then the new heap is same as source list's heap.
returns position of given data.
list | list to search |
position | position of data |
const void * list_get_data_from_listitem | ( | list_item_t * | list_item | ) |
return data inside implicit list item type
[in] | list_item | list item |
memory_heap_t * list_get_heap | ( | list_t * | list | ) |
returns position of given data.
[in] | list | list to search |
[in] | data | data to search |
[position] | position the position of data if found |
size_t list_insert_at | ( | list_t * | list, |
const void * | data, | ||
list_insert_delete_at_t | where, | ||
size_t | position | ||
) |
general method for inserting or deleting data from list types.
[in] | list | the list |
[in] | data | the data |
[in] | where | where and how the data will be inserted |
[in] | position | if data will be added by position |
iterator_t * list_iterator_create | ( | list_t * | list | ) |
creates an iterator from the list
[in] | list | source list |
the returned type is implicit. see also list_iterator_internal_t iterator is created at the heap of list.
merge given list into self list
[in] | self | source list |
[in] | list | destination list |
sets list's capacity
[in] | list | list to be modified |
capacity | new capacity |
if list is null then this method returns -1. if new capacity is less than current size of list then this method returns -1. if list is not array list then this method returns -2.
list_data_comparator_f list_set_comparator | ( | list_t * | list, |
list_data_comparator_f | comparator | ||
) |
updates list's comparator and returns the old one.
[in] | list | list to be modified |
comparator | new comparator |
int8_t list_set_equality_comparator | ( | list_t * | list, |
list_data_comparator_f | comparator | ||
) |
sets equality comparator for list
[in] | list | source list |
[in] | comparator | comparator function |