{"id":18009641,"url":"https://github.com/mkostoevr/cdict","last_synced_at":"2025-03-26T14:31:06.989Z","repository":{"id":185591545,"uuid":"315141911","full_name":"mkostoevr/cdict","owner":"mkostoevr","description":"A simple dictionary implementation in C","archived":true,"fork":false,"pushed_at":"2024-12-30T18:30:51.000Z","size":111,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T15:53:21.945Z","etag":null,"topics":["associative-array","c","dependency-free","dictionary","header-only","independent","map","no-dependencies","unordered-map"],"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/mkostoevr.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}},"created_at":"2020-11-22T22:08:26.000Z","updated_at":"2025-01-02T18:22:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"e856efa2-4ecf-4a2f-98c6-7cc4113bb93f","html_url":"https://github.com/mkostoevr/cdict","commit_stats":null,"previous_names":["mkostoevr/cdict"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkostoevr%2Fcdict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkostoevr%2Fcdict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkostoevr%2Fcdict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkostoevr%2Fcdict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkostoevr","download_url":"https://codeload.github.com/mkostoevr/cdict/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245670605,"owners_count":20653398,"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":["associative-array","c","dependency-free","dictionary","header-only","independent","map","no-dependencies","unordered-map"],"created_at":"2024-10-30T02:09:57.621Z","updated_at":"2025-03-26T14:31:06.564Z","avatar_url":"https://github.com/mkostoevr.png","language":"C","readme":"# CDict - a simple dictionary implementation in C\n## Ready to use!\n\nIt may be used out of the box with key and value of type `CStr` (which is `char *` - zero-terminated string). Once it instantiated in some file using `CDICT_INST` definition:\n\n```C\n#define CDICT_INST\n#include \"cdict.h\"\n```\n\nIt may be then declared just using `#include`:\n\n```C\n#include \"cdict.h\"\n\nint main() {\n    CDict_CStr_CStr dict;\n    if (!cdict_CStr_CStr_init(\u0026dict)) {\n    \tprintf(\"CDict returned error #%d\", dict.error_code);\n    \treturn 0;\n    }\n    cdict_CStr_CStr_add_vv(\u0026dict, \"key_a\", \"value_a\", CDICT_REPLACE_EXIST);\n    printf(\"[key_a] = \\\"%s\\\"\\n\", cdict_CStr_CStr_get_v(\u0026dict, \"key_a\"));\n}\n```\n\n## Easy to configure!\n\nIf you want to create a dictionary for other key types you should provide your own keys hashing and comparsion functions, in such case the instantiation of the library will look like this:\n\n```C\n#define CDICT_INST\n#define CDICT_KEY_T MyType\n#define CDICT_HASH_FN(pkey) my_hash(pkey)\n#define CDICT_CMP_FN(pkey0, pkey1) my_cmp(pkey0, pkey1)\n#include \"cdict.h\"\n\nint my_cmp(MyType *pkey0, MyType *pkey1) {\n    // Return `whatever_negative` if `key0 \u003c key1`, `0` if `key0 == key1` and `whatever_positive` if `key0 \u003e key1` \n}\n\nunsigned long my_hash(MyType *key) {\n    // Return the hash of the key\n}\n```\n\nThen to use the new dictionary you only need to define key type before the header inclusion:\n\n```C\n#define CDICT_KEY_T MyType\n#include \"cdict.h\"\n\n// ...\n    CDict_MyType_CStr dict;\n    cdict_MyType_CStr_init(\u0026dict);\n// ...\n```\n\nIf you want to specify the type of values - just define the type:\n\n```C\n#define CDICT_VAL_T MyValueType\n```\n\nAnd so on.\n\n## Dependency-free!\n\nEvery single used dependency may be redefined:\n\n```C\n#define CDICT_ASSERT_FN(x) my_assert(x);\n```\n\n## Flexible!\n\nMay define user data to be used in overriden functions (for example - custom allocators):\n\n```C\n#define CDICT_USER_DATA_T UserData\n#define CDICT_HASHTAB_ITEM_ALLOC_FN(cdict, size) item_alloc(cdict, size)\n#define CDICT_HASHTAB_ITEM_FREE_FN(cdict, ptr) item_free(cdict, ptr)\n#define CDICT_HASHTAB_ALLOC_FN(cdict, size) hashtab_alloc(cdict, size)\n```\n\n## Checkout\n\n[The library](cdict.h).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkostoevr%2Fcdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkostoevr%2Fcdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkostoevr%2Fcdict/lists"}