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>