{"id":17250717,"url":"https://github.com/larskuhtz/cuckoo","last_synced_at":"2025-04-14T05:17:59.240Z","repository":{"id":46675123,"uuid":"201986131","full_name":"larskuhtz/cuckoo","owner":"larskuhtz","description":"Haskell Implementation of Cuckoo Filters","archived":false,"fork":false,"pushed_at":"2021-10-21T06:11:19.000Z","size":90,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T19:06:21.562Z","etag":null,"topics":["cuckoo-filter","haskell","probabilistic-data-structures","set-membership"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/larskuhtz.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":"2019-08-12T18:23:47.000Z","updated_at":"2023-06-26T06:41:14.000Z","dependencies_parsed_at":"2022-09-15T23:12:08.594Z","dependency_job_id":null,"html_url":"https://github.com/larskuhtz/cuckoo","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/larskuhtz%2Fcuckoo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larskuhtz%2Fcuckoo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larskuhtz%2Fcuckoo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larskuhtz%2Fcuckoo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larskuhtz","download_url":"https://codeload.github.com/larskuhtz/cuckoo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248779205,"owners_count":21160309,"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":["cuckoo-filter","haskell","probabilistic-data-structures","set-membership"],"created_at":"2024-10-15T06:49:23.683Z","updated_at":"2025-04-14T05:17:59.221Z","avatar_url":"https://github.com/larskuhtz.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Hackage](https://img.shields.io/hackage/v/cuckoo.svg?logo=haskell)](https://hackage.haskell.org/package/cuckoo)\n\nHaskell implementation of Cuckoo filters as described in\n\n[B. Fan, D.G. Anderson, M. Kaminsky, M.D. Mitzenmacher. Cuckoo Filter:\nPractically Better Than Bloom. In Proc. CoNEXT,\n2014.](https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf)\n\nCuckoo filters are a data structure for probabilistic set membership. They\nsupport insertion, deletion, and membership queries for set elements.\n\nMembership queries may return false positive results. But queries don't return\nfalse negative results.\n\nUnlike Bloom filters, Cuckoo filters maintain an upper bound on the false\npositive rate that is independent of the load of the filter. However, insertion\nof new elements in the filter can fail. For typical configurations this\nprobability is very small for load factors smaller than 90 percent.\n\nThe implementation allows the user to specify the bucket size and the fingerprint\nsize in addition to the capacity of the filter. The user can also provide custom\nfunctions for computing the primary hash and fingerprint.\n\n## Installation\n\n```bash\ncabal install cuckoo\n```\n\nFor running the test-suites\n\n```bash\ncabal test cuckoo\n```\n\nFor running the benchmarks\n\n```bash\ncabal bench cuckoo\n```\n\n## Example\n\n```haskell\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE TypeApplications #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# OPTIONS_GHC -fno-warn-orphans #-}\n\nimport Control.Monad (filterM)\nimport Data.Cuckoo\nimport Data.List ((\\\\))\n\n-- Define CuckooFilterHash instance (this uses the default implementation)\ninstance CuckooFilterHash Int\n\nmain :: IO ()\nmain = do\n    -- Create Filter for a minimum of 500000 entries\n    f \u003c- newCuckooFilter @4 @8 @Int 0 500000\n\n    -- Insert 450000 items\n    failed \u003c- filterM (fmap not . insert f) [0..500000-1]\n\n    -- Query inserted items\n    missing \u003c- filterM (fmap not . member f) [0..500000-1]\n\n    -- Test for false positives\n    false \u003c- filterM (member f) [500000..1000000 - 1]\n\n    -- Report results\n    putStrLn $ \"failed inserts: \" \u003c\u003e show (length failed)\n    putStrLn $ \"false positives: \" \u003c\u003e show (length false)\n    putStrLn $ \"false positive rate (%): \" \u003c\u003e show @Double (fromIntegral (length false) * 100 / 500000)\n    putStrLn $ \"missing (must be 0): \" \u003c\u003e show (length $ missing \\\\ failed)\n\n    -- Filter properties\n    putStrLn $ \"capacity: \" \u003c\u003e show (capacityInItems f)\n    putStrLn $ \"size in allocated bytes: \" \u003c\u003e show (sizeInAllocatedBytes f)\n\n    -- computing the following is a bit slow\n    c \u003c- itemCount f\n    putStrLn $ \"item count: \" \u003c\u003e show c\n    lf \u003c- loadFactor f\n    putStrLn $ \"load factor (%): \" \u003c\u003e show lf\n    putStrLn $ \"bits per item: \" \u003c\u003e show @Double (fromIntegral (sizeInAllocatedBytes f) * 8 / fromIntegral c)\n```\n\nWhich produces the following results:\n\n```bash\n$ ghc -o main -threaded -O -with-rtsopts=-N Main.hs\n[1 of 1] Compiling Main             ( Main.hs, Main.o )\nLinking main ...\n$ ./main\nfailed inserts: 0\nfalse positives: 14796\nfalse postive rate (%): 2.9592\nmissing (must be 0): 0\ncapacity: 524288\nsize in allocated bytes: 524292\nitem count: 500000\nload factor (%): 95.367431640625\nbits per item: 8.388672\n```\n\nAnother example can be found in the file\n[bench/SpellChecker.hs](https://github.com/larskuhtz/cuckoo/blob/master/bench/SpellChecker.hs).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarskuhtz%2Fcuckoo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarskuhtz%2Fcuckoo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarskuhtz%2Fcuckoo/lists"}