Struct prefix_array::set::SetSubSlice
source · #[repr(transparent)]pub struct SetSubSlice<K: AsRef<str>>(_);
Expand description
A subslice of a PrefixArraySet
in which all items contain a common prefix (which may be the unit prefix ""
).
The SetSubSlice
does not store what that common prefix is for performance reasons (but it can be computed, see: SetSubSlice::common_prefix
), it is up to the user to keep track of.
Implementations§
source§impl<K: AsRef<str>> SetSubSlice<K>
impl<K: AsRef<str>> SetSubSlice<K>
sourcepub fn iter(&self) -> Iter<'_, K> ⓘ
pub fn iter(&self) -> Iter<'_, K> ⓘ
Returns an iterator over all of the elements of this SetSubSlice
sourcepub fn to_vec(&self) -> Vec<K>where
K: Clone,
pub fn to_vec(&self) -> Vec<K>where K: Clone,
Creates an owned copy of this SetSubSlice
as a Vec
.
If you wish to preserve PrefixArraySet
semantics consider using ToOwned
instead.
sourcepub fn find_all_with_prefix<'a>(&'a self, prefix: &str) -> &'a Self
pub fn find_all_with_prefix<'a>(&'a self, prefix: &str) -> &'a Self
Returns the SetSubSlice
where all K
have the same prefix prefix
.
Will return an empty array if there are no matches.
This operation is O(log n)
Examples
let set = PrefixArraySet::from_iter(["foo", "bar", "baz"]);
assert_eq!(set.find_all_with_prefix("b").to_vec(), vec!["bar", "baz"]);
sourcepub fn common_prefix(&self) -> &str
pub fn common_prefix(&self) -> &str
Compute the common prefix of this SetSubSlice
from the data.
Will return an empty string if this subslice is empty.
Note that this may be more specific than what was searched for, i/e:
let arr = PrefixArraySet::from_iter(["12346", "12345", "12341"]);
// Common prefix is *computed*, so even though we only
// searched for "12" we got something more specific
assert_eq!(arr.find_all_with_prefix("12").common_prefix(), "1234");
This operation is O(1)
, but it is not computationally free.
sourcepub fn contains(&self, key: &str) -> bool
pub fn contains(&self, key: &str) -> bool
Returns whether this SetSubSlice
contains the given key
This operation is O(log n)
.
sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
Returns whether this SetSubSlice
is empty
sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the length of this SetSubSlice
Trait Implementations§
source§impl<K: AsRef<str>> Borrow<SetSubSlice<K>> for PrefixArraySet<K>
impl<K: AsRef<str>> Borrow<SetSubSlice<K>> for PrefixArraySet<K>
source§fn borrow(&self) -> &SetSubSlice<K>
fn borrow(&self) -> &SetSubSlice<K>
source§impl<'a, K: AsRef<str>> IntoIterator for &'a SetSubSlice<K>
impl<'a, K: AsRef<str>> IntoIterator for &'a SetSubSlice<K>
source§impl<K: PartialEq + AsRef<str>> PartialEq<SetSubSlice<K>> for SetSubSlice<K>
impl<K: PartialEq + AsRef<str>> PartialEq<SetSubSlice<K>> for SetSubSlice<K>
source§fn eq(&self, other: &SetSubSlice<K>) -> bool
fn eq(&self, other: &SetSubSlice<K>) -> bool
self
and other
values to be equal, and is used
by ==
.