Files | Functions

Cp_list

Files

file  linked_list.c
 

Implementation of cp_list Collection with linked elements and cp_list_iterator.


Functions

int cp_list_txlock (cp_list *list, int type)
int cp_list_txunlock (cp_list *list)
static cp_list_entrycp_list_create_entry (cp_list *list, void *item)
 Creates an entry with the mode of the list.
static cp_list_entrycp_list_insert_internal (cp_list *list, void *item)
 Unsynchronized and unchecked insert a new element at the beginning of the list.
static cp_list_entrycp_list_remove_internal (cp_list *list, cp_list_entry *entry)
 Unsynchronized and unchecked remove the entry from the list.
static cp_list_entrycp_list_append_internal (cp_list *list, void *item)
 Appends the element and returns the Entry.
static cp_list_entrycp_list_remove_head_internal (cp_list *list)
 Removes the first entry from the list and returns it.
static cp_list_entrycp_list_remove_tail_internal (cp_list *list)
 Removes the last entry from the list and returns it.
cp_listcp_list_create_internal (int mode, cp_compare_fn compare_fn, cp_copy_fn copy_fn, cp_destructor_fn item_destructor, int is_view)
cp_listcp_list_create ()
 Default constructor.
cp_listcp_list_create_nosync ()
cp_listcp_list_create_list (int mode, cp_compare_fn compare_fn, cp_copy_fn copy_fn, cp_destructor_fn item_destructor)
 Constructor.
cp_listcp_list_create_view (int mode, cp_compare_fn compare_fn, cp_copy_fn copy_fn, cp_destructor_fn item_destructor, cp_lock *lock)
void cp_list_destroy_internal (cp_list *list, cp_destructor_fn fn, int mode)
void cp_list_destroy (cp_list *list)
 Destroy the object with the mode stored in the list.
void cp_list_destroy_by_option (cp_list *list, int option)
 Destroy the object with the specified mode (override default).
void cp_list_destroy_custom (cp_list *list, cp_destructor_fn fn)
 Destroy the object and all contained elements.
long cp_list_item_count (cp_list *list)
 Get the number of elements in the collection.
static cp_list_entry ** cp_list_get_entry_ref (cp_list *list, void *item)
void * cp_list_insert (cp_list *list, void *item)
 Insert a new element at the beginning of the list.
void * cp_list_remove (cp_list *list, void *item)
 Remove the element from the list.
void * cp_list_insert_after (cp_list *list, void *item, void *existing)
 Insert the element after an existing one.
void * cp_list_insert_before (cp_list *list, void *item, void *existing)
 Insert the element before an existing one.
void * cp_list_search (cp_list *list, void *item)
 Get the first element that equals the parameter.
int cp_list_callback (cp_list *l, int(*item_action)(void *, void *), void *id)
 run a callback on each item.
void * cp_list_append (cp_list *list, void *item)
 Append the element at the end of the list.
void * cp_list_get_head (cp_list *list)
 Returns the first element of the list.
void * cp_list_get_tail (cp_list *list)
 Returns the last element of the list.
void * cp_list_remove_head (cp_list *list)
 remove and release first entry
void * cp_list_remove_tail (cp_list *list)
 remove and release last entry
int cp_list_is_empty (cp_list *list)
 Test if object is empty.
int cp_list_lock_internal (cp_list *list, int mode)
int cp_list_unlock_internal (cp_list *list)
int cp_list_lock (cp_list *list, int type)
 Locks the collection with the specified mode.
int cp_list_unlock (cp_list *list)
 Unlock the object.
int cp_list_get_mode (cp_list *list)
int cp_list_set_mode (cp_list *list, int mode)
int cp_list_unset_mode (cp_list *list, int mode)
int cp_list_use_mempool (cp_list *list, cp_mempool *pool)
int cp_list_share_mempool (cp_list *list, cp_shared_mempool *pool)
cp_list_iteratorcp_list_create_iterator (cp_list *list, int type)
 create a new iterator and initialize it at the beginning of the list.
int cp_list_iterator_init (cp_list_iterator *iterator, cp_list *list, int type)
 Initialize the Iterator at the first position.
int cp_list_iterator_head (cp_list_iterator *iterator)
 Move the iterator to the beginning of the list.
int cp_list_iterator_tail (cp_list_iterator *iterator)
 Move the iterator to the end of the list.
int cp_list_iterator_init_tail (cp_list_iterator *iterator, cp_list *list, int type)
 Initialize the Iterator at the end.
int cp_list_iterator_release (cp_list_iterator *iterator)
 unlock the list the iterator is operating on.
int cp_list_iterator_destroy (cp_list_iterator *iterator)
void * cp_list_iterator_next (cp_list_iterator *iterator)
 Go to the next entry in the list and return the content.
void * cp_list_iterator_prev (cp_list_iterator *iterator)
 Go to the previous entry in the list and return the content.
void * cp_list_iterator_curr (cp_list_iterator *iterator)
 returns the value at the current iterator position
void * cp_list_iterator_insert (cp_list_iterator *iterator, void *item)
 insert item to the list just before the current iterator position.
void * cp_list_iterator_append (cp_list_iterator *iterator, void *item)
 append item to the list just after the current iterator position.
void * cp_list_iterator_remove (cp_list_iterator *iterator)
 delete the item at the current iterator position.

Function Documentation

void* cp_list_append ( cp_list list,
void *  item 
)

Append the element at the end of the list.

Return values:
item the appended item.
existing_item if multiple values not allowed and an equal item already exists.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_MULTIPLE_VALUES, cp_list_append_internal(), and cp_list_entry.

Referenced by cp_db_connection_pool_create(), cp_db_register_dbms(), cp_result_set_next(), cp_thread_pool_set_available(), and lookup_internal().

int cp_list_callback ( cp_list l,
int(*)(void *, void *)  item_action,
void *  id 
)

run a callback on each item.

Stops if the callback function returns non-zero.

References COLLECTION_LOCK_READ, and cp_list_entry.

static cp_list_entry * cp_list_create_entry ( cp_list list,
void *  item 
) [static]

Creates an entry with the mode of the list.

The new entry is not added to the list. If the list has copy mode, it copies the item and puts the copy into the new entry.

Returns:
entry object for the item.

References cp_list_entry.

Referenced by cp_list_append_internal(), cp_list_insert_after(), cp_list_insert_before(), cp_list_insert_internal(), cp_list_iterator_append(), and cp_list_iterator_insert().

cp_list_iterator* cp_list_create_iterator ( cp_list list,
int  lock_mode 
)

create a new iterator and initialize it at the beginning of the list.

Parameters:
list the list to iterate over
lock_mode locking mode to use
Returns:
new iterator object
cp_list* cp_list_create_list ( int  mode,
cp_compare_fn  compare_fn,
cp_copy_fn  copy_fn,
cp_destructor_fn  item_destructor 
)

Constructor.

Parameters:
mode operation mode bitmap (see collection.h)
compare_fn compare method
copy_fn copy method

Referenced by cp_db_connection_pool_create().

void cp_list_destroy_custom ( cp_list list,
cp_destructor_fn  fn 
)

Destroy the object and all contained elements.

For each element the method cp_destructor_fn is called.

Referenced by cp_db_shutdown().

void* cp_list_insert ( cp_list list,
void *  item 
)

Insert a new element at the beginning of the list.

The operation is synchronized according to the properties of the object.

References COLLECTION_LOCK_WRITE, COLLECTION_MODE_MULTIPLE_VALUES, cp_list_entry, and cp_list_insert_internal().

Referenced by cp_db_connection_pool_release_connection(), and lookup_internal().

int cp_list_is_empty ( cp_list list  ) 

Test if object is empty.

Return values:
true if no element contained.
false if at least one element is contained.

References COLLECTION_LOCK_READ.

long cp_list_item_count ( cp_list  ) 

Get the number of elements in the collection.

Returns:
number of elements in the list.
Return values:
0 if list is NULL

Referenced by cp_db_connection_pool_shutdown(), and cp_db_register_dbms().

void* cp_list_iterator_append ( cp_list_iterator iterator,
void *  item 
)

append item to the list just after the current iterator position.

In the special case that the iterator has been moved beyond the list head the new item is added at the head of the list.

Returns:
the added item or NULL if the list mode is not & COLLECTION_MODE_NOSYNC and the iterator does not own a write lock

References COLLECTION_LOCK_WRITE, cp_list_create_entry(), and cp_list_entry.

void* cp_list_iterator_curr ( cp_list_iterator iterator  ) 

returns the value at the current iterator position

Returns:
value at the current position.
Return values:
NULL if list is empty.
int cp_list_iterator_init ( cp_list_iterator iterator,
cp_list list,
int  lock_mode 
)

Initialize the Iterator at the first position.

Set the iterator at the beginning of the list and lock the list in the mode specified in type.

Parameters:
iterator the iterator object
list the list to iterate over
lock_mode locking mode to use
Return values:
return-code of the aquired lock
0 if no locking
int cp_list_iterator_init_tail ( cp_list_iterator iterator,
cp_list list,
int  lock_mode 
)

Initialize the Iterator at the end.

Set the iterator at the end of the list and lock the list in the mode specified in type.

Parameters:
iterator the iterator object
list the list to iterate over
lock_mode locking mode to use
Return values:
return-code of the aquired lock
0 if no locking
void* cp_list_iterator_insert ( cp_list_iterator iterator,
void *  item 
)

insert item to the list just before the current iterator position.

In the special case that the iterator has been moved beyond the list end the new item is added at the end of the list.

Returns:
the added item or NULL if the list mode is not & COLLECTION_MODE_NOSYNC and the iterator does not own a write lock

References COLLECTION_LOCK_WRITE, cp_list_create_entry(), and cp_list_entry.

void* cp_list_iterator_next ( cp_list_iterator iterator  ) 

Go to the next entry in the list and return the content.

Returns:
object of the next entry.
Return values:
NULL if reading beyond end or from empty list.
void* cp_list_iterator_prev ( cp_list_iterator iterator  ) 

Go to the previous entry in the list and return the content.

Returns:
object of the previous entry.
Return values:
NULL if reading beyond beginning or from empty list.
void* cp_list_iterator_remove ( cp_list_iterator iterator  ) 

delete the item at the current iterator position.

Returns:
the deleted item or NULL the list is empty, if the iterator points beyond list limits or if the list mode is not & COLLECTION_MODE_NOSYNC and the iterator does not own a write lock

References COLLECTION_LOCK_WRITE, cp_list_entry, cp_list_remove_internal(), _cp_list_entry::next, and _cp_list_entry::prev.

int cp_list_lock ( cp_list list,
int  mode 
)

Locks the collection with the specified mode.

This overrides the default mode stored in the object.

void* cp_list_remove ( cp_list list,
void *  item 
)

Remove the element from the list.

The operation is synchronized according to the properties of the object.

References COLLECTION_LOCK_WRITE, cp_list_entry, and cp_list_remove_internal().

void* cp_list_remove_head ( cp_list list  ) 
static cp_list_entry * cp_list_remove_head_internal ( cp_list list  )  [static]

Removes the first entry from the list and returns it.

Sets the references into a consistent state.

References cp_list_entry, and _cp_list_entry::next.

Referenced by cp_list_remove_head().

void* cp_list_remove_tail ( cp_list list  ) 

remove and release last entry

Returns:
Element that was stored in the last entry.

References COLLECTION_LOCK_WRITE, cp_list_entry, and cp_list_remove_tail_internal().

static cp_list_entry * cp_list_remove_tail_internal ( cp_list list  )  [static]

Removes the last entry from the list and returns it.

Sets the references into a consistent state.

References cp_list_entry, and _cp_list_entry::prev.

Referenced by cp_list_remove_tail().