Fixed size hash set

I think I'd like a in-place-allocated (runtime) set with an API like:

fn main() {
    let set = FixedHashSet::<_, 2>::with_capacity(); // Stack-allocated with_capacity=2.
    assert!(set.capacity() == 2);
    // pub fn insert(&mut self, value: T) -> Option<bool>;
    set.insert(2).unwrap(); // panic

Do you know if something like this exists? (In most cases I don't need this because when the set is small a linear scan in an array is faster).
An alternative design could heap-allocte when the constant capacity is exhausted, like SmallVec does.

After some googling, I found this SmallSet, which is based on SmallVec, but it's not implemented as a hash table, so it always works in linear time.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.