[][src]Macro sortedvec::sortedvec_slicekey

macro_rules! sortedvec_slicekey {
    (
    $(#[$attr:meta])*
    $v:vis struct $name:ident {
        fn derive_key($i:ident : & $val:ty) -> & [ $key:ty ] {
            $keyexpr:expr
        } $(,)?
    }
) => { ... };
}

A macro that defines a specialized sorted vector data structure on slice keys.

It differs from the standard sortedvec! macro in that the generated data structure is sorted on slices. This enables binary searches to be a bit smarter by skipping the comparison of the start of the slice that was shared with probes smaller and larger than the current probe.

Note that when your key can be compared as &[u8]s, like &str, a regular sortedvec! may still be faster as SIMD instructions can be used to compare long byte sequences and there is less bookkeeping involved.

The generated struct is specific to the given keys and value types. To create the struct, four bits are required:

  • a struct name,
  • a value type,
  • a slice key type of the form &[K]. Since we will sort on these internally, K must implement Ord,
  • a key extraction function of type FnMut(&T) -> &[K].

It matches the following input:

$(#[$attr:meta])*
$v:vis struct $name:ident {
    fn derive_key($i:ident : & $val:ty) -> & [ $key:ty ] {
        $keyexpr:expr
    } $(,)?
}

The exposed methods are identical to that of a data structure generated by sortedvec!. To get an overview of the exposed methods on the generated structure, see the documentation of the example module.