pub struct MapDomain<DK: Domain, DV: Domain>{
pub key_domain: DK,
pub value_domain: DV,
}
Expand description
A Domain that contains maps of (homogeneous) values.
§Proof Definition
MapDomain(key_domain, value_domain, DK, DV)
consists of all hashmaps where
keys are elements of key_domain (of type DK) and
values are elements of value_domain (of type DV).
The elements in the DK domain are hashable and have a strict equality operation.
§Example
use opendp::domains::{MapDomain, AtomDomain};
// Rust infers the type from the context, at compile-time.
// Members of this domain are of type `HashMap<&str, i32>`.
let domain = MapDomain::new(AtomDomain::default(), AtomDomain::default());
use opendp::core::Domain;
use std::collections::HashMap;
// create a hashmap we can test with
let hashmap = HashMap::from_iter([("a", 23), ("b", 12)]);
assert!(domain.member(&hashmap)?);
// Can build up more complicated domains as needed:
let value_domain = AtomDomain::new_closed((0., 1.))?;
let domain = MapDomain::new(AtomDomain::default(), value_domain);
// The following is not a member of the hashmap domain, because a value is out-of-range:
let hashmap = HashMap::from_iter([("a", 0.), ("b", 2.)]);
assert!(!domain.member(&hashmap)?);
Fields§
§key_domain: DK
§value_domain: DV
Implementations§
Trait Implementations§
source§impl<DK: Domain, DV: Domain> Domain for MapDomain<DK, DV>
impl<DK: Domain, DV: Domain> Domain for MapDomain<DK, DV>
source§impl<DK: PartialEq + Domain, DV: PartialEq + Domain> PartialEq for MapDomain<DK, DV>
impl<DK: PartialEq + Domain, DV: PartialEq + Domain> PartialEq for MapDomain<DK, DV>
impl<DK: Domain, DV: Domain> StructuralPartialEq for MapDomain<DK, DV>
Auto Trait Implementations§
impl<DK, DV> Freeze for MapDomain<DK, DV>
impl<DK, DV> RefUnwindSafe for MapDomain<DK, DV>where
DK: RefUnwindSafe,
DV: RefUnwindSafe,
impl<DK, DV> Send for MapDomain<DK, DV>
impl<DK, DV> Sync for MapDomain<DK, DV>
impl<DK, DV> Unpin for MapDomain<DK, DV>
impl<DK, DV> UnwindSafe for MapDomain<DK, DV>where
DK: UnwindSafe,
DV: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.