All Projects → junkdog → Bitvector

junkdog / Bitvector

Licence: mit
Uncompressed, dynamically resizeable bitset for Kotlin (JS/JVM/Android)

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to Bitvector

Fastbitset.js
Speed-optimized BitSet implementation for modern browsers and JavaScript engines
Stars: ✭ 118 (+883.33%)
Mutual labels:  bitset
enumset
A library for compact bit sets containing enums.
Stars: ✭ 60 (+400%)
Mutual labels:  bitset
Ewahboolarray
A compressed bitmap class in C++.
Stars: ✭ 381 (+3075%)
Mutual labels:  bitset
Bitset.js
An arbitrary size Bit-Vector implementation in JavaScript
Stars: ✭ 177 (+1375%)
Mutual labels:  bitset
ecs
Build your own Game-Engine based on the Entity Component System concept in Golang.
Stars: ✭ 68 (+466.67%)
Mutual labels:  bitset
bitmap-elixir
Bitmap implementation in Elixir using binaries and integers. Fast space efficient data structure for lookups
Stars: ✭ 30 (+150%)
Mutual labels:  bitset
Croaring Rs
Rust wrapper for CRoaring
Stars: ✭ 89 (+641.67%)
Mutual labels:  bitset
Bitset
Go package implementing bitsets
Stars: ✭ 649 (+5308.33%)
Mutual labels:  bitset
SwiftBitset
A fast Bitset class in Swift
Stars: ✭ 33 (+175%)
Mutual labels:  bitset
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+2575%)
Mutual labels:  bitset
Roaringbitmap
A better compressed bitset in Java
Stars: ✭ 2,460 (+20400%)
Mutual labels:  bitset
Bit-lib4j
Useful library to handle bytes or bits in Java. Read and write data in a byte array with a custom size for Java types. Read/Write Integer, Long, signed data, String, Hexa String and Date bit to bit
Stars: ✭ 53 (+341.67%)
Mutual labels:  bitset
prjxray-db
Project X-Ray Database: XC7 Series
Stars: ✭ 52 (+333.33%)
Mutual labels:  bitset
Pyroaringbitmap
An efficient and light-weight ordered set of 32 bits integers.
Stars: ✭ 128 (+966.67%)
Mutual labels:  bitset
Bitvec
A crate for managing memory bit by bit
Stars: ✭ 411 (+3325%)
Mutual labels:  bitset
Bit
Bitset data structure
Stars: ✭ 100 (+733.33%)
Mutual labels:  bitset
BitLens
🔎 Have your bits and eat them too! A C++17 bit lens container for vector types.
Stars: ✭ 20 (+66.67%)
Mutual labels:  bitset
Croaring
Roaring bitmaps in C (and C++)
Stars: ✭ 735 (+6025%)
Mutual labels:  bitset
Javaewah
A compressed alternative to the Java BitSet class
Stars: ✭ 474 (+3850%)
Mutual labels:  bitset
bitset2
std::bitset with constexpr implementations plus additional features.
Stars: ✭ 76 (+533.33%)
Mutual labels:  bitset

Build Status

BitVector

  • Uncompressed, dynamically resizeable bitset, similar to java.util.BitSet
  • Fast-ish enumeration of set bits (JS not yet profiled)
  • Compatible with JavaScript and JVM/Android backends

The gist

Constructing

val bv: BitVector = bitsOf(1, 2, 56, 64, 128, 129, 130, 131, 420)

Individual bits

val bv = BitVector()
bv[142] = true // or bv.set(142)
assert(142 in bv)

bv.clear(142)  // or bv[142] = false
assert(142 !in bv)

or, and, andNot, xor

As with java.util.BitSet, these operations mutate the callee. Do a copy() if the original BitVector needs to stick around.

These functions are not infix functions, as such syntax would suggest a value copy.

val a = bitsOf(0, 1, 2, 3, 120,                130)
val b = bitsOf(0, 1, 2,    120, 121, 122, 123, 130)

assert(a.and(b) == bitsOf(0, 1, 2, 120, 130))

// caveat: bitvector was mutated above
assert(a == bitsOf(0, 1, 2, 120, 130))

vs other BitVectors

// 1, 4 contained in other 
bitsOf(1, 4) in bitsOf(0, 1, 4, 5, 6) 

Looping over bits: fast way

bitsOf(*bits).forEachBit { println("bit $it says hi") }

Looping over bits: Iterable

// can be combined with filter/map etc
bitsOf(*bits).forEach { println("bit $it says hi") }

Getting Started

Maven: JVM/Android

<dependency>
	<groupId>net.onedaybeard.bitvector</groupId>
	<artifactId>bitvector-jvm</artifactId>
	<version>0.1.4</version>
</dependency>

Maven: JavaScript

<dependency>
	<groupId>net.onedaybeard.bitvector</groupId>
	<artifactId>bitvector-js</artifactId>
	<version>0.1.4</version>
</dependency>

Gradle: JVM/Android

  dependencies { compile "net.onedaybeard.bitvector:bitvector-jvm:0.1.4" }

Gradle: JavaScript

  dependencies { compile "net.onedaybeard.bitvector:bitvector-js:0.1.4" }

JVM Benchmarks / enumerating set bits

Mapping true bit positions into integers, inserting each into an IntBag (thin wrapper around int[]).

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.

See jmh-logs for the full logs.

benchmark.png

Discrepancy 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.

The for-loop performs poorly due to all the Integer boxing, extra indirection and allocation, compared to forEachBit.

java.util.BitSet suffers from not having a way of enumerating all bits at once, instead relying on repeatedly calling nextSetBit.

Tests

Verifying platform-specific implementations

mvn clean install -P impltest

Running JS tests

Build project, mvn clean install, then point the browser to file://$PROJECT_ROOT/js/target/test-classes/index.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].