{"id":28510943,"url":"https://github.com/pavel-kirienko/wild_key_value","last_synced_at":"2025-08-18T05:05:15.733Z","repository":{"id":297970255,"uuid":"991542504","full_name":"pavel-kirienko/wild_key_value","owner":"pavel-kirienko","description":"Fast single-header key-value container in C with pattern matching and routing, suitable for embedded systems.","archived":false,"fork":false,"pushed_at":"2025-06-18T19:54:07.000Z","size":328,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-03T05:36:58.068Z","etag":null,"topics":["c","c99","container","embedded","embedded-c","key-value","pattern-matching","single-header","wildcard"],"latest_commit_sha":null,"homepage":"https://opencyphal.org/","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/pavel-kirienko.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":"2025-05-27T19:33:21.000Z","updated_at":"2025-06-18T19:54:13.000Z","dependencies_parsed_at":"2025-06-08T17:30:49.249Z","dependency_job_id":null,"html_url":"https://github.com/pavel-kirienko/wild_key_value","commit_stats":null,"previous_names":["pavel-kirienko/wild_key_value"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pavel-kirienko/wild_key_value","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavel-kirienko%2Fwild_key_value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavel-kirienko%2Fwild_key_value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavel-kirienko%2Fwild_key_value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavel-kirienko%2Fwild_key_value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pavel-kirienko","download_url":"https://codeload.github.com/pavel-kirienko/wild_key_value/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavel-kirienko%2Fwild_key_value/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266261285,"owners_count":23901288,"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","c99","container","embedded","embedded-c","key-value","pattern-matching","single-header","wildcard"],"created_at":"2025-06-08T23:06:34.935Z","updated_at":"2025-07-21T07:33:12.711Z","avatar_url":"https://github.com/pavel-kirienko.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wild Key-Value\n\n[![Main Workflow](https://github.com/pavel-kirienko/wild_key_value/actions/workflows/main.yml/badge.svg)](https://github.com/pavel-kirienko/wild_key_value/actions/workflows/main.yml)\n\nFast and simple single-header key-value container with pattern matching for embedded systems.\nKeys are strings, and values are void pointers.\nKeys are stored in the heap in fragments; common prefixes are deduplicated so the memory usage is extremely low.\n\nPatterns can be used to look up keys in the container, and also to look up patterns that match a given key;\nthe latter is called \"routing\".\n\n\n## Usage\n\nCopy `wkv.h` into your project and include it:\n\n```c++\n#define WKV_NO_ASSERT   1       ///\u003c Speeds things up by removing runtime invariant checking.\n#include \u003cwkv.h\u003e\n```\n\nDefine the realloc function. If you're using the standard heap, it would look as follows:\n\n```c++\nstatic void* my_realloc(wkv_t* const self, void* const ptr, const size_t new_size)\n{\n    if (new_size \u003e 0) { return realloc(ptr, new_size); }\n    free(ptr);  // Handle freeing explicitly because invoking the standard realloc() with zero size is UB.\n    return NULL;\n}\n```\n\nEmbedded systems might prefer [O1Heap](https://github.com/pavel-kirienko/o1heap), which is only slightly different.\n\nBasic operations -- init, get/set, delete, enumerate:\n\n```c++\nwkv_t kv;\nwkv_init(\u0026kv, my_realloc);\n\n// Insert/update keys in logarithmic time using wkv_set().\nwkv_node_t* node = wkv_set(\u0026kv, wkv_key(\"foo/bar/baz\"));\nif (node != NULL) {\n    if (node-\u003evalue == NULL) {\n        node-\u003evalue = \u0026my_value;    // This is a new item, freshly created. We must assign a non-NULL value.\n    } else {\n        node-\u003evalue = \u0026my_value;    // Such key already existed; we can reassign it here.\n    }\n} else {\n    // Not enough memory.\n}\n\n// Access existing keys in logarithmic time using wkv_get().\nnode = wkv_get(\u0026kv, wkv_key(\"foo/bar/baz\"));\nif (node != NULL) {\n    do_something(node-\u003evalue);      // The value of an existing key is never NULL.\n} else {\n    // The key does not exist.\n}\n\n// Delete a key using wkv_del(). Passing NULL node is safe here.\nwkv_del(\u0026kv, node);                                 // Using a specific node.\nwkv_del(\u0026kv, wkv_get(\u0026kv, wkv_key(\"foo/bar/baz\"))); // If the node needs to be found first (safe if not found).\n\n// Index-based access. The ordering is unspecified and invalidated on insertion.\nnode = wkv_at(\u0026kv, 123);\nif (node != NULL) {\n    do_something(node-\u003evalue);\n} else {\n    // The index points past the last element.\n}\n\n// Get the key of a previosuly found node.\n// WKV does not store full keys; instead, a key is reconstructed ad-hoc like so:\nchar key_buf[node-\u003ekey_len + 1];  // you can replace the VLA with an application-specific capacity.\nwkv_get_key(\u0026kv, node, key_buf);\nprintf(\"Key: %s\\n\", key_buf);\n```\n\nWKV supports pattern matching and routing:\n- Matching refers to finding keys in a container that match a given pattern. This is done via `wkv_match()`.\n- Routing refers to finding patterns in a container that match a given key. This is done via `wkv_route()`.\n\n## Development\n\nBuild and run tests using CMake.\n\nSet CMake cache variable `COVERAGE=ON` to make a coverage build; then build the `lcov` target to generate the report.\n\nTo release a new version, simply tag it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavel-kirienko%2Fwild_key_value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpavel-kirienko%2Fwild_key_value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavel-kirienko%2Fwild_key_value/lists"}