Lil'Bits
Purpose
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.
Usefulness
This data structure has two severe limitations in comparison to other sets:
- Only
u8can be stored (or any integerasu8, of course) - No value
>= 64can be stored. This is in constrast tosmallset, 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 asmallsetor something like it. Otherwise,LilBitSethas some excellent properties:
- Super-fast basic operations such as
insert - super fast
CloneandCopy - trivially benefits from obvious
Sized,Sync,Serialize,Deserializeetc. - set-logic leaning on super fast bitwise operations (eg
unionto|)
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.
Using It Yourself
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.
Examples
See tests.rs for annotated examples.