[−][src]Crate sortedvec
This crate exposes a single macro, def_sorted_vec
. It generates a lookup table
that has quicker lookups than regular Vec
s, O(log(n))
vs O(n)
,
and is simpler and more memory efficient than hashmaps. It is ideal for (very) small
lookup tables where additions and deletions are infrequent.
Example
use sortedvec::def_sorted_vec; def_sorted_vec! { struct SortedVec: u32 => u32, |x| x } let unsorted = vec![3, 5, 0, 10, 7, 1]; let sorted = SortedVec::from(unsorted.clone()); // linear search (slow!) let unsorted_contains_six: Option<_> = unsorted.iter().find(|&x| *x == 6); assert!(unsorted_contains_six.is_none()); // binary search (fast!) let sorted_contains_six: Option<_> = sorted.find(&6); assert!(sorted_contains_six.is_none());
Modules
example | Example of a collection defined using the |
Macros
def_sorted_vec | A macro that defines a sorted vector data collection. |