{"id":28389182,"url":"https://github.com/henryzhao2020/c-storage-kit","last_synced_at":"2025-06-27T16:30:58.025Z","repository":{"id":289207061,"uuid":"970478227","full_name":"HenryZhao2020/C-Storage-Kit","owner":"HenryZhao2020","description":"Generic, memory-safe, well-documented, and highly modular dynamic array module for C, inspired by Java ArrayList and C++ std::vector ","archived":false,"fork":false,"pushed_at":"2025-05-18T03:27:01.000Z","size":114,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-31T10:08:14.231Z","etag":null,"topics":["adt","c","generic-types","memory-management"],"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/HenryZhao2020.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,"zenodo":null}},"created_at":"2025-04-22T04:41:54.000Z","updated_at":"2025-05-18T03:27:04.000Z","dependencies_parsed_at":"2025-04-28T21:39:18.456Z","dependency_job_id":"ff1a8f19-621f-43df-8b31-4c3b12e6f9f7","html_url":"https://github.com/HenryZhao2020/C-Storage-Kit","commit_stats":null,"previous_names":["henryzhao2020/adt","henryzhao2020/alist-c","henryzhao2020/c-storage-kit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HenryZhao2020/C-Storage-Kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryZhao2020%2FC-Storage-Kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryZhao2020%2FC-Storage-Kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryZhao2020%2FC-Storage-Kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryZhao2020%2FC-Storage-Kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HenryZhao2020","download_url":"https://codeload.github.com/HenryZhao2020/C-Storage-Kit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryZhao2020%2FC-Storage-Kit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262292971,"owners_count":23288633,"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":["adt","c","generic-types","memory-management"],"created_at":"2025-05-31T00:37:47.934Z","updated_at":"2025-06-27T16:30:58.017Z","avatar_url":"https://github.com/HenryZhao2020.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\nA calist stores items in a dynamically resizable array, with all items deeply copied into heap memory.\n\nEach calist is associated with a specific **ctype**, defining a common type for all stored items. \nType-specific behaviors (duplication, comparison, printing, and deallocation) are handled through the **ctype interface**.\n\n---\n\n## Memory Model\n\n- All inserted items are deeply copied into separately allocated heap memory.\n- Stack-allocated or heap-allocated objects are both safe to insert; the calist duplicates them internally.\n- Stored items are automatically freed when individually removed or when the calist is destroyed.\n- Clients are responsible for freeing the original heap-allocated objects after insertion to avoid memory leaks.\n\n---\n\n## Example Usage (examples/demo_calist_int.c)\n\n```c\n// Demonstration of calist usage.\n\n#include \u003cstdlib.h\u003e\n#include \u003cstdbool.h\u003e\n#include \u003cassert.h\u003e\n#include \"calist.h\"\n\n// Append stack-allocated, temporary values to al\nstatic void calist_append_stack(calist *al) {\n  int a = 5;\n  const int b = 10;\n  calist_append(al, \u0026a);    // a is deep-copied into al\n  calist_add(al, \u0026b);       // 'calist_add' is an alias for 'calist_append'\n  // a and b can now safely exit the stack frame\n\n  // 'WRAP_INT' adds a stack-allocated integer without a variable\n  calist_append(al, WRAP_INT(20));\n}\n\n// Append heap-allocated objects to al\nstatic void calist_append_heap(calist *al) {\n  int *ptr = malloc(sizeof(*ptr));\n  *ptr = 30;\n  calist_append(al, ptr);   // ptr is deep-copied into al\n  free(ptr);                // Client must free original pointer\n}\n\n// Check if num is even\nstatic bool is_even(const calist *al, const void *item, const void *args) {\n  const int *int_item = item;\n  return (*int_item % 2 == 0);\n}\n\n// Multiply the value of num by 3\nstatic void multiply(const calist *al, void *item, const void *args) {\n  int *int_ptr = item;\n  const int *factor = args;\n  *int_ptr *= (*factor);\n}\n\nint main(void) {\n  // Create an integer calist ['ctype_int' is included in ctype.h]\n  calist *al = calist_create(ctype_int());\n  \n  // Append integers to the back of al\n  calist_append_stack(al);\n  calist_append_heap(al);\n  \n  // Print al to the console\n  calist_print(al);         // Console: [5, 10, 20, 30]\n  // Get the size of al\n  assert(calist_size(al) == 4);\n\n  // Inserting integers before index positions\n  calist_insert(al, 2, WRAP_INT(5));      // al: [5, 10, 5, 20, 30]\n  calist_insert(al, 3, WRAP_INT(25));     // al: [5, 10, 5, 25, 20, 30]\n  calist_insert_front(al, WRAP_INT(35));  // al: [35, 5, 10, 5, 25, 20, 30]\n\n  // Duplicate al\n  calist *al_copy = calist_dup(al);\n  calist_print(al_copy);    // Console: [35, 5, 10, 5, 25, 20, 30]\n  // Comparing al and al_copy for equality\n  assert(calist_equals(al, al_copy));\n\n  // Remove the item at index position 2\n  calist_pop(al, 2);                    // al: [35, 5, 5, 25, 20, 30]\n  // Remove the first item with the value 25\n  calist_remove(al, WRAP_INT(25));      // al: [35, 5, 5, 20, 30]\n  // Remove all items with the value 5\n  calist_remove_all(al, WRAP_INT(5));   // al: [35, 20, 30]\n  // Remove all even integers from al\n  calist_remove_if(al, is_even, NULL);  // al: [35]\n  calist_print(al);         // Console: [35]\n  \n  // Remove all elements from al, but al is kept\n  calist_clear(al);\n  calist_print(al);         // Console: []\n\n  // Add previous items from the copy\n  calist_append_all(al, al_copy);  \n  calist_print(al);         // Console: [35, 5, 10, 5, 25, 20, 30]\n  calist_destroy(al_copy);  // Destroy al_copy and its content\n\n  // Check if integers are in al\n  assert(calist_contains(al, WRAP_INT(10)));\n  assert(!calist_contains(al, WRAP_INT(99)));\n  // First occurrence of 5 is at index position 1\n  assert(calist_index(al, WRAP_INT(5)) == 1);\n  // Last occurrence of 5 is at index position 3\n  assert(calist_index_last(al, WRAP_INT(5)) == 3);\n  // 'CALIST_INDEX_NOT_FOUND': 99 is not in al\n  assert(calist_index(al, WRAP_INT(99)) == CALIST_INDEX_NOT_FOUND);\n  // Count the number of occurrences\n  assert(calist_count(al, WRAP_INT(5)) == 2);\n  assert(calist_count(al, WRAP_INT(99)) == 0);\n  \n  // Access and mutate items at specific index positions\n  // Get the item at index position 2\n  const int *item = calist_get(al, 2);\n  assert(*item == 10);\n  // Modify the item at index position 0\n  int *item_mutable = calist_get_mutable(al, 0);\n  *item_mutable = 40;\n  // Set the item at index position 5\n  calist_set(al, 5, WRAP_INT(25));\n  calist_print(al);         // Console: [40, 5, 10, 5, 25, 25, 30]\n\n  // Quick sort algorithm\n  calist_qsort(al);         \n  calist_print(al);         // Console: [5, 5, 10, 25, 25, 30, 40]\n  // Binary search on the sorted list\n  assert(calist_bsearch(al, WRAP_INT(30)) != CALIST_INDEX_NOT_FOUND);\n  assert(calist_bsearch(al, WRAP_INT(99)) == CALIST_INDEX_NOT_FOUND);\n  // Reverse the list\n  calist_reverse(al);\n  calist_print(al);         // Console: [40, 30, 25, 25, 10, 5, 5]\n  // Multiply all items by 3\n  calist_foreach(al, multiply, WRAP_INT(3));\n  calist_print(al);         // Console: [120, 90, 75, 75, 30, 15, 15]\n\n  // Find unique elements and remove duplicates\n  al_copy = calist_unique(al);\n  calist_print(al_copy);    // Console: [120, 90, 75, 30, 15]\n  assert(calist_remove_dup(al) == 2);\n  calist_print(al);         // Console: [120, 90, 75, 30, 15]\n  assert(calist_equals(al, al_copy));\n\n  // IMPORTANT: free al and al_copy to prevent memory leak\n  calist_destroy(al);\n  calist_destroy(al_copy);\n  calist_destroy(NULL);     // Also safe\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryzhao2020%2Fc-storage-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryzhao2020%2Fc-storage-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryzhao2020%2Fc-storage-kit/lists"}