{"id":19017472,"url":"https://github.com/junkdog/bitvector","last_synced_at":"2025-04-23T02:49:03.600Z","repository":{"id":57737536,"uuid":"94715605","full_name":"junkdog/bitvector","owner":"junkdog","description":"Uncompressed, dynamically resizeable bitset for Kotlin (JS/JVM/Android)","archived":false,"fork":false,"pushed_at":"2017-07-12T14:15:56.000Z","size":112,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T02:48:58.189Z","etag":null,"topics":["bitset","kotlin","kotlin-js"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/junkdog.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":"2017-06-18T22:04:44.000Z","updated_at":"2025-03-27T09:48:12.000Z","dependencies_parsed_at":"2022-08-24T10:52:12.555Z","dependency_job_id":null,"html_url":"https://github.com/junkdog/bitvector","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/junkdog%2Fbitvector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Fbitvector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Fbitvector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Fbitvector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junkdog","download_url":"https://codeload.github.com/junkdog/bitvector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250360249,"owners_count":21417717,"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":["bitset","kotlin","kotlin-js"],"created_at":"2024-11-08T19:47:07.724Z","updated_at":"2025-04-23T02:49:03.576Z","avatar_url":"https://github.com/junkdog.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/junkdog/bitvector.svg)](https://travis-ci.org/junkdog/bitvector)\n\n## BitVector\n\n- Uncompressed, dynamically resizeable bitset, similar to `java.util.BitSet`\n- [Fast-ish][bench] enumeration of set bits (JS not yet profiled) \n- Compatible with JavaScript and JVM/Android backends\n  - 4 byte words, avoids [`Long` emulation][long-emu] in js\n\n [long-emu]: https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html#representing-kotlin-types-in-javascript \n [bench]: https://github.com/junkdog/bitvector#jvm-benchmarks--enumerating-set-bits\n \n## The gist\n\n#### Constructing\n```kotlin\nval bv: BitVector = bitsOf(1, 2, 56, 64, 128, 129, 130, 131, 420)\n```\n\n\n#### Individual bits\n```kotlin\nval bv = BitVector()\nbv[142] = true // or bv.set(142)\nassert(142 in bv)\n\nbv.clear(142)  // or bv[142] = false\nassert(142 !in bv)\n```\n\n\n#### `or`, `and`, `andNot`, `xor`\nAs with `java.util.BitSet`, these operations mutate the callee. Do a `copy()` if the original BitVector needs to stick around.\n\nThese functions are not infix functions, as such syntax would suggest a value copy.\n  \n```kotlin\nval a = bitsOf(0, 1, 2, 3, 120,                130)\nval b = bitsOf(0, 1, 2,    120, 121, 122, 123, 130)\n\nassert(a.and(b) == bitsOf(0, 1, 2, 120, 130))\n\n// caveat: bitvector was mutated above\nassert(a == bitsOf(0, 1, 2, 120, 130))\n```\n\n\n#### vs other BitVectors\n```kotlin\n// 1, 4 contained in other \nbitsOf(1, 4) in bitsOf(0, 1, 4, 5, 6) \n```\n\n#### Looping over bits: fast way\n```kotlin\nbitsOf(*bits).forEachBit { println(\"bit $it says hi\") }\n```\n\n\n#### Looping over bits: Iterable\u003cInt\u003e\n```kotlin\n// can be combined with filter/map etc\nbitsOf(*bits).forEach { println(\"bit $it says hi\") }\n```\n\n## Getting Started\n\n#### Maven: JVM/Android\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003enet.onedaybeard.bitvector\u003c/groupId\u003e\n\t\u003cartifactId\u003ebitvector-jvm\u003c/artifactId\u003e\n\t\u003cversion\u003e0.1.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Maven: JavaScript\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003enet.onedaybeard.bitvector\u003c/groupId\u003e\n\t\u003cartifactId\u003ebitvector-js\u003c/artifactId\u003e\n\t\u003cversion\u003e0.1.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### Gradle: JVM/Android\n\n```groovy\n  dependencies { compile \"net.onedaybeard.bitvector:bitvector-jvm:0.1.4\" }\n```\n\n#### Gradle: JavaScript\n\n```groovy\n  dependencies { compile \"net.onedaybeard.bitvector:bitvector-js:0.1.4\" }\n```\n\n\n## JVM Benchmarks / enumerating set bits\n\nMapping `true` bit positions into integers, inserting each into an `IntBag` (thin wrapper around `int[]`).\n \n[artemis-odb](https://github.com/junkdog/artemis-odb)'s `BitVector` was the basis for this implementation. The benchmark setup favors the artemis implementation, as it provides an optimized `toIntBag` method: it serves as a reference for best possible performance.\n\nSee [jmh-logs](https://github.com/junkdog/bitvector/tree/master/jmh-logs) for the full logs.\n\n![benchmark.png](http://junkdog.github.io/images/bitvector-jmh.png)\n\nDiscrepancy to artemis' `BitVector` is unwelcome. The implementation is for the most part the same, except that this implementation uses `int` for words, instead of `long`. 4 or 8 byte words did not have a significant impact on performance.\n\nThe for-loop performs poorly due to all the `Integer` boxing, extra indirection and allocation, compared to `forEachBit`.   \n\n`java.util.BitSet` suffers from not having a way of enumerating all bits at once, instead relying on repeatedly calling `nextSetBit`. \n\n\n## Tests\n\n#### Verifying platform-specific implementations\n```\nmvn clean install -P impltest\n```\n\n#### Running JS tests\nBuild project, `mvn clean install`, then point the browser to `file://$PROJECT_ROOT/js/target/test-classes/index.html`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunkdog%2Fbitvector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunkdog%2Fbitvector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunkdog%2Fbitvector/lists"}