index-set
bitset implementation with support for atomic operations
Why use index-set
?
In our use case, We needed to track the online/offline status of millions of users with minimal memory usage and lightning-fast lookup performance. Our ideal solution required the following:
-
Reuses identifiers when they are removed from the set. When an identifier is removed, it is recycled for future use.
-
Atomic and thread-safe operations.
-
Constant-time performance: Insertion, removal, and lookup operations must all be
O(1)
. -
Compact memory usage, Each identifier is represented by a bit in the memory. For example,
1
megabyte of memory can store8
millions (8,388,608
) unique identifiers. -
Identifiers are unique and as small as possible.
Example
Add this to your Cargo.toml
file:
[]
= "0.2"
Here is a simple example of how to use AtomicBitSet
:
use ;
// Create `AtomicBitSet` with memory size of 1 kilobyte
static BIT_SET: from_kilobytes }> = new;
Here is basic usage of BitSet
and BitSetMut
traits.
use ;
let mut bitset = ;
bitset.insert;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Here is an example of bitvec, which is Vec<T>
that implements BitSetMut
traits.
use ;
let mut bitvec: = Vec new;
insert;
assert_eq!;
assert_eq!;
assert_eq!;