{"id":20528745,"url":"https://github.com/zmap/cachehash","last_synced_at":"2025-04-14T04:53:06.981Z","repository":{"id":23899253,"uuid":"27279027","full_name":"zmap/cachehash","owner":"zmap","description":"An efficient C hash-table like data structure with static size that evicts LRU object on insertion","archived":false,"fork":false,"pushed_at":"2023-09-10T21:49:05.000Z","size":20,"stargazers_count":10,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T18:52:40.757Z","etag":null,"topics":[],"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/zmap.png","metadata":{"files":{"readme":"README.rst","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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-28T19:03:39.000Z","updated_at":"2024-11-28T03:22:12.000Z","dependencies_parsed_at":"2024-11-15T23:27:08.455Z","dependency_job_id":"c2503cd7-31ab-40f9-a63c-5689ab5d17b1","html_url":"https://github.com/zmap/cachehash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmap%2Fcachehash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmap%2Fcachehash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmap%2Fcachehash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmap%2Fcachehash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zmap","download_url":"https://codeload.github.com/zmap/cachehash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248824693,"owners_count":21167343,"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":[],"created_at":"2024-11-15T23:26:59.777Z","updated_at":"2025-04-14T04:53:06.963Z","avatar_url":"https://github.com/zmap.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"CacheHash\n=========\n\nAn efficient C hash table data structure that supports a limited number of\nhash table items and evicts the least recently used object (with a callback)\non insertion. This is accomplished with a Judy Array where hash table items\npoint to an statically allocated doubly-linked-list where head is MRU object\nand tail is LRU. On object access, object is moved to the head of the list.\n\nThis is primarily intended for caches. \n\nAPI\n===\n\nInitialization::\n\n\ttypedef void (*cachehash_evict_cb)(void* key, size_t keylen, void *data) \n\t*cachehash cachehash_init(size_t maxitems, cachehash_evict_cb *cb)\n\nHas Item? (returns item without rearranging)::\n\n\tvoid* cachehash_has(cachehash *ch, void *key, size_t key_len)\n\nGet Item! (returns item and moves to be MRU object)::\n\n\tvoid* cachehash_get(cachehash *ch, void *key, size_t key_len)\n\nPut Item! (adds an item to the cachehash)::\n\n\tvoid* cachehash_put(cachehash *ch, void *key, size_t key_len, void *value)\n\t\nEvict Item! (evicts LRU item if the cachehash is full)::\n\n\tvoid* cachehash_evict_if_full(cachehash *ch)\n\t\nFree Cache Hash (frees all memory used by data structure)::\n\n\tvoid cachehash_free(cachehash *ch, cachehash_process_cb *cb);\n\t\nIterate (call callback for each item in hash table from MRU -\u003e LRU order)::\n\n\tvoid cachehash_iter(cachehash *ch, cachehash_process_cb *cb);\n\t\nDebug Print (print out entire data structure assuming that keys and values are null-terminated strings)::\n\n\tvoid cachehash_debug_dump(cachehash *ch);\n\nExample\n=======\n\nA quick example::\n\n\tinclude \u003ccachehash.h\u003e\n\tch = cachehash_init(5, NULL);\n\t\n\tchar *key = \"test-key\";\n\tchar *value = \"test-value\";\n\tcachehash_put(ch, key, strlen(key), value);\n\t\n\tprintf(\"value of has is %s\\n\", cachehash_has(ch, key, strlen(key)));\n\tassert(cachehash_has(ch, key, strlen(key)) == value);\n\t\n\tcachehash_free(ch, NULL);\n\n\nDependencies\n============\n\nCacheHash uses Judy Arrays (http://judy.sourceforge.net/) for its backend hash table.\nThis can generally be installed using your operating system's package manager. For example,\nyou need to run `sudo apt-get install libjudy-dev` on Debian-based systems.\n\n\nLicense\n=======\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed\nunder the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\nCONDITIONS OF ANY KIND, either express or implied. See LICENSE for the specific\nlanguage governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmap%2Fcachehash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzmap%2Fcachehash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmap%2Fcachehash/lists"}