{"id":25526268,"url":"https://github.com/exbotanical/lib.cartilage","last_synced_at":"2026-01-05T20:30:17.064Z","repository":{"id":46155171,"uuid":"384041800","full_name":"exbotanical/lib.cartilage","owner":"exbotanical","description":"classical implementations of list and ring data structures for the C programming language","archived":false,"fork":false,"pushed_at":"2022-11-05T20:54:54.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-04T10:26:26.611Z","etag":null,"topics":["data-structures","dynamically-linked-library","linked-list","shared-object"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exbotanical.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-08T07:39:16.000Z","updated_at":"2021-11-11T03:25:40.000Z","dependencies_parsed_at":"2022-09-03T22:10:47.938Z","dependency_job_id":null,"html_url":"https://github.com/exbotanical/lib.cartilage","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Flib.cartilage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Flib.cartilage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Flib.cartilage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exbotanical%2Flib.cartilage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exbotanical","download_url":"https://codeload.github.com/exbotanical/lib.cartilage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239735252,"owners_count":19688262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","dynamically-linked-library","linked-list","shared-object"],"created_at":"2025-02-19T21:17:06.847Z","updated_at":"2026-01-05T20:30:17.003Z","avatar_url":"https://github.com/exbotanical.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lib.cartilage\n\nclassical implementations of list and ring data structures for the C programming language\n\n# Install\n\nVia [clib](https://github.com/clibs/clib/):\n\n```bash\nclib install exbotanical/lib.cartilage\n```\n\nFrom Source:\n```bash\ngit clone https://github.com/exbotanical/lib.cartilage\ncd lib.cartilage \u0026\u0026 make\n```\n\n## Dynamic Linking\n\nLinking to `lib.cartilage`:\n\n```bash\n# 1) include and use lib.cartilage in your project\n# 2) generate object file for your project\ngcc -I ../path/to/libcartilage -c main.c -o main.o\n# 3) generate shared object file\nmake\n# 4) link your project to lib.cartilage\ngcc -o main main.o -L../path/to/libcartilage -llibcartilage\n# you may need to add the lib location to your PATH\n```\n\nLinking to `lib.cartilage` on Windows:\n\n```bash\n# 1) include and use lib.cartilage in your project\n# 2) generate object file for your project\ngcc -I ../path/to/libcartilage -c main.c -o main.o\n# 3) generate shared object file\nmake win\n# 3) link your project to lib.cartilage\ngcc -o main.exe main.o -L /path/to/lib.cartilage -llib_cartilage.dll\n# you may need to add the lib location to your PATH\n```\n\n## API and Documentation\n\n- Circular Singly Linked List\n\n- GlThread (aka 'Glue Linked List') - stores data at a memory offset\n\n### CircularSinglyLinkedList\n\n```c\n/**\n * @brief Node type; atomic - points to next Node*\n */\ntypedef struct ForwardNode {\n\tvoid* data;\n\tstruct ForwardNode* next;\n\tstruct CircularSinglyLinkedList* list; /* A pointer to the list to which the node belongs */\n} ForwardNode_t;\n```\n\n```c\n/**\n * @brief CircularSinglyLinkedList type\n */\ntypedef struct CircularSinglyLinkedList {\n\tForwardNode_t* head;\n\tuint32_t size;\n} CircularSinglyLinkedList;\n```\n\n```c\n/**\n * @brief Instantiate an empty circular singly linked list\n *\n * @return CircularSinglyLinkedList*\n */\nCircularSinglyLinkedList* csll_make_list(void);\n\nForwardNode_t* __csll_make_node(void* value);\n```\n\n```c\n/**\n * @brief Push a new node with value `value` to the back of the list\n *\n * @param ll\n * @param value\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_push_back(CircularSinglyLinkedList* ll, void* value);\n```\n\n```c\n/**\n * @brief Push a new node with value `value` to the front of the list\n *\n * @param ll\n * @param value\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_push_front(CircularSinglyLinkedList* ll, void* value);\n\n```c\n/**\n * @brief Iterate over the list and invoke `callback` with each node\n *\n * @param ll\n * @param callback\n */\nvoid csll_iterate(CircularSinglyLinkedList* ll, void (*callback)(void*));\n```\n\n```c\n/**\n * @brief Returns the next list node, if extant; else, NULL\n *\n * @param ll\n * @param node\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_next(CircularSinglyLinkedList* ll, ForwardNode_t* node);\n```\n\n```c\n/**\n * @brief Returns the previous list node, if extant; else, NULL\n *\n * @param ll\n * @param node\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_prev(CircularSinglyLinkedList* ll, ForwardNode_t* node);\n\n```c\n/**\n * @brief Remove a given node from the list\n *\n * @param ll\n * @param node\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_remove_node(CircularSinglyLinkedList* ll, ForwardNode_t* node);\n```\n\n```c\n/**\n * @brief Remove the last node from the list\n *\n * @param ll\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_pop(CircularSinglyLinkedList* ll);\n\n```c\n/**\n * @brief Insert a new node with value `value` immediately after `mark`\n *\n * If `mark` is not an element of the list, the list is not modified\n *\n * `mark` must not be NULL\n *\n * @param ll\n * @param value\n * @param mark\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_insert_after(CircularSinglyLinkedList* ll, void* value, ForwardNode_t* mark);\n```\n\n```c\n/**\n * @brief Insert a new node with value `value` immediately before `mark`\n *\n * If `mark` is not an element of the list, the list is not modified\n *\n * `mark` must not be NULL\n *\n * @param ll\n * @param value\n * @param mark\n * @return ForwardNode_t*\n */\nForwardNode_t* csll_insert_before(CircularSinglyLinkedList* ll, void* value, ForwardNode_t* mark);\n```\n\n```c\n/**\n * @brief Move a given node to its new position before `mark`\n *\n * If either the given node or mark are not an element of the list; node == mark; or node.next == mark, the list is not modified\n *\n * Both the node and mark must not be NULL\n *\n * @param ll\n * @param node\n * @param mark\n * @return int - 0 if success, else -1\n */\nint csll_move_before(CircularSinglyLinkedList* ll, ForwardNode_t* node, ForwardNode_t* mark);\n```\n\n```c\n/**\n * @brief Move a given node to its new position after `mark`\n *\n * If either the given node or mark are not an element of the list; node == mark; or mark.next == node, the list is not modified\n *\n * Both the node and mark must not be NULL\n *\n * @param ll\n * @param node\n * @param mark\n * @return int - 0 if success, else -1\n */\nint csll_move_after(CircularSinglyLinkedList* ll, ForwardNode_t* node, ForwardNode_t* mark);\n```\n\n```c\n/**\n * @brief Insert a copy of another list at the back of the caller list\n *\n * The lists may be the same, but must not be NULL\n *\n * @param ll\n * @param other\n * @return CircularSinglyLinkedList*\n */\nCircularSinglyLinkedList* csll_push_back_list(CircularSinglyLinkedList* ll, CircularSinglyLinkedList* other);\n```\n\n\n```c\n/**\n * @brief Insert a copy of another list at the front of the caller list\n *\n * The lists may be the same, but must not be NULL\n *\n * @param ll\n * @param other\n * @return CircularSinglyLinkedList*\n */\nCircularSinglyLinkedList* csll_push_front_list(CircularSinglyLinkedList* ll, CircularSinglyLinkedList* other);\n```\n\n### GlThread\n\nThis data structure is a linked list that points to a memory offset (at which the node data resides) instead of an address; it is thereby leaner than a traditional linked list.\n\nOther advantages include:\n\n- accommodates being referenced by multiple data structures\n- data objects' memory can be freed without the need to remove multiple pointer references\n\n```c\n/**\n * @brief glthread meta container\n */\ntypedef struct glthread {\n\tstruct glthread* prev;\n\tstruct glthread* next;\n} glthread_t;\n```\n\n```c\n/**\n * @brief Initialize a new glthread\n *\n * @param glthread\n */\nvoid glthread_init(glthread_t* glthread);\n```\n\n```c\n/**\n * @brief Insert a new glthread node after the given mark\n *\n * @param mark\n * @param next\n */\nvoid glthread_insert_after(glthread_t* mark, glthread_t* next);\n```\n\n```c\n/**\n * @brief Insert a new glthread node before the given mark\n *\n * @param mark\n * @param next\n */\nvoid glthread_insert_before(glthread_t* mark, glthread_t* next);\n```\n\n```c\n/**\n * @brief Remove a given glthread node\n *\n * @param mark\n */\nvoid glthread_remove(glthread_t* mark);\n```\n\n```c\n/**\n * @brief Push new glthread node to tail\n *\n * @param head\n * @param next\n */\nvoid glthread_push(glthread_t* head, glthread_t* next);\n```\n\n```c\n/**\n * @brief Delete all nodes in a given glthread\n *\n * @param head\n */\nvoid glthread_del_list(glthread_t* head);\n```\n\n```c\n/**\n * @brief Get current size of glthread\n *\n * @param head\n * @return unsigned int\n */\nunsigned int glthread_size(glthread_t* head);\n```\n\n```c\n/**\n * @brief Prioritized insertion\n *\n * @param head\n * @param glthread\n * @param comparator\n * @param offset\n */\nvoid glthread_priority_insert(\n\tglthread_t* head,\n\tglthread_t* glthread,\n\tint(*comparator)(void*, void*),\n\tint offset\n);\n```\n\n```c\n/**\n * @brief Dequeue the head node\n *\n * @param head\n * @return glthread_t*\n */\nglthread_t* glthread_dequeue_first(glthread_t* head);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexbotanical%2Flib.cartilage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexbotanical%2Flib.cartilage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexbotanical%2Flib.cartilage/lists"}