{"id":19669895,"url":"https://github.com/attractivechaos/dlist","last_synced_at":"2025-04-29T00:31:09.235Z","repository":{"id":139697206,"uuid":"228987092","full_name":"attractivechaos/dlist","owner":"attractivechaos","description":"Five implementations of double linked lists to demonstrate generic data structures in C","archived":false,"fork":false,"pushed_at":"2019-12-19T15:47:39.000Z","size":14,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T12:02:10.564Z","etag":null,"topics":["c","double-linked-list","generic-programming"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/attractivechaos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-12-19T06:09:36.000Z","updated_at":"2024-07-14T01:26:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"69baccb4-b972-41bf-a359-ffe740365ac0","html_url":"https://github.com/attractivechaos/dlist","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attractivechaos%2Fdlist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attractivechaos%2Fdlist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attractivechaos%2Fdlist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/attractivechaos%2Fdlist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/attractivechaos","download_url":"https://codeload.github.com/attractivechaos/dlist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251410250,"owners_count":21584986,"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":["c","double-linked-list","generic-programming"],"created_at":"2024-11-11T17:02:44.315Z","updated_at":"2025-04-29T00:31:09.230Z","avatar_url":"https://github.com/attractivechaos.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Generic Data Structures in C\n\nUnlike C++, the C programming language doesn't provide a general mechanism to\nimplement generic data structures or algorithms. However, it is still possible\nto write generic C code matching the performance of type-specific\nimplemntations. This repo demonstrates five ways to implement a generic\ndouble-linked list in C. Some of these techniques can be adapted to other data\nstructures with no compromise on performance.\n\n1. With `void*` pointers (`*-void.*`). This is the most common but often the\n   least efficient way to implement generic data structures. It requires extra\n   malloc per element, which wastes memory and hurts data locality. I don't recommend\n   it.\n\n2. With intrusive data structures (`*-intru2.*`). This approach doesn't call\n   malloc/etc inside the library code, which gives callers full control of\n   memory management. It is the preferred way to implement double-linked\n   list, but is not optimal for binary trees because it incurs overhead to\n   comparisons between objects. Generally, intrusive data structures are not\n   applicable to vectors or [closed hash tables][closed-hash].\n\n3. Combining intrusive data structures and macros (`*-intru1.*`). This is my\n   preferred way to implement binary trees (see [kavl.h][kavl]), but for\n   double-linked list, it is more complex.\n\n4. With macros (`*-macro1.*`). This approach can be optimal for all common data\n   structures. However, it involves unusual syntax and is inflexible in terms of\n   memory management at the caller end. My [khash.h][khash] library is\n   implemented this way. STL containers also follow a similar rationale.\n\n5. With before-header macros (`*-macro2.*`). This is an alternative way to\n   implement method 4 and is functionally equivalent. It gets rid of long\n   multi-line macros but complicates header inclusion.\n\nI recommend method 2 for double-linked lists, 3 for binary search trees such as\nred-black or AVL trees, and method 4 for plain vectors and closed hash tables.\n\n[closed-hash]: https://en.wikipedia.org/wiki/Open_addressing\n[khash]: https://github.com/attractivechaos/klib/blob/master/khash.h\n[kavl]: https://github.com/attractivechaos/klib/blob/master/kavl.h\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattractivechaos%2Fdlist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fattractivechaos%2Fdlist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fattractivechaos%2Fdlist/lists"}