Turnstone Operating System
Loading...
Searching...
No Matches
list.64.c File Reference

generic linked list implementation More...

#include <types.h>
#include <list.h>
#include <indexer.h>
#include <cpu/sync.h>
#include <strings.h>
#include <logging.h>

Classes

struct  list_item_t
 
struct  list_t
 list internal interface More...
 

Typedefs

typedef struct list_item_t list_item_t
 short hand for struct More...
 
typedef struct list_t list_t
 linked list implicit type
 

Functions

 MODULE ("turnstone.lib")
 
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)
 
memory_heap_tlist_get_heap (list_t *list)
 returns list's heap 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...
 
int8_t list_set_equality_comparator (list_t *list, list_data_comparator_f comparator)
 sets equality comparator for list More...
 
size_t list_size (const list_t *list)
 returns item count at linked list More...
 
int8_t list_merge (list_t *self, list_t *list)
 merge given list into self list More...
 
const void * list_get_data_from_listitem (list_item_t *item)
 return data inside implicit list item type More...
 
list_tlinkedlist_create_with_type (memory_heap_t *heap, list_type_t type, list_data_comparator_f comparator, indexer_t indexer)
 
list_tarraylist_create_with_type (memory_heap_t *heap, list_type_t type, list_data_comparator_f comparator, indexer_t indexer)
 
list_tlist_create_with_type (memory_heap_t *heap, list_type_t type, list_data_comparator_f comparator, indexer_t indexer)
 linked list creator More...
 
uint8_t linkedlist_destroy_with_type (list_t *list, list_destroy_type_t type, list_item_destroyer_callback_f destroyer)
 
uint8_t arraylist_destroy_with_type (list_t *list, list_destroy_type_t type, list_item_destroyer_callback_f destroyer)
 
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 linkedlist_insert_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position)
 
size_t arraylist_insert_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position)
 
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 * linkedlist_delete_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position)
 
const void * arraylist_delete_at (list_t *list, const void *data, list_insert_delete_at_t where, size_t position)
 
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...
 
const void * linkedlist_get_data_at_position (list_t *list, size_t position)
 
const void * arraylist_get_data_at_position (list_t *list, size_t position)
 
const void * list_get_data_at_position (list_t *list, size_t position)
 returns position of given data. More...
 
int8_t linkedlist_get_position (list_t *list, const void *data, size_t *position)
 
int8_t arraylist_get_position (list_t *list, const void *data, size_t *position)
 
int8_t list_get_position (list_t *list, const void *data, size_t *position)
 returns position of given data. More...
 
iterator_tlinkedlist_iterator_create (list_t *list)
 
iterator_tarraylist_iterator_create (list_t *list)
 
iterator_tlist_iterator_create (list_t *list)
 creates an iterator from the list More...
 
int8_t arraylist_set_capacity (list_t *list, size_t capacity)
 
int8_t list_set_capacity (list_t *list, size_t capacity)
 sets list's capacity More...
 
list_tlinkedlist_duplicate_list_with_heap (memory_heap_t *heap, list_t *list)
 
list_tarraylist_duplicate_list_with_heap (memory_heap_t *heap, list_t *list)
 
list_tlist_duplicate_list_with_heap (memory_heap_t *heap, list_t *list)
 duplicates list at the given heap More...
 

Detailed Description

generic linked list implementation

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Typedef Documentation

◆ list_item_t

short hand for struct

linked list item implicit type

Function Documentation

◆ list_create_with_type()

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

Parameters
[in]heapmemory_heap_t the heap where linked list will be at.
[in]typelist_type_t linked list type
[in]comparatorlist_data_comparator_f data comparator used at sorted list
[in]indexerindexer_t index linked list nodes.
Returns
list_t

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.

◆ list_default_data_comparator()

int8_t list_default_data_comparator ( const void *  data1,
const void *  data2 
)

linked list default data comparator

Parameters
data1item 1
data2item 2
Returns
-1 data1<data2, 0 data1=data2, 1 data1>data2

assumes data1 and data2 is size_t pointer

◆ list_delete_at()

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.

Parameters
[in]listthe list
[in]datathe data
[in]wherewhere and how the data will be inserted
[in]positionif data will be deleted by position
Returns
the deleted data

◆ list_destroy_with_type()

uint8_t list_destroy_with_type ( list_t list,
list_destroy_type_t  type,
list_item_destroyer_callback_f  destroyer 
)

destroys linked list

Parameters
[in]listlist_t* the list to be destoyed
[in]typelist_destroy_type_t the type with
[in]destroyerlist_item_destroyer_callback_f destroyer callback, it frees list item
Returns
0 on success.

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_duplicate_list_with_heap()

list_t * list_duplicate_list_with_heap ( memory_heap_t heap,
list_t list 
)

duplicates list at the given heap

Parameters
[in]heapthe heap where the list will be created
[in]listsource list
Returns
a new list at heap

if heap is NULL then the new heap is same as source list's heap.

◆ list_get_data_at_position()

const void * list_get_data_at_position ( list_t list,
size_t  position 
)

returns position of given data.

Parameters
listlist to search
positionposition of data
Returns
data if found or null

◆ list_get_data_from_listitem()

const void * list_get_data_from_listitem ( list_item_t list_item)

return data inside implicit list item type

Parameters
[in]list_itemlist item
Returns
data inside the list.

◆ list_get_heap()

memory_heap_t * list_get_heap ( list_t list)

returns list's heap

Parameters
[in]listlist to be get heap
Returns
memory_heap_t

◆ list_get_position()

int8_t list_get_position ( list_t list,
const void *  data,
size_t position 
)

returns position of given data.

Parameters
[in]listlist to search
[in]datadata to search
[position]position the position of data if found
Returns
0 if data found, else -1.

◆ list_insert_at()

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.

Parameters
[in]listthe list
[in]datathe data
[in]wherewhere and how the data will be inserted
[in]positionif data will be added by position
Returns
insertation location

◆ list_iterator_create()

iterator_t * list_iterator_create ( list_t list)

creates an iterator from the list

Parameters
[in]listsource list
Returns
the iterator

the returned type is implicit. see also list_iterator_internal_t iterator is created at the heap of list.

◆ list_merge()

int8_t list_merge ( list_t self,
list_t list 
)

merge given list into self list

Parameters
[in]selfsource list
[in]listdestination list
Returns
0 on success

◆ list_set_capacity()

int8_t list_set_capacity ( list_t list,
size_t  capacity 
)

sets list's capacity

Parameters
[in]listlist to be modified
capacitynew capacity
Returns
0 on success

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_set_comparator()

list_data_comparator_f list_set_comparator ( list_t list,
list_data_comparator_f  comparator 
)

updates list's comparator and returns the old one.

Parameters
[in]listlist to be modified
comparatornew comparator
Returns
old comparator

◆ list_set_equality_comparator()

int8_t list_set_equality_comparator ( list_t list,
list_data_comparator_f  comparator 
)

sets equality comparator for list

Parameters
[in]listsource list
[in]comparatorcomparator function
Returns
0 on success

◆ list_size()

size_t list_size ( const list_t list)

returns item count at linked list

Parameters
[in]listlist_t* the list whose size will be returned
Returns
size_t linked list size