Struct CapeOpenMap

Source
pub struct CapeOpenMap<V>(HashMap<CapeStringHashKey<'static>, V, FxBuildHasher>);
Expand description

Class to store a platform dependent string encoding for use in case insensitive hash maps or for use of case insensitive comparisons.

For COBIA, strings go over the pipeline as null terminated. For Windows, COBIA requires UTF-16 encoding.

The CapeStringHashKey implementation uses a Vec<u16> to store, owned string data, or allows reference to data provided by any class that implements CapeStringConstProvider, so that a copy of the data is not needed for hash lookups.

This construct however requires that the hash keys are given a lifetime; the hash keys that are stored in the map are owned by the map and are given a dummy life time of ’static. Hash keys that are borrowed from a CapeStringConstProvider are given the lifetime of the provider. This implies that the life time checker for any mutable references to the hash map assumes that keys past to such references are of life time ’static. Hence, mutable members of the hash map cannot take a borrowed key, but must use an owned key; in particular we cannot remove a key from the map using a borrowed key, nor can we return mutable references to the values in the map based on borrowed keys. Some traits, like Index, do not allow for such life time constraints and are not implemented. Use fn get() instead. Other than that, the CapeOpenMap generally provides the same interface as the standard HashMap, on which it is based.

A common use case in CAPE-OPEN is to make hash maps of strings for case-insentive lookups: CapeOpenMap` uses the more performant hasher in the FxHasmap class.

As the constructors are not const, a construct like for example LazyLock can be used to make static instances of this class, or any class that contains this class.

§Examples

use cobia::*;
use cobia::prelude::*;
let mut map=cobia::CapeOpenMap::new();
map.insert(cobia::CapeStringHashKey::from_string("idealGasEnthalpy"),1);
map.insert("idealGasEntropy".into(),2);

assert_eq!(map.get(&cobia::CapeStringConstNoCase::from_string("IDEALGASENTHALPY")),Some(&1));

assert_eq!(map.get(&cobia::CapeStringImpl::from_string("IDEALGASENTROPY")),Some(&2));

let s2=cobia::CapeStringImpl::from_string("IDEALGASENTHALPY");
fn test_string_in(map:&cobia::CapeOpenMap<i32>,s: &cobia::CapeStringIn) {
    assert_eq!(map.get(s),Some(&1));
}
test_string_in(&map,&CapeStringInFromProvider::from(&s2).as_cape_string_in());

assert_eq!(map.get(&cobia::CapeStringImpl::from_string("CriticalTemperature")),None);

Tuple Fields§

§0: HashMap<CapeStringHashKey<'static>, V, FxBuildHasher>

Implementations§

Source§

impl<V> CapeOpenMap<V>

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn capacity(&self) -> usize

Source

pub fn keys(&self) -> Keys<'_, CapeStringHashKey<'static>, V>

Source

pub fn into_keys(self) -> IntoKeys<CapeStringHashKey<'static>, V>

Source

pub fn values(&self) -> Values<'_, CapeStringHashKey<'static>, V>

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, CapeStringHashKey<'static>, V>

Source

pub fn into_values(self) -> IntoValues<CapeStringHashKey<'static>, V>

Source

pub fn iter(&self) -> Iter<'_, CapeStringHashKey<'static>, V>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, CapeStringHashKey<'static>, V>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn drain(&mut self) -> Drain<'_, CapeStringHashKey<'static>, V>

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&CapeStringHashKey<'static>, &mut V) -> bool,

Source

pub fn clear(&mut self)

Source

pub fn reserve(&mut self, additional: usize)

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Source

pub fn shrink_to_fit(&mut self)

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Source

pub fn entry( &mut self, key: CapeStringHashKey<'static>, ) -> Entry<'_, CapeStringHashKey<'static>, V>

Source

pub fn get<'a, 'b, Q: CapeStringConstProvider>( &'a self, k: &'b Q, ) -> Option<&'a V>
where 'b: 'a,

Source

pub fn get_mut<'a>( &'a mut self, k: CapeStringHashKey<'static>, ) -> Option<&'a mut V>

Source

pub fn contains_key<Q: CapeStringConstProvider>(&self, k: &Q) -> bool

Source

pub fn insert_from_cape_string_constant<T: CapeStringConstProvider>( &mut self, k: T, v: V, ) -> Option<V>

Source

pub fn insert(&mut self, k: CapeStringHashKey<'static>, v: V) -> Option<V>

Source

pub fn remove<'a>(&'a mut self, k: CapeStringHashKey<'static>) -> Option<V>

Source

pub fn remove_entry<'a>( &mut self, k: CapeStringHashKey<'static>, ) -> Option<(CapeStringHashKey<'static>, V)>

Trait Implementations§

Source§

impl<V: Clone> Clone for CapeOpenMap<V>

Source§

fn clone(&self) -> Self

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<V: Debug> Debug for CapeOpenMap<V>

Source§

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

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

impl<V> Default for CapeOpenMap<V>

Source§

fn default() -> Self

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

impl<V: PartialEq> PartialEq for CapeOpenMap<V>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Eq> Eq for CapeOpenMap<V>

Auto Trait Implementations§

§

impl<V> Freeze for CapeOpenMap<V>

§

impl<V> RefUnwindSafe for CapeOpenMap<V>
where V: RefUnwindSafe,

§

impl<V> Send for CapeOpenMap<V>
where V: Send,

§

impl<V> Sync for CapeOpenMap<V>
where V: Sync,

§

impl<V> Unpin for CapeOpenMap<V>
where V: Unpin,

§

impl<V> UnwindSafe for CapeOpenMap<V>
where V: UnwindSafe,

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.