stacked_set/
alloc_vec.rs

1use crate::collection::SetCollection;
2
3/// [`alloc::vec::Vec`]-based implementation
4///
5/// On my machine, worst time to check for existence is about 0.8ns/item
6pub type Vec<'l, Item> = crate::collection::CollectionSet<'l, alloc::vec::Vec<Item>>;
7
8impl<Item: PartialEq> SetCollection for alloc::vec::Vec<Item> {
9    type Item = Item;
10
11    type ExtendMemory = ();
12
13    #[inline]
14    fn new() -> Self {
15        alloc::vec::Vec::new()
16    }
17
18    #[inline]
19    fn extend(&mut self, new_item: Self::Item) -> Self::ExtendMemory {
20        self.push(new_item);
21    }
22
23    #[inline]
24    fn contains_ref(&self, item: &Self::Item) -> bool {
25        <[Item]>::contains(self, item)
26    }
27
28    #[inline]
29    fn remove(&mut self, _present_item: Self::ExtendMemory) {
30        let _ = self.pop();
31    }
32
33    type IntoIter<'i>
34        = core::slice::Iter<'i, Item>
35    where
36        Self: 'i;
37
38    #[inline]
39    fn iter(&self) -> Self::IntoIter<'_> {
40        <[Item]>::iter(self)
41    }
42}