Struct lasso::Rodeo [−][src]
pub struct Rodeo<K = Spur, S = RandomState> { /* fields omitted */ }
Expand description
A string interner that caches strings quickly with a minimal memory footprint,
returning a unique key to re-access it with O(1)
times.
By default Rodeo uses the Spur
type for keys and RandomState
as its hasher
Implementations
impl<K> Rodeo<K, RandomState> where
K: Key,
[src]
impl<K> Rodeo<K, RandomState> where
K: Key,
[src]pub fn new() -> Self
[src]
pub fn new() -> Self
[src]Create a new Rodeo
Example
use lasso::{Rodeo, Spur}; let mut rodeo: Rodeo<Spur> = Rodeo::new(); let hello = rodeo.get_or_intern("Hello, "); let world = rodeo.get_or_intern("World!"); assert_eq!("Hello, ", rodeo.resolve(&hello)); assert_eq!("World!", rodeo.resolve(&world));
pub fn with_capacity(capacity: Capacity) -> Self
[src]
pub fn with_capacity(capacity: Capacity) -> Self
[src]pub fn with_memory_limits(memory_limits: MemoryLimits) -> Self
[src]
pub fn with_memory_limits(memory_limits: MemoryLimits) -> Self
[src]Create a new Rodeo with the specified memory limits. The interner will be able to hold max_memory_usage
bytes of interned strings until it will start returning None
from try_get_or_intern
or panicking from
get_or_intern
.
Note: If the capacity of the interner is greater than the memory limit, then that will be the effective maximum for allocated memory
See MemoryLimits
for more information
Example
use lasso::{Rodeo, MemoryLimits, Spur}; let rodeo: Rodeo<Spur> = Rodeo::with_memory_limits(MemoryLimits::for_memory_usage(4096));
pub fn with_capacity_and_memory_limits(
capacity: Capacity,
memory_limits: MemoryLimits
) -> Self
[src]
pub fn with_capacity_and_memory_limits(
capacity: Capacity,
memory_limits: MemoryLimits
) -> Self
[src]Create a new Rodeo with the specified capacity and memory limits. The interner will be able to hold max_memory_usage
bytes of interned strings until it will start returning None
from try_get_or_intern
or panicking from
get_or_intern
.
Note: If the capacity of the interner is greater than the memory limit, then that will be the effective maximum for allocated memory
See Capacity
MemoryLimits
for more information
Example
use lasso::{Rodeo, MemoryLimits, Spur}; let rodeo: Rodeo<Spur> = Rodeo::with_memory_limits(MemoryLimits::for_memory_usage(4096));
impl<K, S> Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]pub fn with_hasher(hash_builder: S) -> Self
[src]
pub fn with_hasher(hash_builder: S) -> Self
[src]Creates an empty Rodeo which will use the given hasher for its internal hashmap
Example
use lasso::{Spur, Rodeo}; use std::collections::hash_map::RandomState; let rodeo: Rodeo<Spur, RandomState> = Rodeo::with_hasher(RandomState::new());
pub fn with_capacity_and_hasher(capacity: Capacity, hash_builder: S) -> Self
[src]
pub fn with_capacity_and_hasher(capacity: Capacity, hash_builder: S) -> Self
[src]Creates a new Rodeo with the specified capacity that will use the given hasher for its internal hashmap
See Capacity
for more information
Example
use lasso::{Spur, Capacity, Rodeo}; use std::collections::hash_map::RandomState; let rodeo: Rodeo<Spur, RandomState> = Rodeo::with_capacity_and_hasher(Capacity::for_strings(10), RandomState::new());
pub fn with_capacity_memory_limits_and_hasher(
capacity: Capacity,
memory_limits: MemoryLimits,
hash_builder: S
) -> Self
[src]
pub fn with_capacity_memory_limits_and_hasher(
capacity: Capacity,
memory_limits: MemoryLimits,
hash_builder: S
) -> Self
[src]Creates a new Rodeo with the specified capacity and memory limits that will use the given hasher for its internal hashmap
See Capacity
and MemoryLimits
for more information
Example
use lasso::{Spur, Capacity, MemoryLimits, Rodeo}; use std::collections::hash_map::RandomState; let rodeo: Rodeo<Spur, RandomState> = Rodeo::with_capacity_memory_limits_and_hasher( Capacity::for_strings(10), MemoryLimits::for_memory_usage(4096), RandomState::new(), );
pub fn get_or_intern<T>(&mut self, val: T) -> K where
T: AsRef<str>,
[src]
pub fn get_or_intern<T>(&mut self, val: T) -> K where
T: AsRef<str>,
[src]Get the key for a string, interning it if it does not yet exist
Panics
Panics if the key’s try_from_usize
function fails. With the default keys, this means that
you’ve interned more strings than it can handle. (For Spur
this means that u32::MAX - 1
unique strings were interned)
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); // Interned the string let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key)); // No string was interned, as it was already contained let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
pub fn try_get_or_intern<T>(&mut self, val: T) -> LassoResult<K> where
T: AsRef<str>,
[src]
pub fn try_get_or_intern<T>(&mut self, val: T) -> LassoResult<K> where
T: AsRef<str>,
[src]Get the key for a string, interning it if it does not yet exist
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); // Interned the string let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap(); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key)); // No string was interned, as it was already contained let key = rodeo.try_get_or_intern("Strings of things with wings and dings").unwrap(); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
pub fn get_or_intern_static(&mut self, string: &'static str) -> K
[src]
pub fn get_or_intern_static(&mut self, string: &'static str) -> K
[src]Get the key for a static string, interning it if it does not yet exist
This will not reallocate or copy the given string
Panics
Panics if the key’s try_from_usize
function fails. With the default keys, this means that
you’ve interned more strings than it can handle. (For Spur
this means that u32::MAX - 1
unique strings were interned)
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); // Interned the string let key = rodeo.get_or_intern_static("Strings of things with wings and dings"); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key)); // No string was interned, as it was already contained let key = rodeo.get_or_intern_static("Strings of things with wings and dings"); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
pub fn try_get_or_intern_static(
&mut self,
string: &'static str
) -> LassoResult<K>
[src]
pub fn try_get_or_intern_static(
&mut self,
string: &'static str
) -> LassoResult<K>
[src]Get the key for a static string, interning it if it does not yet exist
This will not reallocate or copy the given string
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); // Interned the string let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap(); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key)); // No string was interned, as it was already contained let key = rodeo.try_get_or_intern_static("Strings of things with wings and dings").unwrap(); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
pub fn get<T>(&self, val: T) -> Option<K> where
T: AsRef<str>,
[src]
pub fn get<T>(&self, val: T) -> Option<K> where
T: AsRef<str>,
[src]Get the key value of a string, returning None
if it doesn’t exist
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert_eq!(Some(key), rodeo.get("Strings of things with wings and dings")); assert_eq!(None, rodeo.get("This string isn't interned"));
pub fn contains<T>(&self, val: T) -> bool where
T: AsRef<str>,
[src]
pub fn contains<T>(&self, val: T) -> bool where
T: AsRef<str>,
[src]Returns true
if the given string has been interned
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert!(rodeo.contains("Strings of things with wings and dings")); assert!(!rodeo.contains("This string isn't interned"));
impl<K, S> Rodeo<K, S> where
K: Key,
[src]
impl<K, S> Rodeo<K, S> where
K: Key,
[src]pub fn contains_key(&self, key: &K) -> bool
[src]
pub fn contains_key(&self, key: &K) -> bool
[src]Returns true
if the given key exists in the current interner
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert!(rodeo.contains_key(&key)); assert!(!rodeo.contains_key(&key_that_doesnt_exist));
pub fn resolve<'a>(&'a self, key: &K) -> &'a str
[src]
pub fn resolve<'a>(&'a self, key: &K) -> &'a str
[src]Resolves a string by its key. Only keys made by the current Rodeo may be used
Panics
Panics if the key is out of bounds
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert_eq!("Strings of things with wings and dings", rodeo.resolve(&key));
pub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
[src]
pub fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
[src]Resolves a string by its key, returning None
if it’s out of bounds. Only keys made by the
current Rodeo may be used
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); assert_eq!(Some("Strings of things with wings and dings"), rodeo.try_resolve(&key));
pub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
[src]
pub unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
[src]Resolves a string by its key, without bounds checks
Safety
The key must be valid for the current interner
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Strings of things with wings and dings"); unsafe { assert_eq!("Strings of things with wings and dings", rodeo.resolve_unchecked(&key)); }
impl<K, S> Rodeo<K, S>
[src]
impl<K, S> Rodeo<K, S>
[src]pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]Gets the number of interned strings
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); rodeo.get_or_intern("Documentation often has little hidden bits in it"); assert_eq!(rodeo.len(), 1);
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true
if there are no currently interned strings
Example
use lasso::Rodeo; let rodeo = Rodeo::default(); assert!(rodeo.is_empty());
pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
[src]Returns the number of strings that can be interned without a reallocation
Example
use lasso::{Spur, Capacity, Rodeo}; let rodeo: Rodeo<Spur> = Rodeo::with_capacity(Capacity::for_strings(10)); assert_eq!(rodeo.capacity(), 10);
pub fn iter(&self) -> Iter<'_, K>ⓘ
[src]
pub fn iter(&self) -> Iter<'_, K>ⓘ
[src]Returns an iterator over the interned strings and their key values
pub fn set_memory_limits(&mut self, memory_limits: MemoryLimits)
[src]
pub fn set_memory_limits(&mut self, memory_limits: MemoryLimits)
[src]Set the Rodeo
’s maximum memory usage while in-flight
Note that setting the maximum memory usage to below the currently allocated memory will do nothing
pub fn current_memory_usage(&self) -> usize
[src]
pub fn current_memory_usage(&self) -> usize
[src]Get the Rodeo
’s currently allocated memory
pub fn max_memory_usage(&self) -> usize
[src]
pub fn max_memory_usage(&self) -> usize
[src]Get the Rodeo
’s current maximum of allocated memory
impl<K, S> Rodeo<K, S>
[src]
impl<K, S> Rodeo<K, S>
[src]#[must_use]pub fn into_reader(self) -> RodeoReader<K, S>
[src]
#[must_use]pub fn into_reader(self) -> RodeoReader<K, S>
[src]Consumes the current Rodeo, returning a RodeoReader
to allow contention-free access of the interner
from multiple threads
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Appear weak when you are strong, and strong when you are weak."); let read_only_rodeo = rodeo.into_reader(); assert_eq!( "Appear weak when you are strong, and strong when you are weak.", read_only_rodeo.resolve(&key), );
#[must_use]pub fn into_resolver(self) -> RodeoResolver<K>
[src]
#[must_use]pub fn into_resolver(self) -> RodeoResolver<K>
[src]Consumes the current Rodeo, returning a RodeoResolver
to allow contention-free access of the interner
from multiple threads with the lowest possible memory consumption
Example
use lasso::Rodeo; let mut rodeo = Rodeo::default(); let key = rodeo.get_or_intern("Appear weak when you are strong, and strong when you are weak."); let resolver_rodeo = rodeo.into_resolver(); assert_eq!( "Appear weak when you are strong, and strong when you are weak.", resolver_rodeo.resolve(&key), );
Trait Implementations
impl Default for Rodeo<Spur, RandomState>
[src]
impl Default for Rodeo<Spur, RandomState>
[src]Creates a Rodeo using Spur
as its key and RandomState
as its hasher
impl<'de, K: Key, S: BuildHasher + Default> Deserialize<'de> for Rodeo<K, S>
[src]
impl<'de, K: Key, S: BuildHasher + Default> Deserialize<'de> for Rodeo<K, S>
[src]fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<K, S, T> Extend<T> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
T: AsRef<str>,
[src]
impl<K, S, T> Extend<T> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
T: AsRef<str>,
[src]fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]Extends a collection with the contents of an iterator. Read more
fn extend_one(&mut self, item: A)
[src]
fn extend_one(&mut self, item: A)
[src]extend_one
)Extends a collection with exactly one element.
fn extend_reserve(&mut self, additional: usize)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl<Str, K, S> FromIterator<Str> for Rodeo<K, S> where
Str: AsRef<str>,
K: Key,
S: BuildHasher + Default,
[src]
impl<Str, K, S> FromIterator<Str> for Rodeo<K, S> where
Str: AsRef<str>,
K: Key,
S: BuildHasher + Default,
[src]fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Str>,
[src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Str>,
[src]Creates a value from an iterator. Read more
impl<K, S> Index<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> Index<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]impl<K, S> Interner<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> Interner<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]fn get_or_intern(&mut self, val: &str) -> K
[src]
fn get_or_intern(&mut self, val: &str) -> K
[src]Get the key for a string, interning it if it does not yet exist Read more
fn try_get_or_intern(&mut self, val: &str) -> LassoResult<K>
[src]
fn try_get_or_intern(&mut self, val: &str) -> LassoResult<K>
[src]Get the key for a string, interning it if it does not yet exist
fn get_or_intern_static(&mut self, val: &'static str) -> K
[src]
fn get_or_intern_static(&mut self, val: &'static str) -> K
[src]Get the key for a static string, interning it if it does not yet exist Read more
fn try_get_or_intern_static(&mut self, val: &'static str) -> LassoResult<K>
[src]
fn try_get_or_intern_static(&mut self, val: &'static str) -> LassoResult<K>
[src]Get the key for a static string, interning it if it does not yet exist Read more
impl<'a, K: Key, S> IntoIterator for &'a Rodeo<K, S>
[src]
impl<'a, K: Key, S> IntoIterator for &'a Rodeo<K, S>
[src]impl<K, S> IntoReader<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> IntoReader<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]type Reader = RodeoReader<K, S>
type Reader = RodeoReader<K, S>
The type of Reader
the interner will be converted into
#[must_use]fn into_reader(self) -> Self::Reader where
Self: 'static,
[src]
#[must_use]fn into_reader(self) -> Self::Reader where
Self: 'static,
[src]#[must_use]fn into_reader_boxed(self: Box<Self>) -> Self::Reader where
Self: 'static,
[src]
Self: 'static,
impl<K, S> IntoResolver<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> IntoResolver<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]type Resolver = RodeoResolver<K>
type Resolver = RodeoResolver<K>
The type of Resolver
the reader will be converted into
#[must_use]fn into_resolver(self) -> Self::Resolver where
Self: 'static,
[src]
#[must_use]fn into_resolver(self) -> Self::Resolver where
Self: 'static,
[src]#[must_use]fn into_resolver_boxed(self: Box<Self>) -> Self::Resolver where
Self: 'static,
[src]
Self: 'static,
impl<K, S> PartialEq<Rodeo<K, S>> for RodeoReader<K, S>
[src]
impl<K, S> PartialEq<Rodeo<K, S>> for RodeoReader<K, S>
[src]impl<K, S> PartialEq<Rodeo<K, S>> for RodeoResolver<K>
[src]
impl<K, S> PartialEq<Rodeo<K, S>> for RodeoResolver<K>
[src]impl<K, S> PartialEq<Rodeo<K, S>> for ThreadedRodeo<K, S> where
K: Eq + Hash + Key,
S: Clone + BuildHasher,
[src]
impl<K, S> PartialEq<Rodeo<K, S>> for ThreadedRodeo<K, S> where
K: Eq + Hash + Key,
S: Clone + BuildHasher,
[src]impl<K, S> PartialEq<RodeoReader<K, S>> for Rodeo<K, S>
[src]
impl<K, S> PartialEq<RodeoReader<K, S>> for Rodeo<K, S>
[src]impl<K, S> PartialEq<RodeoResolver<K>> for Rodeo<K, S>
[src]
impl<K, S> PartialEq<RodeoResolver<K>> for Rodeo<K, S>
[src]impl<K, S> Reader<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
impl<K, S> Reader<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]impl<K, S> Resolver<K> for Rodeo<K, S> where
K: Key,
[src]
impl<K, S> Resolver<K> for Rodeo<K, S> where
K: Key,
[src]fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
[src]
fn try_resolve<'a>(&'a self, key: &K) -> Option<&'a str>
[src]Attempts to resolve the given key into a string, returning None
if it cannot be found Read more
unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
[src]
unsafe fn resolve_unchecked<'a>(&'a self, key: &K) -> &'a str
[src]Resolves a string by its key without preforming bounds checks Read more
fn contains_key(&self, key: &K) -> bool
[src]
fn contains_key(&self, key: &K) -> bool
[src]Returns true
if the current interner contains the given key
impl<K, S> Eq for Rodeo<K, S>
[src]
impl<K, S> IntoReaderAndResolver<K> for Rodeo<K, S> where
K: Key,
S: BuildHasher,
[src]
K: Key,
S: BuildHasher,
impl<K: Send, S: Send> Send for Rodeo<K, S>
[src]
Auto Trait Implementations
impl<K, S> RefUnwindSafe for Rodeo<K, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
impl<K, S> Sync for Rodeo<K, S> where
K: Sync,
S: Sync,
K: Sync,
S: Sync,
impl<K, S> Unpin for Rodeo<K, S> where
K: Unpin,
S: Unpin,
K: Unpin,
S: Unpin,
impl<K, S> UnwindSafe for Rodeo<K, S> where
K: UnwindSafe,
S: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,