{"id":23366908,"url":"https://github.com/matsuoka-601/fastuniq","last_synced_at":"2026-02-27T17:48:20.698Z","repository":{"id":267601879,"uuid":"866093628","full_name":"matsuoka-601/FastUniq","owner":"matsuoka-601","description":"A header-only library for fast string deduplication using a parallelized hash table","archived":false,"fork":false,"pushed_at":"2025-01-01T16:20:06.000Z","size":107,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T00:28:22.019Z","etag":null,"topics":["hash","hashtable","multi-threading","parallel","string"],"latest_commit_sha":null,"homepage":"","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/matsuoka-601.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}},"created_at":"2024-10-01T16:28:51.000Z","updated_at":"2025-02-03T15:51:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"1c77c70b-0e30-44db-8126-84cc38362ae5","html_url":"https://github.com/matsuoka-601/FastUniq","commit_stats":null,"previous_names":["matsuoka-601/fastuniq"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsuoka-601%2FFastUniq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsuoka-601%2FFastUniq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsuoka-601%2FFastUniq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsuoka-601%2FFastUniq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsuoka-601","download_url":"https://codeload.github.com/matsuoka-601/FastUniq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744328,"owners_count":20988783,"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":["hash","hashtable","multi-threading","parallel","string"],"created_at":"2024-12-21T14:19:20.098Z","updated_at":"2026-02-27T17:48:15.630Z","avatar_url":"https://github.com/matsuoka-601.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastUniq\n`FastUniq` is a header-only library for extremely fast string deduplication using a parallelized hash table. It's possible to uniquify newline-separated strings at a speed exceeding 1 GB/s when there are a lot of duplicates (see the \"Benchmark\" section for detail).\n\n`sort \u003cinput file\u003e | uniq` is often used as a one liner for string deduplication. \nBut if your goal is only deduplication and you don't need a sorted output, you can go much faster! \nIn this repository, we investigate how much faster a string uniquifier that implements the following optimization can be than `sort \u003cinput file\u003e | uniq` :\n\n- Parallelized hash table that scales well with the number of threads\n- Fast hash function using SSE/AVX2\n- Batching hash calculation and insertion into hash table\n- Prefetching for hash table accesses\n\n**Note that `FastUniq` cannot uniquify two strings which have same hash values.** ~~Since 64-bit hash is used, the chance of two strings having same hashes is very low, but not zero. See \"Probability of hash collision\" section for detail.~~ I see a very small number (around 1~2) of hash collisions when there are $\\geq 10^7$ unique strings. Therefore I recommend using this library when it's acceptable to miss some strings.\n## How to use `FastUniq` in your program\nIn order to use `FastUniq` in your program, include `FastUniq.hpp` and give `-mavx2, -maes, -fopenmp` flags to your compiler when compiling the program. For maximum performance, it's recommended to give either `-O3` or `-Ofast`.\n\nExample: \n```\ng++ your_program.cpp -mavx2 -maes -O3 -fopenmp\n```\n\nCurrently you can use the following APIs.\n- `std::vector\u003cstd::string\u003e Uniquify(const char* inputFile)` : Deduplicates newline-separated strings in `inputFile` and returns a vector of deduplicated strings.\n    - Currently this is slower than `UniquifyToStdout` because of the merging of the results from each thread.\n- `void UniquifyToStdout(const char* inputFile)` : Deduplicates newline-separated strings in `inputFile` and outputs deduplicated strings to stdout.\n## Benchmark\nThe following graph shows the results of performance measurements with the number of strings fixed at 30 million and with different numbers of threads. Benchmark is performed using `UniquifyToStdout` and sending the output to `/dev/null`. **But as always, take the results with a grain of salt. Always measure for your own workload.**\n\n![](img/scalability.png)\n\nThe benchmark was performed on a machine with a Ryzen 7 5825U CPU (8 cores, 16 threads) and 16GB of RAM. Maximum length of a string is 30. \n\nWe can see the following performance characteristics from the graph.\n\n- The performance with 16 threads is found to be approximately 3~4x compared to single-thread performance.\n- The performance degrades as the number of unique strings increases.\n    - This is likely due to the fact that the number of insertions into the hash table increases as the number of unique strings increases. Insertion into a hash table requires an exclusive access to a bucket and other threads should wait for that insertion, which negatively impacts performance.\n- FastUniq is constantly faster than `sort | uniq` even when single threaded.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsuoka-601%2Ffastuniq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsuoka-601%2Ffastuniq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsuoka-601%2Ffastuniq/lists"}