{"id":25319708,"url":"https://github.com/aghajari/c-collections","last_synced_at":"2026-04-29T01:34:01.295Z","repository":{"id":98252854,"uuid":"463611308","full_name":"Aghajari/C-Collections","owner":"Aghajari","description":"Java collections and lists for C","archived":false,"fork":false,"pushed_at":"2022-03-03T20:30:32.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T19:37:53.403Z","etag":null,"topics":["arraylist","c","collections","collections-c","hashmap","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aghajari.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":"2022-02-25T16:59:37.000Z","updated_at":"2023-11-17T02:27:57.000Z","dependencies_parsed_at":"2023-05-19T00:32:11.659Z","dependency_job_id":null,"html_url":"https://github.com/Aghajari/C-Collections","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Aghajari/C-Collections","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aghajari%2FC-Collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aghajari%2FC-Collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aghajari%2FC-Collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aghajari%2FC-Collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aghajari","download_url":"https://codeload.github.com/Aghajari/C-Collections/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aghajari%2FC-Collections/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32407164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["arraylist","c","collections","collections-c","hashmap","linked-list"],"created_at":"2025-02-13T20:54:44.236Z","updated_at":"2026-04-29T01:34:01.290Z","avatar_url":"https://github.com/Aghajari.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C-Collections\n Java collections and lists for C\n \n ## Table of Contents  \n- [ArrayList](#arraylist)  \n- [LinkedList](#linkedlist)\n- [Iterator](#iterator)\n- [Collection](#collection)\n  - [Swap](https://www.geeksforgeeks.org/collections-swap-method-in-java-with-examples/)\n  - [Sort \u0026 SortRangeOf](https://www.geeksforgeeks.org/collections-sort-java-examples/)\n  - [BinarySearch](https://www.geeksforgeeks.org/collections-binarysearch-java-examples/)\n  - [Max](https://www.geeksforgeeks.org/collections-max-method-in-java-with-examples/)\n  - [Min](https://www.geeksforgeeks.org/collections-min-method-in-java-with-examples/)\n  - [Fill](https://www.geeksforgeeks.org/collections-fill-method-in-java-with-examples/)\n  - [Reverse](https://www.geeksforgeeks.org/collections-reverse-method-in-java-with-examples/)\n  - [Rotate](https://www.geeksforgeeks.org/java-util-collections-rotate-method-java-examples/)\n- [HashMap](#hashmap)\n- HashSet (TO-DO)\n\n\n\n## ArrayList\n\nWhat is [ArrayList](https://www.geeksforgeeks.org/arraylist-in-java/)?\n\u003e ArrayList is a dynamic array and we do not have to specify the size while creating it, the size of the array automatically increases when we dynamically add and remove items.\n\n### Usage\n\n- include ArrayList header file\n```c\n#include \"array_list.h\"\n```\n\n- Create ArrayList struct :\n```c\nstruct ArrayList *list = array_list_create(); // or array_list_create2(capacity);\n```\n\n- Add items to the list :\n```c\narray_list_add(list, \"Hello\");\narray_list_add(list, \"World\");\n```\n\nResult : \n1. Hello\n2. World\n\n- Insert item :\n```c\narray_list_insert(list, \"First\", 0);\n```\n\nResult :\n1. First\n2. Hello\n3. World\n\n- InsertAll (Or AddAll) :\n```c\nchar *list2[] = {\"Hi\", \"Hii\", \"Hiii\"};\narray_list_insertAll(list, collection_create((void **) list2, 3), 1);\n```\n\nResult :\n1. First\n2. Hi\n3. Hii\n4. Hiii\n5. Hello\n6. World\n\n- Remove item (Or removeRange/ removeData) :\n```c\narray_list_remove(list, index);\n```\n\n\n## LinkedList\n\nWhat is [LinkedList](https://geeksforgeeks.org/data-structures/linked-list/)?\n\u003e A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers\n\n### Usage\n\n- include LinkedList header file\n```c\n#include \"linked_list.h\"\n```\n\n- Create the Head element :\n```c\nstruct LinkedListNode *list = linked_list_new(\"Hello\");\n```\n\n- Append\n```c\nlinked_list_append(linked_list_new(\"Test\"), list);\n```\n\nResult: Hello -\u003e Test\n\n- Push\n```c\nlinked_list_push(linked_list_new(\"1\", linked_list_new(\"2\")), list);\n```\n\nResult: 1 -\u003e 2 -\u003e Hello -\u003e Test\n\n- Pop\n```c\nlinked_list_pop(list);\n```\nResult: 2 -\u003e Hello -\u003e Test\n\n- Insert\n```c\nlinked_list_insertAt(linked_list_new(\"A\"), list, 1);\n```\nResult: 2 -\u003e A -\u003e Hello -\u003e Test\n\n- Insert with Finder function\n```c\n// -1 = insert before target\n// +1 = insert after target\n// +2 = insert after the next position of target, ...\nint finder(struct LinkedListNode* node, int index, const void *target) {\n    return strcmp(target, node-\u003edata) == 0 ? 2 : 0;\n}\n\nlinked_list_insert(linked_list_new(\"B\"), list, \"A\", finder);\n```\nResult: 2 -\u003e A -\u003e Hello -\u003e B -\u003e Test\n\n- Remove\n```c\nlinked_list_removeAt(list, 2);\n```\nResult: 2 -\u003e A -\u003e B -\u003e Test\n\n- Connect\n```c\nlinked_list_connect_before(\u0026list, linked_list_new(\"NEW\", linked_list_new(\"HI\")), linked_list_new(\"TEST\"));\n```\nResult: TEST -\u003e NEW -\u003e HI -\u003e 2 -\u003e A -\u003e B -\u003e Test\n\n- Check out other functions such as `connect_after`, `pollLast`, `peekLast`, `removeRange`, `copy`, `toArray`, `indexOf`, `lastIndexOf`, `swap`, `set`, `find`, ...\n\n## Iterator\n\nWhat is [Iterator](https://www.w3schools.com/java/java_iterator.asp)?\n\u003e Iterator can be used to loop through collections\n\n### Usage\n\n```c\n#include \"iterator.h\"\n\nstruct Iterator *iter = collection_iterator(collection);\n// struct Iterator *iter = array_list_iterator(arrayList);\n// struct Iterator *iter = linked_list_iterator(linkedList);\n\nwhile (iterator_has_next(iter)) {\n    printf(\"%s -\u003e \", (char *) iterator_next(iter));\n    // iterator_remove(iter) if needed to remove the element from the collection\n}\niterator_destroy(iter);\n```\n\n## Collection\n```c\n#include \"collection.h\"\n\nstruct Collection coll = collection_create(array, size);\n// struct Collection coll = array_list_collection(arrayList);\n// struct Collection coll = linked_list_collection(linkedList);\n\ncollection_sort(coll, comparator);\ncollection_reverse(coll);\ncollection_rotate(coll, 1);\nvoid * value = collection_binarySearch(coll, key, comparator);\nvoid * value = collection_max(coll, comparator);\nvoid * value = collection_min(coll, comparator);\ncollection_fill(coll, value);\n```\n\n## HashMap\n\nWhat is [HashMap](https://www.geeksforgeeks.org/java-util-hashmap-in-java-with-examples/)?\n\u003e HashMap stores the data in (Key, Value) pairs...\n\n### Usage\n\n- include HashMap header file\n```c\n#include \"hash_map.h\"\n```\n\n- Create HashMap struct :\n```c\nstruct HashMap *map = hash_map_create(); // or hash_map_create2(capacity);\n```\n\n- Put key-values :\n```c\nhash_map_string_put(map, \"Key1\", \"Item1\");\nhash_map_int_put(map, 2, \"Item2\");\nhash_map_put(map, key, value);\n```\n\n- Get value by key :\n```c\nprintf(\"%s\\n\", (char *) hash_map_string_get(map, \"Key1\"));\nprintf(\"%s\\n\", (char *) hash_map_int_get(map, 2));\n```\n\n- Remove value by key\n```c\nhash_map_int_remove(map, 2);\n```\n\n- Checkout other functions such as `containsKey`, `containsValue`, `putAll`, ...\n\n### Iterator over keys, values and entries\n\n`hash_map_entryIterator`, `hash_map_keyIterator` and `hash_map_valueIterator`\n\n```c\nstruct Iterator *iter = hash_map_entryIterator(map);\nwhile (iterator_has_next(iter)) {\n    struct HashMapEntry *entry = iterator_next(iter);\n    printf(\"Key: %s, Value: %s\\n\", (char *) entry-\u003ekey, (char *) entry-\u003evalue);\n}\niterator_destroy(iter);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faghajari%2Fc-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faghajari%2Fc-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faghajari%2Fc-collections/lists"}