[][src]Struct leveled_hash_map::LeveledHashMap

pub struct LeveledHashMap<K: Eq + Hash, V> { /* fields omitted */ }

A structure to separate values into different levels with keys. Every key-value entry which is not at the top level has a parent key at the superior level. Keys at the same level are unique, no matter what parent keys they have.

Implementations

impl<K: Eq + Hash, V> LeveledHashMap<K, V>[src]

pub fn new() -> LeveledHashMap<K, V>[src]

Create a new LeveledHashMap instance. The key needs to be implemented Eq and Hash traits.

extern crate leveled_hash_map;

use leveled_hash_map::LeveledHashMap;

let _map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

pub fn get(&self, key_chain: &[Arc<K>]) -> Option<&V>[src]

Get a value by a key chain. The key chain starts at Level 0.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

let _result = map.get(&[Arc::new("first_key")]);

pub fn get_mut(&mut self, key_chain: &[Arc<K>]) -> Option<&mut V>[src]

Get a value by a key chain. The key chain starts at Level 0.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

let _result = map.get_mut(&[Arc::new("first_key")]);

pub fn get_advanced(
    &self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Option<&V>
[src]

Get a value by a key chain and a level which the key chain starts with.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

let _result = map.get_advanced(&[Arc::new("second_key")], 1);

pub fn get_advanced_mut(
    &mut self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Option<&mut V>
[src]

Get a value by a key chain and a level which the key chain starts with.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

let _result = map.get_advanced_mut(&[Arc::new("second_key")], 1);

pub fn get_professional(
    &self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Result<(Option<Arc<K>>, &V), LeveledHashMapError<K>>
[src]

Get a value and its parent key by a key chain and a level which the key chain starts with. It returns a Err(LeveledHashMapError) instance to describe the reason of the getting failure.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], "甜點".to_string()).unwrap();

let result_1 = map.get_professional(&[Arc::new("food")], 0).unwrap();

let result_2 = map.get_professional(&[Arc::new("food"), Arc::new("dessert")], 0).unwrap();

assert_eq!(None, result_1.0);
assert_eq!("食物", result_1.1);

assert_eq!(Some(Arc::new("food")), result_2.0);
assert_eq!("甜點", result_2.1);

pub fn get_professional_mut(
    &mut self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Result<(Option<Arc<K>>, &mut V), LeveledHashMapError<K>>
[src]

Get a value and its parent key by a key chain and a level which the key chain starts with. It returns a Err(LeveledHashMapError) instance to describe the reason of the getting failure.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], "甜點".to_string()).unwrap();

let result = map.get_professional_mut(&[Arc::new("food")], 0).unwrap();

result.1.push_str("/食品");

assert_eq!(None, result.0);
assert_eq!("食物/食品", result.1);

pub fn remove(
    &mut self,
    key_chain: &[Arc<K>]
) -> Option<(V, Vec<HashMap<Arc<K>, (Option<Arc<K>>, V)>>)>
[src]

Remove a value by a key chain. The key chain starts at Level 0.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], "甜點".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("meat")], "肉類".to_string()).unwrap();

let result = map.remove(&[Arc::new("food"), Arc::new("dessert")]).unwrap();

assert_eq!("甜點", result.0);
assert_eq!(0, result.1.len());

let result = map.remove(&[Arc::new("food")]).unwrap();

assert_eq!("食物", result.0);
assert_eq!(1, result.1.len());
assert_eq!(
    &(Some(Arc::new("food")), "肉類".to_string()),
    result.1[0].get(&Arc::new("meat")).unwrap()
);

pub fn remove_advanced(
    &mut self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Option<(V, Vec<HashMap<Arc<K>, (Option<Arc<K>>, V)>>)>
[src]

Remove a value by a key chain and a level which the key chain starts with.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], "甜點".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("meat")], "肉類".to_string()).unwrap();

let result = map.remove_advanced(&[Arc::new("dessert")], 1).unwrap();

assert_eq!("甜點", result.0);
assert_eq!(0, result.1.len());

let result = map.remove_advanced(&[Arc::new("food")], 0).unwrap();

assert_eq!("食物", result.0);
assert_eq!(1, result.1.len());
assert_eq!(
    &(Some(Arc::new("food")), "肉類".to_string()),
    result.1[0].get(&Arc::new("meat")).unwrap()
);

pub fn remove_professional(
    &mut self,
    key_chain: &[Arc<K>],
    start_level: usize
) -> Result<(Option<Arc<K>>, V, Vec<HashMap<Arc<K>, (Option<Arc<K>>, V)>>), LeveledHashMapError<K>>
[src]

Remove a value by a key chain and a level which the key chain starts with. It returns a Err(LeveledHashMapError) instance to describe the reason of the getting failure.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], "甜點".to_string()).unwrap();

map.insert(&[Arc::new("food"), Arc::new("meat")], "肉類".to_string()).unwrap();

let result = map.remove_professional(&[Arc::new("dessert")], 1).unwrap();

assert_eq!(Some(Arc::new("food")), result.0);
assert_eq!("甜點", result.1);
assert_eq!(0, result.2.len());

let result = map.remove_professional(&[Arc::new("food")], 0).unwrap();

assert_eq!(None, result.0);
assert_eq!("食物", result.1);
assert_eq!(1, result.2.len());
assert_eq!(
    &(Some(Arc::new("food")), "肉類".to_string()),
    result.2[0].get(&Arc::new("meat")).unwrap()
);

pub fn insert(
    &mut self,
    key_chain: &[Arc<K>],
    value: V
) -> Result<Option<V>, LeveledHashMapError<K>>
[src]

Insert a value by a key chain. It returns a Err(LeveledHashMapError) instance to describe the reason of the getting failure.

extern crate leveled_hash_map;

use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

{
    let result = map.get(&[Arc::new("food")]).unwrap();

    assert_eq!("食物", result);
}

let result = map.insert(&[Arc::new("food")], "食品".to_string()).unwrap();

assert_eq!(Some("食物".to_string()), result);

let result = map.get(&[Arc::new("food")]).unwrap();

assert_eq!("食品", result);

pub fn insert_many(
    &mut self,
    key_chain: &[Arc<K>],
    value: HashMap<K, V>,
    start_level: usize
) -> Result<HashMap<Arc<K>, V>, LeveledHashMapError<K>>
[src]

Insert values by a key chain and a HashMap instance and a level which the key chain starts with. It returns a Err(LeveledHashMapError) instance to describe the reason of the getting failure.

extern crate leveled_hash_map;

use std::collections::HashMap;
use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

let mut insert_map = HashMap::new();

insert_map.insert("dessert", "甜點".to_string());
insert_map.insert("meat", "肉類".to_string());

map.insert_many(&[Arc::new("food")], insert_map, 0).unwrap();

let result = map.get(&[Arc::new("food"), Arc::new("dessert")]).unwrap();

assert_eq!("甜點", result);

let result = map.get(&[Arc::new("food"), Arc::new("meat")]).unwrap();

assert_eq!("肉類", result);

pub fn keys(&self, level: usize) -> Option<&HashMap<Arc<K>, HashSet<Arc<K>>>>[src]

Get the keys at a specific level.

extern crate leveled_hash_map;

use std::collections::HashMap;
use std::sync::Arc;

use leveled_hash_map::LeveledHashMap;

let mut map: LeveledHashMap<&'static str, String> = LeveledHashMap::new();

map.insert(&[Arc::new("food")], "食物".to_string()).unwrap();

let mut insert_map = HashMap::new();

insert_map.insert("dessert", "甜點".to_string());
insert_map.insert("meat", "肉類".to_string());

map.insert_many(&[Arc::new("food")], insert_map, 0).unwrap();

let result = map.keys(0).unwrap();

assert_eq!(1, result.len());

let result = map.keys(1).unwrap();

assert_eq!(2, result.len());

Trait Implementations

impl<K: Debug + Eq + Hash, V: Debug> Debug for LeveledHashMap<K, V>[src]

impl<K: Eq + Hash, V> Default for LeveledHashMap<K, V>[src]

Auto Trait Implementations

impl<K, V> RefUnwindSafe for LeveledHashMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V> Send for LeveledHashMap<K, V> where
    K: Send + Sync,
    V: Send

impl<K, V> Sync for LeveledHashMap<K, V> where
    K: Send + Sync,
    V: Sync

impl<K, V> Unpin for LeveledHashMap<K, V> where
    V: Unpin

impl<K, V> UnwindSafe for LeveledHashMap<K, V> where
    K: RefUnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.