{"id":15969052,"url":"https://github.com/barrust/counting_bloom","last_synced_at":"2025-04-05T06:17:50.378Z","repository":{"id":46370213,"uuid":"43412759","full_name":"barrust/counting_bloom","owner":"barrust","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-10T19:45:22.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T00:29:49.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/barrust.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-30T04:57:25.000Z","updated_at":"2022-06-17T21:14:19.000Z","dependencies_parsed_at":"2022-09-22T23:20:27.139Z","dependency_job_id":null,"html_url":"https://github.com/barrust/counting_bloom","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fcounting_bloom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fcounting_bloom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fcounting_bloom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/barrust%2Fcounting_bloom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/barrust","download_url":"https://codeload.github.com/barrust/counting_bloom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294567,"owners_count":20915341,"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-10-07T19:21:27.119Z","updated_at":"2025-04-05T06:17:50.361Z","avatar_url":"https://github.com/barrust.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Counting Bloom\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![GitHub release](https://img.shields.io/github/v/release/barrust/counting_bloom.svg)](https://github.com/barrust/counting_bloom/releases)\n[![Build Status](https://github.com/barrust/counting_bloom/workflows/C/C++%20CI/badge.svg?branch=master)](https://github.com/barrust/counting_bloom/actions)\n[![codecov](https://codecov.io/gh/barrust/counting_bloom/branch/master/graph/badge.svg)](https://codecov.io/gh/barrust/counting_bloom)\n\nCounting Bloom Filter implementation written in **C**\n\nA counting bloom filter is similar to a standard bloom filter except that instead\nof using bits, one increments each index in the array. This allows for the removal\nof items from the filter. The data stored in a Bloom Filter is not retrievable. Once\ndata is 'inserted', data can be checked to see if it likely has been seen or if\nit definitely has not. Bloom Filters guarantee a 0% False Negative rate with a\npre-selected false positive rate.\n\nTo use the library, copy the `src/counting_bloom.h` and `src/counting_bloom.c`\nfiles into your project and include it where needed.\n\nFor a **python version**, please check out [pyprobables](https://github.com/barrust/pyprobables)\nwhich has a binary compatible output.\n\n## License:\nMIT 2015\n\n## Usage:\n``` c\n#include \u003cstdio.h\u003e\n#include \"counting_bloom.h\"\n\n\nCountingBloom cb;\ncounting_bloom_init(\u0026cb, 10, 0.01);\ncounting_bloom_add_string(\u0026cb, \"google\");\ncounting_bloom_add_string(\u0026cb, \"facebook\");\ncounting_bloom_add_string(\u0026cb, \"twitter\");\ncounting_bloom_add_string(\u0026cb, \"google\");\nif (counting_bloom_check_string(\u0026cb, \"google\") == COUNTING_BLOOM_SUCCESS) {\n\tprintf(\"'google' is in the counting bloom a maximum of %d times!\\n\", counting_bloom_get_max_insertions(\u0026cb, \"google\"));\n}\ncounting_bloom_remove_string(\u0026cb, \"google\");\ncounting_bloom_stats(\u0026cb);\ncounting_bloom_destroy(\u0026cb);\n```\n\n## Required Compile Flags:\n-lm\n\n\n## Backward Compatible Hash Function\nTo use the older counting bloom filters (v1.0.3 or lower) that utilized the default hashing\nalgorithm, then change use the following code as the hash function:\n\n``` c\n/* NOTE: The caller will free the results */\nstatic uint64_t* original_default_hash(unsigned int num_hashes, const char* str) {\n    uint64_t *results = (uint64_t*)calloc(num_hashes, sizeof(uint64_t));\n    char key[17] = {0}; // largest value is 7FFF,FFFF,FFFF,FFFF\n    results[0] = __fnv_1a(str);\n    for (unsigned int i = 1; i \u003c num_hashes; ++i) {\n        sprintf(key, \"%\" PRIx64 \"\", results[i-1]);\n        results[i] = old_fnv_1a(key);\n    }\n    return results;\n}\n\nstatic uint64_t old_fnv_1a(const char* key) {\n    // FNV-1a hash (http://www.isthe.com/chongo/tech/comp/fnv/)\n    int i, len = strlen(key);\n    uint64_t h = 14695981039346656073ULL; // FNV_OFFSET 64 bit\n    for (i = 0; i \u003c len; ++i){\n            h = h ^ (unsigned char) key[i];\n            h = h * 1099511628211ULL; // FNV_PRIME 64 bit\n    }\n    return h;\n}\n```\n\nIf using only older Counting Bloom Filters, then you can update the // FNV_OFFSET 64 bit\nto use `14695981039346656073ULL`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrust%2Fcounting_bloom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbarrust%2Fcounting_bloom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbarrust%2Fcounting_bloom/lists"}