Skip to content

swanav/linked-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake CodeQL CodeFactor codecov FOSSA Status

Linked List

API Documentation


Insert an item

void linked_list_Insert ( LinkedListRef** list, void* item );

Insert a new Item to the LinkedList

  • param list - Reference to the LinkedList
  • param item - Reference to the item to be added

Remove an item

void* linked_list_Remove ( LinkedListRef** list, void* item );

Remove an item from the LinkedList

  • param list - Reference to the LinkedList
  • param item - Reference to the item to be removed
  • returns void* - Reference to the recently removed item, NULL if item is not found
  • @warning Freeing the allocated memory of the returned pointer is the developer's responsibility.

Iterate all items

void linked_list_Iterate ( LinkedListRef** list, IterateMethod callbackMethod, void* userData );

Iterate all items in the LinkedList

  • param list - Reference to the LinkedList
  • param callbackMethod - A callback function which is called for each item
  • param userData - A pointer which is sent to the callback method.

Search for an item

void* linked_list_Search ( LinkedListRef** list, SearchMethod testMethod, void* userData );

Search for an item in the LinkedList

  • param list - Reference to the LinkedList
  • param testMethod - A callback function which is called for each item as a comparison test.
  • param userData - A pointer which is sent to the callback method.
  • returns void* Reference to the item found as a result of the search, NULL if item not found.

Drop a Linked List

void linked_list_Drop ( LinkedListRef** list, FreeMethod freeCallback );

Free the complete Linked List and the data it contains.

  • param list - Reference to the LinkedList.
  • param freeCallback - Callback Method called for each item removed from linked list.
  • @warning Developer should free the memory of that item in this callback.

Type Definitions

LinkedListRef Structure

struct __linked_list_item_ref {
    void* data;
    struct __linked_list_item_ref* next;
};

typedef struct __linked_list_item_ref LinkedListRef;

SearchMethod Callback

typedef bool (*SearchMethod) (void* listItem, void* userData);

Callback Method template for search operation in a LinkedList

  • param listItem - A test item
  • param userData - A pointer as given to linked_list_Search
  • returns boolean - true if comparison successful, false otherwise

Iterate Method Callback

typedef void (*IterateMethod)(int index, void* listItem, void* userData);

Callback Method for each item in the iteration of the linked list

  • param index - item index
  • param listItem - An item from the linked list
  • param userData - A pointer as given to linked_list_Iterate

Free Method Callback

typedef void (*FreeMethod)(void* listItem);

Callback Method for each item in the iteration of the linked list

  • param listItem - Pointer to the item to be freed.

License

FOSSA Status