Struct shawshank::StadiumSet
[−]
[src]
pub struct StadiumSet<O: StableAddress<Target = R>, R: ?Sized + StableAddress = <O as Deref>::Target, I = usize, M = HashMap<&'static <R as Deref>::Target, I>>(pub ArenaSet<O, I, M>);
Specialization of ArenaSet
where O::Target: StableAddress
.
Example: if O = Arc<Vec<u8>>
, then O::Target = Vec<u8>
. Therefore,
the map M
can be HashMap<&'static u8, usize>
, rather than the
HashMap<&'static Vec<u8>, usize>
that ArenaSet
would use.
intern
can similarly accept &'a [u8]
instead of &'a Vec<u8>
.
Methods
impl<O, R, I, M> StadiumSet<O, R, I, M> where
O: StableAddress<Target = R>,
R: 'static + StableAddress,
I: Copy + ToPrimitive + FromPrimitive + Bounded,
M: Map<Key = &'static <R as Deref>::Target, Value = I>,
[src]
O: StableAddress<Target = R>,
R: 'static + StableAddress,
I: Copy + ToPrimitive + FromPrimitive + Bounded,
M: Map<Key = &'static <R as Deref>::Target, Value = I>,
fn intern<Q>(&mut self, item: Q) -> Result<I, Error> where
Q: Borrow<<O::Target as Deref>::Target>,
O::Target: From<Q>,
O: From<<O as Deref>::Target>,
Q: Borrow<<O::Target as Deref>::Target>,
O::Target: From<Q>,
O: From<<O as Deref>::Target>,
Analogue of intern
.
use std::collections::HashMap; use std::sync::Arc; let mut p = shawshank::byte_stadium_set(); assert_eq!(p.intern(&[1,2,3][..]), Ok(0)); assert_eq!(p.intern(vec![1,2,3]), Ok(0));
fn disintern<'a, U: Borrow<I>>(&'a mut self, id: U) -> Result<O, Error>
Analogue of disintern
.
use std::collections::HashMap; use std::ops::Deref; use std::sync::Arc; let mut p = shawshank::byte_stadium_set(); assert_eq!(p.intern(&[1,2,3][..]), Ok(0)); assert_eq!(p.disintern(0).unwrap().deref().deref(), &[1,2,3]);
fn resolve<'a, U, Q: ?Sized>(&'a self, id: U) -> Result<&'a Q, Error> where
U: Borrow<I>,
O: Borrow<Q>,
U: Borrow<I>,
O: Borrow<Q>,
Analogue of resolve
.
use std::collections::HashMap; use std::sync::Arc; let mut p = shawshank::byte_stadium_set(); assert_eq!(p.intern(&[1,2,3][..]), Ok(0)); let s1: &Vec<u8> = p.resolve(0).unwrap(); let s1: &Arc<Vec<u8>> = p.resolve(0).unwrap();
fn shrink<T: Map<Key = I, Value = I>>(&mut self) -> T
Analogue of shrink
.