BisetMap

Struct BisetMap 

Source
pub struct BisetMap<L: Eq + Hash + Clone, R: Eq + Hash + Clone> { /* private fields */ }
Expand description

A two-way map between keys (left) and values (right).

See the module-level documentation for more details and examples.

Implementations§

Source§

impl<L: Eq + Hash + Clone, R: Eq + Hash + Clone> BisetMap<L, R>

Source

pub fn new() -> BisetMap<L, R>

Creates an empty BisetMap.

§Examples
use bisetmap::BisetMap;

let bmap: BisetMap<char, u32> = BisetMap::new();
Source

pub fn with_capacity(capacity: usize) -> BisetMap<L, R>

Creates an empty BisetMap with the given capacity.

§Examples
use bisetmap::BisetMap;

let bmap: BisetMap<char, u32> = BisetMap::with_capacity(5);
Source

pub fn clear(&self)

Removes all key-value pairs from the BisetMap, but keeps the allocated memory for reuse.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('b', 2);
bmap.insert('c', 3);
bmap.clear();
assert!(bmap.len() == 0);
Source

pub fn rev(&self) -> BisetMap<R, L>

Returns a new BisetMap where keys and values are swapped.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('b', 2);
bmap.insert('c', 3);
let rmap = bmap.rev();
assert_eq!(rmap.get(&1), ['a']);
Source

pub fn collect(&self) -> Vec<(L, Vec<R>)>

Returns a vector of (key,values) pairs, where values itself is a vector. (Order of all pairs is unknown)

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('a', 2);
bmap.insert('b', 3);
assert_eq!(bmap.collect(), vec![('a',vec![1,2]), ('b',vec![3])]);
Source

pub fn flat_collect(&self) -> Vec<(L, R)>

Returns a vector of (key,value) pairs. (Order of pairs is unknown)

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('a', 2);
bmap.insert('b', 3);
assert_eq!(bmap.flat_collect(), [('a',1), ('a',2), ('b',3)]);
Source

pub fn insert(&self, k: L, v: R)

Inserts the given key-value pair into the BisetMap.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('a', 1);
bmap.insert('a', 2);
bmap.insert('b', 3);
assert_eq!(bmap.flat_collect(), [('a',1), ('a',2), ('b',3)]);
Source

pub fn remove(&self, k: &L, v: &R)

Removes the specified key-value pair from the BisetMap.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('a', 1);
bmap.insert('a', 2);
bmap.insert('c', 3);
assert_eq!(bmap.len(), 2);
assert_eq!(bmap.rev_len(), 3);
bmap.remove(&'a', &2);
assert_eq!(bmap.len(), 2);
assert_eq!(bmap.rev_len(), 2);
Source

pub fn contains(&self, k: &L, v: &R) -> bool

Returns true if the map contains the given key-value pair and false otherwise.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
assert!(bmap.contains(&'a', &1));
assert!(!bmap.contains(&'b', &1));
assert!(!bmap.contains(&'a', &2));
Source

pub fn key_exists(&self, k: &L) -> bool

Returns true if the map contains the given key (left) value and false otherwise.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
assert!(bmap.key_exists(&'a'));
assert!(!bmap.key_exists(&'b'));
Source

pub fn value_exists(&self, v: &R) -> bool

Returns true if the map contains the given value (right) and false otherwise.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
assert!(bmap.value_exists(&1));
assert!(!bmap.value_exists(&2));
Source

pub fn get(&self, k: &L) -> Vec<R>

Returns a vector of values (right) corresponding to the given key (left).

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
assert_eq!(bmap.get(&'a'), [1]);
assert_eq!(bmap.get(&'z'), []);
Source

pub fn rev_get(&self, v: &R) -> Vec<L>

Returns a vector of keys (left) corresponding to the given value (right).

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
assert_eq!(bmap.rev_get(&1), ['a']);
assert_eq!(bmap.rev_get(&2), []);
Source

pub fn delete(&self, k: &L) -> Vec<R>

Removes the specified key and all values associated with it.

Returns a vector of previous values associated with given key.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('a', 2);
bmap.insert('c', 3);
assert_eq!(bmap.delete(&'a'), [1, 2]);
assert_eq!(bmap.len(), 1);
Source

pub fn rev_delete(&self, v: &R) -> Vec<L>

Removes the specified value and all keys associated with it.

Returns a vector of previous keys associated with given value.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('b', 1);
bmap.insert('c', 2);
assert_eq!(bmap.rev_delete(&1), ['a', 'b']);
assert_eq!(bmap.len(), 1);
Source

pub fn len(&self) -> usize

Returns the number of unique keys (left).

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('b', 2);
bmap.insert('c', 3);
bmap.insert('c', 4);
assert_eq!(bmap.len(), 3);
Source

pub fn rev_len(&self) -> usize

Returns the number of unique values (right).

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
bmap.insert('a', 1);
bmap.insert('b', 2);
bmap.insert('c', 3);
bmap.insert('d', 3);
assert_eq!(bmap.rev_len(), 3);
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no key-value pairs, and false otherwise.

§Examples
use bisetmap::BisetMap;

let bmap = BisetMap::new();
assert!(bmap.is_empty());
bmap.insert('a', 1);
assert!(!bmap.is_empty());
bmap.rev_delete(&1);
assert!(bmap.is_empty());

Trait Implementations§

Source§

impl<L: Clone + Eq + Hash + Clone, R: Clone + Eq + Hash + Clone> Clone for BisetMap<L, R>

Source§

fn clone(&self) -> BisetMap<L, R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Eq + Hash + Clone + Debug, R: Eq + Hash + Clone + Debug> Debug for BisetMap<L, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: Eq + Hash + Clone, R: Eq + Hash + Clone> Default for BisetMap<L, R>

Source§

fn default() -> BisetMap<L, R>

Returns the “default value” for a type. Read more
Source§

impl<'de, L: Eq + Hash + Clone + Deserialize<'de>, R: Eq + Hash + Clone + Deserialize<'de>> Deserialize<'de> for BisetMap<L, R>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<L: Eq + Hash + Clone + Serialize, R: Eq + Hash + Clone + Serialize> Serialize for BisetMap<L, R>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<L, R> Freeze for BisetMap<L, R>

§

impl<L, R> RefUnwindSafe for BisetMap<L, R>

§

impl<L, R> Send for BisetMap<L, R>
where L: Send, R: Send,

§

impl<L, R> Sync for BisetMap<L, R>
where L: Send, R: Send,

§

impl<L, R> Unpin for BisetMap<L, R>

§

impl<L, R> UnwindSafe for BisetMap<L, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,