{"id":22499717,"url":"https://github.com/mahdavipanah/libcdll","last_synced_at":"2025-10-12T01:42:53.285Z","repository":{"id":146016620,"uuid":"50384801","full_name":"mahdavipanah/libcdll","owner":"mahdavipanah","description":"A cozy C library that implements circular doubly linked list","archived":false,"fork":false,"pushed_at":"2018-10-09T21:41:22.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-03T06:37:24.296Z","etag":null,"topics":["c","data-structures","library","linked-list"],"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/mahdavipanah.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-25T22:12:49.000Z","updated_at":"2024-12-03T10:15:57.000Z","dependencies_parsed_at":"2023-05-25T16:15:23.000Z","dependency_job_id":null,"html_url":"https://github.com/mahdavipanah/libcdll","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mahdavipanah/libcdll","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahdavipanah%2Flibcdll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahdavipanah%2Flibcdll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahdavipanah%2Flibcdll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahdavipanah%2Flibcdll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mahdavipanah","download_url":"https://codeload.github.com/mahdavipanah/libcdll/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mahdavipanah%2Flibcdll/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009796,"owners_count":26084648,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c","data-structures","library","linked-list"],"created_at":"2024-12-06T22:15:33.907Z","updated_at":"2025-10-12T01:42:53.280Z","avatar_url":"https://github.com/mahdavipanah.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libcdll\nThis was project is part of my data structures course in university.   \nI tried to write the code as clean as possible, so everyone can read and understand it quikly.   \n\n## Usage\n\nTo use libcdll you have to compile it with a compiler that supports c99 standard.\n\nAn example command for compiling libcdll with your program using gcc or clang:\n\n```Shell\ngcc -std=c99 main.c libcdll.c\n```\n```Shell\nclang -std=c99 main.c libcdll.c\n```\n\n## How to use it?\n\nFirst of all you need to define a CDLL object.\n\n```C\n// Don't forget to initialize it with NULL\n// so cdll functions can understand that\n// your list is empty at the moment.\n\nCDLL list = NULL;\n```\n\n### Functions\n\n#### cdll_init (CDLL *list, void *data) =\u003e void\nInitializes a list if it is empty and gets a data as it's first data.\nYou rarely have to use this function because when you use other functions to manipulate the list, they know when to invoke this function.\n\nThis function does nothing if list is not empty.\n\n```C\nCDLL list = NULL;\n\nint *a = malloc(sizeof(int));\n*a = 10;\ncdll_init (\u0026list, a);\n\n// =\u003e list: [10]\n\nint *b = malloc(sizeof(int));\n*b = 20;\n// This time nothing happens because our list is already initialized\ncdll_init (\u0026list, b);\n\n// =\u003e list: [10]\n```\n\n#### cdll_push (CDLL *list, void *data) =\u003e void\nAdds a node with given data to end of list.\n\nIf list is empty and not initialized yet (== NULL), this functions invokes cdll_init and initializes it.\n\n```C\nCDLL list = NULL;\n\nint *a = malloc(sizeof(int));\n*a = 10;\ncdll_push (\u0026list, a);\n\n// =\u003e list: [10]\n\nint *b = malloc(sizeof(int));\n*b = 20;\ncdll_push (\u0026list, b);\n\n// =\u003e list: [10, 20]\n```\n\n#### cdll_pop (CDLL *list) =\u003e void *\nRemoves and frees the last node in the list and returns it's data.\n\nThis function does not free the last node's data's memory, so it is on you to\ndo whatever you want with it such as freeing it's dynamic memory.\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nint *data = (int *) cdll_pop(\u0026list);\n\n// =\u003e *data: 5\n// =\u003e list: [1, 2, 3, 4]\n\nfree(data);\n\n```\n\n#### cdll_add (CDLL *list, void *data) =\u003e void\nAdds a node to first of list with the given data.\n\nIf list is empty and not initialized yet (== NULL), this functions invokes cdll_init and initializes it.\n\n```C\nCDLL list = NULL;\n\nint *a = malloc(sizeof(int));\n*a = 10;\ncdll_add (\u0026list, a);\n\n// =\u003e list: [10]\n\nint *b = malloc(sizeof(int));\n*b = 20;\ncdll_add (\u0026list, b);\n\n// =\u003e list: [20, 10]\n```\n\n#### cdll_remove_first (CDLL *list) =\u003e void *\nRemoves and frees the first node in the list and returns it's data.\n\nThis function does not free the last node's data's memory, so it is on you to\ndo whatever you want with it such as freeing it's dynamic memory.\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nint *data = (int *) cdll_remove_first(\u0026list);\n\n// =\u003e *data: 1\n// =\u003e list: [2, 3, 4, 5]\n\nfree(data);\n\n```\n\n#### cdll_length (const CDLL *list) =\u003e size_t\nReturns the length of the list. (Number of nodes (elements)).\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nsize_t len = cdll_length(\u0026list);\n\n// =\u003e len: 5\n\n```\n\n#### cdll_first (const CDLL *list) =\u003e CDLL\nReturns the first node in the list.\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nCDLL first_node = cdll_first(\u0026list);\n\nint *data = (int *) first_node-\u003edata;\nint *second_data = (int *) first_node-\u003enext-\u003edata;\n\n// =\u003e *data: 1\n// =\u003e *second_data: 2\n\n```\n\n#### cdll_last (const CDLL *list) =\u003e CDLL\nReturns the last node in the list.\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nCDLL last_node = cdll_last(\u0026list);\n\nint *data = (int *) last_node-\u003edata;\nint *before_last_data = (int *) last_node-\u003eprevious-\u003edata;\n\n// =\u003e *data: 5\n// =\u003e *before_last_data: 4\n\n```\n\n#### cdll_foreach (const CDLL *list, void (*function) (void*, void*), void *user_data) =\u003e void\nIterates over list's nodes starting from the first node to the last one and calls the given handler function with these two parameters :\n* The node's data (is probably different in each handler's invocation)\n* The given user_data (is same in every handler's invocation)\n\n```C\nvoid func (void *data, void *user_data)\n{\n        int * number     = (int *) data;\n        int * sum_number = (int *) user_data;\n\n        *number += *sum_number;\n}\n```\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nint * number = malloc(sizeof(int));\n*number = 2;\n\ncdll_foreach(\u0026list, func, number);\n\n// =\u003e list: [3, 4, 5, 6, 7]\n\n```\n\n#### cdll_reverse_foreach (const CDLL *list, void (*function) (void*, void*), void *user_data) =\u003e void\nIterates over nodes of the list, starting from the last node to the first one and calls the given handler function with these two parameters :\n* The node's data (is probably different in each handler's invocation)\n* The given user_data (is same in every handler's invocation)\n\n#### cdll_find (const CDLL *list, const void *data) =\u003e CDLL\nReturns the node in the list that it's data is the same as the the second argument. In other word, the node that it's data is pointing to the same place that given data argument points to.\n\nReturns NULL if no node found.\n\n```C\nCDLL list = NULL;\n\nint *data_3;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n\n        if (i == 3)\n                data_3 = num;\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nCDLL node = cdll_find(\u0026list, data_3);\n\nint *data = (int *) node-\u003edata;\nint *next_node = (int *) node-\u003enext-\u003edata;\n\n// =\u003e *data: 3\n// =\u003e *next_node: 4\n\n```\n\n#### cdll_deep_find (const CDLL *list, const void *data, int (*compare)(const void *, const void *)) =\u003e CDLL\nReturns the node in the list that it's data is the same as the the second argument. In other word, the node that it's data is pointing to the same place that given data argument points to.\nBut you have to provide a function that tells when two data valus are equal. compare function should return 0 if two values are equal.\n\nReturns NULL if no node found.\n\n```C\nint int_ptr_compare (const void *a, const void *b)\n{\n\tint m = *((int *) a);\n\tint n = *((int *) n);\n\tif (m == n)\n\t\treturn 0;\n}\n```\n\n```C\nCDLL list = NULL;\n\nfor (int i = 1; i \u003c= 5; ++i) {\n        int *num = malloc(sizeof(int));\n        *num = i;\n        cdll_push(\u0026list, num);\n}\n\n// =\u003e list: [1, 2, 3, 4, 5]\n\nint * number = malloc(sizeof(int));\n*number = 3;\n\nCDLL node = cdll_find(\u0026list, number, int_ptr_compare);\n\nint *data = (int *) node-\u003edata;\nint *next_node = (int *) node-\u003enext-\u003edata;\n\n// =\u003e *data: 3\n// =\u003e *next_node: 4\n\n```\n\n#### cdll_position (const CDLL *list, const CDLL node) =\u003e int\nReturns index of node in the list starting from 0.\n\nReturns -1 if node not found.\n\n\n#### cdll_data_position (const CDLL *list, const void *data) =\u003e int\nReturns index of first node with data equal to the data argument.\n\nReturns -1 if no node with given data found.\n\n\n#### cdll_deep_data_position (const CDLL *list, const void *data,  int (*compare)(const void *, const void *)) =\u003e int\nReturns index of first node with data equal to the data argument. But you have to provide a function that tells when two data valus are equal. compare function should return 0 if two values are equal.\n\nReturns -1 if no node with given data found.\n\n\n#### cdll_delete_node (CDLL *list, CDLL  node) =\u003e void*\nRemoves a node with given pointer in the list and returns it's data.\n\nThis function does not free the node's data, so it is on you to do whatever you want with it such as freeing it's dynamic memory.\n\n#### cdll_nth (const CDLL *list, size_t index) =\u003e CDLL\nReturns the nth node in the list.\n\n#### cdll_nth_data (const CDLL *list, size_t index) =\u003e void*\nReturns the nth data in the list.\n\n#### cdll_remove_data (CDLL *list, const void *data) =\u003e void*\nRemoves the first node that has the given data and return it's data.\n\n#### cdll_deep_remove_data (CDLL *list, const void *data) =\u003e void*\nDeep removes the first node that has the given data and return it's data.\n\n#### cdll_copy (const CDLL *list) =\u003e CDLL\nReturns a shallow copy of given list.\n\nShallow copy means this function does not duplicate any node's data, it just copy it's address (pointer).\n\n#### cdll_deep_copy (const CDLL *list, void*(*function)(const void*, void*), void *user_data) =\u003e CDLL\n Returns a deep copy of given list.\n \nThis functions gets a function pointer for copying every node's data.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdavipanah%2Flibcdll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmahdavipanah%2Flibcdll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmahdavipanah%2Flibcdll/lists"}