{"id":16572840,"url":"https://github.com/lemire/csharpewah","last_synced_at":"2025-03-16T20:31:30.594Z","repository":{"id":2372971,"uuid":"3337588","full_name":"lemire/csharpewah","owner":"lemire","description":"Compressed bitmaps in C#","archived":false,"fork":false,"pushed_at":"2023-08-28T18:15:15.000Z","size":150,"stargazers_count":82,"open_issues_count":0,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-02-27T13:23:07.330Z","etag":null,"topics":["bitmap","bitset","compression","ewah"],"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/lemire.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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":"2012-02-02T18:47:13.000Z","updated_at":"2024-08-10T18:36:25.000Z","dependencies_parsed_at":"2024-10-27T11:36:44.176Z","dependency_job_id":null,"html_url":"https://github.com/lemire/csharpewah","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fcsharpewah","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fcsharpewah/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fcsharpewah/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemire%2Fcsharpewah/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemire","download_url":"https://codeload.github.com/lemire/csharpewah/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830912,"owners_count":20354848,"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":["bitmap","bitset","compression","ewah"],"created_at":"2024-10-11T21:28:42.042Z","updated_at":"2025-03-16T20:31:29.635Z","avatar_url":"https://github.com/lemire.png","language":"C#","readme":"CSharpEWAH\n==\n\n\nThis is a compressed variant of\nthe standard bitarray class. It uses a 64-bit RLE-like\ncompression scheme. It can be used to implement\nbitmap indexes.\n\nThe goal of word-aligned compression is not to\nachieve the best compression, but rather to\nimprove query processing time. Hence, we try\nto save CPU cycles, maybe at the expense of\nstorage. However, the EWAH scheme we implemented\nis always more efficient storage-wise than an\nuncompressed bitarray.\n\n\nReal-world usage\n----------------\n\nCSharpEWAH has been reviewed by Matt Warren as part of his work on the Stack Overflow tag system:\n\nhttp://mattwarren.org/2015/10/29/the-stack-overflow-tag-engine-part-3/\n\nThe Java counterpart of this library (JavaEWAH) is part of Apache Hive and its derivatives (e.g.,  Apache Spark) and Eclipse JGit. It has been used in production systems for many years. It is part of major Linux distributions.\n\nEWAH is used to accelerate the distributed version control system Git (http://githubengineering.com/counting-objects/). You can find the C port of EWAH written by the Git team at https://github.com/git/git/tree/master/ewah\n\nWhen should you use a bitmap?\n----------------------------------------\n\nSets are a fundamental abstraction in\nsoftware. They can be implemented in various\nways, as hash sets, as trees, and so forth.\nIn databases and search engines, sets are often an integral\npart of indexes. For example, we may need to maintain a set\nof all documents or rows  (represented by numerical identifier)\nthat satisfy some property. Besides adding or removing\nelements from the set, we need fast functions\nto compute the intersection, the union, the difference between sets, and so on.\n\n\nTo implement a set\nof integers, a particularly appealing strategy is the\nbitmap (also called bitset or bit vector). Using n bits,\nwe can represent any set made of the integers from the range\n[0,n): it suffices to set the ith bit is set to one if integer i is present in the set.\nCommodity processors use words of W=32 or W=64 bits. By combining many such words, we can\nsupport large values of n. Intersections, unions and differences can then be implemented\n as bitwise AND, OR and ANDNOT operations.\nMore complicated set functions can also be implemented as bitwise operations.\n\nWhen the bitset approach is applicable, it can be orders of\nmagnitude faster than other possible implementation of a set (e.g., as a hash set)\nwhile using several times less memory.\n\n\nWhen should you use compressed bitmaps?\n----------------------------------------\n\nAn uncompress BitSet can use a lot of memory. For example, if you take a BitSet\nand set the bit at position 1,000,000 to true and you have just over 100kB. That's over 100kB\nto store the position of one bit. This is wasteful  even if you do not care about memory:\nsuppose that you need to compute the intersection between this BitSet and another one\nthat has a bit at position 1,000,001 to true, then you need to go through all these zeroes,\nwhether you like it or not. That can become very wasteful.\n\nThis being said, there are definitively cases where attempting to use compressed bitmaps is wasteful.\nFor example, if you have a small universe size. E.g., your bitmaps represent sets of integers\nfrom [0,n) where n is small (e.g., n=64 or n=128). If you can use an uncompressed BitSet and\nit does not blow up your memory usage,  then compressed bitmaps are probably not useful\nto you. In fact, if you do not need compression, then a BitSet offers remarkable speed.\nOne of the downsides of a compressed bitmap like those provided by JavaEWAH is slower random access:\nchecking whether a bit is set to true in a compressed bitmap takes longer.\n\n\nHow does EWAH compares with the alternatives?\n-------------------------------------------\n\nEWAH is part of a larger family of compressed bitmaps that are run-length-encoded\nbitmaps. They identify long runs of 1s or 0s and they represent them with a marker word.\nIf you have a local mix of 1s and 0, you use an uncompressed word.\n\nThere are many formats in this family beside EWAH:\n\n* Oracle's BBC is an obsolete format at this point: though it may provide good compression,\nit is likely much slower than more recent alternatives due to excessive branching.\n* WAH is a patented variation on BBC that provides better performance.\n* Concise is a variation on the patented WAH. It some specific instances, it can compress\nmuch better than WAH (up to 2x better), but it is generally slower.\n* EWAH is both free of patent, and it is faster than all the above. On the downside, it\ndoes not compress quite as well. It is faster because it allows some form of \"skipping\"\nover uncompressed words. So though none of these formats are great at random access, EWAH\nis better than the alternatives.\n\nThere are other alternatives however. For example, the Roaring\nformat (https://github.com/lemire/RoaringBitmap) is not a run-length-encoded hybrid. It provides faster random access\nthan even EWAH.\n\n\nData format\n------------\n\nFor more details regarding the compression format, please\nsee Section 3 of the following paper:\n\nDaniel Lemire, Owen Kaser, Kamel Aouiche, Sorting improves word-aligned bitmap indexes. Data \u0026 Knowledge Engineering 69 (1), pages 3-28, 2010.  \n http://arxiv.org/abs/0901.3751\n\n (The PDF file is freely available on the arXiv site.)\n\nUnit testing\n==\n\n Building using Mono\n\n\nYou can build CSharpEWAH using the open source\nMono toolchain using the msbuild command.\nThen you can run the executable using\nthe mono command:\n```\n$ nuget restore EWAH.sln\n$ msbuild\n$ mono ./EWAH.RunTests/bin/Debug/EWAH.RunTests.exe\n```\n\nThis will run unit tests.\n\n\nUsage\n==\n\nSee example.cs.\n\nCredit\n==\n\n\n\n(c) Kemal Erdogan, Daniel Lemire, Ciaran Jessup, Michael Rice, Matt Warren\nThis code is licensed under the Apache\nLicense, Version 2.0 (ASL2.0)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fcsharpewah","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemire%2Fcsharpewah","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemire%2Fcsharpewah/lists"}