{"id":30732524,"url":"https://github.com/itsm3abena/c-ds","last_synced_at":"2025-09-03T17:09:50.686Z","repository":{"id":311948813,"uuid":"885772537","full_name":"itsm3abena/c-ds","owner":"itsm3abena","description":"A lightweight and efficient single-header library (ds.h) providing implementations of essential data structures in C, including Hashmaps, Hybrid Arrays, and Linked Lists.","archived":false,"fork":false,"pushed_at":"2025-08-27T16:21:21.000Z","size":69,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-28T01:35:22.608Z","etag":null,"topics":["c","cpp","datastructures","dsa-algorithm"],"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/itsm3abena.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,"zenodo":null}},"created_at":"2024-11-09T11:05:34.000Z","updated_at":"2025-08-27T16:21:24.000Z","dependencies_parsed_at":"2025-08-28T01:35:27.407Z","dependency_job_id":"11b5733b-81fd-45d5-b64f-c9c7c01b1f95","html_url":"https://github.com/itsm3abena/c-ds","commit_stats":null,"previous_names":["itsm3abena/c-ds"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/itsm3abena/c-ds","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsm3abena%2Fc-ds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsm3abena%2Fc-ds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsm3abena%2Fc-ds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsm3abena%2Fc-ds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsm3abena","download_url":"https://codeload.github.com/itsm3abena/c-ds/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsm3abena%2Fc-ds/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273477156,"owners_count":25112622,"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-09-03T02:00:09.631Z","response_time":76,"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","cpp","datastructures","dsa-algorithm"],"created_at":"2025-09-03T17:08:15.283Z","updated_at":"2025-09-03T17:09:50.677Z","avatar_url":"https://github.com/itsm3abena.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Structures in C - Single Header Library (ds.h)\n\nWelcome to the Data Structures in C project! This repository provides a single-header library, ds.h, that includes implementations for various data structures. Just include this header in your project, and you're ready to use powerful and efficient data structures with ease.\nFeatures\n\nThe library includes the following data structures:\n\n## Hashmaps\nA key-value store using chaining to handle hash collisions.\nSupported Operations:\n\n- insert – Add key-value pairs to the map\n- find – Retrieve the value for a given key\n- remove – Delete a key-value pair\n- print – Display the hashmap contents\n- destroy – Clean up memory used by the hashmap\n\nExample: \n```c\n#include \"ds.h\"\n\nint main() {\n    Hashmap *map = hashmap_create(10);\n    if (!map) {\n        fprintf(stderr, \"Failed to create hashmap\\n\");\n        return 1;\n    }\n\n    hashmap_insert(map, \"name\", \"Abena\");\n    hashmap_insert(map, \"age\", \"24\");\n    hashmap_insert(map, \"city\", \"Addis Ababa\");\n\n    printf(\"Name: %s\\n\", (char *)hashmap_get(map, \"name\"));\n    printf(\"Age: %s\\n\", (char *)hashmap_get(map, \"age\"));\n    printf(\"City: %s\\n\", (char *)hashmap_get(map, \"city\"));\n\n    hashmap_remove(map, \"age\");\n    printf(\"Age after removal: %s\\n\", (char *)hashmap_get(map, \"age\"));\n\n    hashmap_print(map);\n\n    hashmap_destroy(map);\n    return 0;\n}\n\n```\n\n## Hybrid Arrays\nAn automatically resizable array that grows dynamically as elements are added.\nSupported Operations:\n\n- push_back – Append an element to the array\n- get – Access an element at a given index\n- print – Display the array contents\n- destroy – Free memory allocated to the array\n\nExample: Hybrid Array Usage\n```c\n#include \"ds.h\"\n#include \u003cstdio.h\u003e\n\nint main() {\n    printf(\"=== Hybrid Array Example ===\\n\");\n\n    // Initialize a HybridArray\n    HybridArray array;\n    hybrid_array_init(\u0026array);\n\n    // Add elements to the array\n    hybrid_array_push_back(\u0026array, 10);\n    hybrid_array_push_back(\u0026array, 20);\n    hybrid_array_push_back(\u0026array, 30);\n\n    // Print the array's contents\n    printf(\"Array contents: \");\n    hybrid_array_print(\u0026array);\n\n    // Access elements by index\n    printf(\"Element at index 0: %d\\n\", hybrid_array_get(\u0026array, 0));\n    printf(\"Element at index 1: %d\\n\", hybrid_array_get(\u0026array, 1));\n    printf(\"Element at index 2: %d\\n\", hybrid_array_get(\u0026array, 2));\n\n    // Clean up memory\n    hybrid_array_destroy(\u0026array);\n\n    return 0;\n}\n\n```\n\n## Linked Lists\nA singly linked list implementation with convenient operations.\nSupported Operations:\n\n- insertAtHead – Insert an element at the beginning\n- insertAtTail – Insert an element at the end\n- deleteNode – Delete a node with a specific value\n- search – Find a node by its value\n- printList – Display the contents of the list\n- freeList – Release memory used by the list\n\nExample: Linked List Usage\n```c\n#include \"linked_list.h\"\n\nint main() {\n    Node* head = NULL;\n\n    insertAtHead(\u0026head, 10);\n    insertAtHead(\u0026head, 20);\n    insertAtTail(\u0026head, 30);\n\n    printList(head);\n\n    deleteNode(\u0026head, 20);\n    printList(head);\n\n    freeList(head);\n\n    return 0;\n}\n\n```\n\n## Binary Search Tree (BST)\n\nA simple integer BST with fast insert/search/delete.\nSupported Operations:\n\n- bst_insert – Insert a value\n\n- bst_search – Check if a value exists\n\n- bst_delete – Delete a value (returns the new root)\n\n- bst_inorder_print – Display the tree in sorted order\n\n- bst_free – Release memory used by the tree\n\nExample: BST Usage\n```c\n#include \"tree.h\"\nint main(void) {\n    BST *t = bst_create(cmp_str, free, free);\n    if (!t) return 1;\n\n    bst_insert(t, strdup(\"name\"), strdup(\"Abena\"));\n    bst_insert(t, strdup(\"city\"), strdup(\"Addis Ababa\"));\n    bst_insert(t, strdup(\"role\"), strdup(\"C dev\"));\n    bst_insert(t, strdup(\"city\"), strdup(\"Accra\"));\n\n    printf(\"role: %s\\n\", (char*)bst_get(t, \"role\"));\n    printf(\"size before delete: %zu\\n\", bst_size(t));\n    bst_remove(t, \"name\");\n    printf(\"size after delete: %zu\\n\\n\", bst_size(t));\n\n    puts(\"In-order traversal:\");\n    bst_inorder(t, visit_print, NULL);\n\n    bst_destroy(t);\n    return 0;\n}\n```\n\n## Trie\n\nA prefix tree for lowercase a–z words (other characters are ignored).\nSupported Operations:\n\n- trie_insert – Insert a word\n\n- trie_search – Check if a word exists\n\n- trie_starts_with – Check if any word has the given prefix\n\n- trie_delete – Remove a word and prune unused nodes\n\n- trie_free – Release memory used by the trie\n\nExample: Trie Usage\n```c\n#include \"trie.h\"\n\nint main(void) {\n    Trie *tr = trie_create(free);\n\n    trie_insert(tr, \"hello\", strdup(\"world\"));\n    trie_insert(tr, \"help\",  strdup(\"me\"));\n    trie_insert(tr, \"helium\",strdup(\"gas\"));\n\n    printf(\"contains 'help'? %s\\n\", trie_contains(tr, \"help\") ? \"yes\" : \"no\");\n    printf(\"starts_with 'he'? %s\\n\", trie_starts_with(tr, \"he\") ? \"yes\" : \"no\");\n    printf(\"value at 'hello': %s\\n\", (char*)trie_get(tr, \"hello\"));\n\n    trie_remove(tr, \"help\");\n    printf(\"contains 'help' after remove? %s\\n\", trie_contains(tr, \"help\") ? \"yes\" : \"no\");\n    printf(\"trie size: %zu\\n\", trie_size(tr));\n\n    trie_destroy(tr);\n    return 0;\n}\n```\n\n## How to Use\n1. Include the Header\nDownload the ds.h file and place it in your project directory. Include it in your source file as follows:\n```c\n#include \"ds.h\"\n```\n\n2. Compile Your Code\nUse a C compiler such as gcc to compile your program. For example:\n```shell\ngcc -o my_program main.c\n```\n\n3. Run the Program\nExecute the compiled output:\n```shell\n./my_program   # On Linux or macOS\nmy_program.exe # On Windows\n```\n\n## Benefits\nSingle Header Library: Simple integration – no separate source files needed.\nEfficient Implementations: Optimized for performance and memory usage.\nReusable: Designed for use in various applications without modifications.\n\n## License\nThis project is released under the MIT License. See the [LICENSE](https://github.com/itsm3abena/c-ds/blob/main/LICENSE) file for more details.\nContributing\n\nWe welcome contributions! To improve the library, fix bugs, or add new features:\n\n1. Fork the repository.\n2. Create a new branch.\n3. Commit your changes.\n4. Submit a pull request.\n\n## Contact\n\nFor questions, suggestions, or feedback, feel free to reach out:\n\nGitHub Issues: Open an [issue](https://github.com/itsm3abena/c-ds/issues) on this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsm3abena%2Fc-ds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsm3abena%2Fc-ds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsm3abena%2Fc-ds/lists"}