Crates.io | lilbits |
lib.rs | lilbits |
version | 0.1.0 |
source | src |
created_at | 2018-01-16 12:40:54.091664 |
updated_at | 2018-01-16 12:40:54.091664 |
description | Super fast u8 set (ie bitmap) relying on the assumption that elements are <= 63 |
homepage | |
repository | https://github.com/sirkibsirkib/trailing_cell |
max_upload_size | |
id | 47050 |
size | 14,277 |
In some instances, even a simple HashMap<T>
is too much for your application.
The LilBitsSet
is inspired by works such as smallset
, sparseset
and
bitmap
, but is incredibly simplistic with very few bells and whistles by
excelling at really only one thing: HashSet<u8>
semantics when your values are
never > 63
.
Personally, I plan to use this in my server-client library, where users can
optionally choose to broadcast to a LilBitSet
of clients. As no more than ~10
are expected to be online at once, a LilBitSet
is perfect for reasoning over
objects relating to these clients and their corresponding IDs.
This data structure has two severe limitations in comparison to other sets:
u8
can be stored (or any integer as
u8, of course)>= 64
can be stored. This is in constrast to smallset
, where the
limitation is on the number of elements, rather than the value of the elements.
Chances are, if these restrictions are dealbreakers for your purpose rather use a smallset
or something like it. Otherwise, LilBitSet
has some excellent properties:insert
Clone
and Copy
Sized
,Sync
, Serialize
, Deserialize
etc.union
to |
)Additionally, there exists a convenience macro lilbits!
for constructing a LilBitSet
,
as well as some potentially useful From
implementations to convert back and forth to other common sets
HashSet
, BTreeSet
.
The semantics of LilBitSet
are similar to that of HashSet<u8>
minus some missing functions which woudln't be useful, such as new_with_capacity
.
Most noteworthy is that the thread will Panic!
if there is ever an attempt to
insert
some u8 with a value greater than 63. If this behaviour is undesirable,
just protect it with an if
check. I avoided implementing it myself as it
simply bloats the API.
See tests.rs
for annotated examples.