{"id":13507339,"url":"https://github.com/rozap/spacesaving","last_synced_at":"2026-02-21T01:30:56.533Z","repository":{"id":57550649,"uuid":"52250973","full_name":"rozap/spacesaving","owner":"rozap","description":"stream count distinct element estimation","archived":false,"fork":false,"pushed_at":"2016-04-11T19:23:59.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-04T23:16:03.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/rozap.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}},"created_at":"2016-02-22T06:07:48.000Z","updated_at":"2016-06-12T03:37:08.000Z","dependencies_parsed_at":"2022-09-26T18:41:51.870Z","dependency_job_id":null,"html_url":"https://github.com/rozap/spacesaving","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/rozap%2Fspacesaving","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozap%2Fspacesaving/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozap%2Fspacesaving/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozap%2Fspacesaving/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rozap","download_url":"https://codeload.github.com/rozap/spacesaving/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222535178,"owners_count":16999233,"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-08-01T02:00:31.521Z","updated_at":"2025-10-21T18:33:08.354Z","avatar_url":"https://github.com/rozap.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"# Spacesaving\n\nSimple algorithm to estimate distinct elements in an unbounded stream using bounded space. The estimate is the upper bound on the element's actual count.\n\n[Docs on hex](http://hexdocs.pm/spacesaving/Spacesaving.html)\n\n## Usage\n\nAdd it to you `mix.exs` deps\n```elixir\n{:spacesaving, \"~\u003e 0.0.2\"}\n```\n\nInit with 3 spaces, so we track 3 elements\n```elixir\nimport Spacesaving\n\nstate = init(3)\n```\n\nPush some elements\n```elixir\nstate = state\n|\u003e push(:foo) |\u003e push(:foo) |\u003e push(:foo) |\u003e push(:foo)\n|\u003e push(:bar) |\u003e push(:bar) |\u003e push(:bar)\n|\u003e push(:baz) |\u003e push(:baz)\n|\u003e push(:buzz)\n```\n\nGet the top k elements\n```elixir\ntop(state, 2) # This will be [foo: 4, bar: 3]\ntop(state, 3) # This will be [foo: 4, bar: 3, buzz: 3], so the inaccuracy starts to come into play when an element is kicked out, and the estimate is the upper bound\n```\n\nMerge two states\n```elixir\nleft  = init(4) |\u003e push(:foo) |\u003e push(:bar)\nright = init(4) |\u003e push(:foo) |\u003e push(:baz)\n\nmerge(left, right)\n|\u003e top(3) # Would be [foo: 2, bar: 1, baz: 1]\n```\n\n\n## References\n[Original Paper](http://www.cse.ust.hk/~raywong/comp5331/References/EfficientComputationOfFrequentAndTop-kElementsInDataStreams.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozap%2Fspacesaving","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frozap%2Fspacesaving","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozap%2Fspacesaving/lists"}