[−][src]Crate sortedvec
This crate exposes a single macro, sortedvec. It generates a lookup
table on Ord keys that has quicker lookups than regular Vecs, O(log(n)) vs O(n),
and is simpler and more memory efficient than hashmaps. It is ideal for (very) small
lookup tables where insertions and deletions are infrequent.
Example
use sortedvec::sortedvec; sortedvec! { struct SortedVec { fn key_deriv(x: &u32) -> u32 { *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
| sortedvec | A macro that defines a sorted vector data collection. |