Struct leveled_hash_map::LeveledHashMap [−][src]
Expand description
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
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();
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")]);
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")]);
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);
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);
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);
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);
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() );
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() );
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() );
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);
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);
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
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,