Struct opendp::domains::MapDomain

source ·
pub struct MapDomain<DK: Domain, DV: Domain>
where DK::Carrier: Eq + Hash,
{ 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§

source§

impl<DK: Domain, DV: Domain> MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

source

pub fn new(key_domain: DK, element_domain: DV) -> Self

Trait Implementations§

source§

impl<DK: Clone + Domain, DV: Clone + Domain> Clone for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

source§

fn clone(&self) -> MapDomain<DK, DV>

Returns a copy 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<DK: Debug + Domain, DV: Debug + Domain> Debug for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

source§

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

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

impl<DK: Default + Domain, DV: Default + Domain> Default for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

source§

fn default() -> MapDomain<DK, DV>

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

impl<DK: Domain, DV: Domain> Domain for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

§

type Carrier = HashMap<<DK as Domain>::Carrier, <DV as Domain>::Carrier>

The underlying type that the Domain specializes. This is the type of a member of a domain, where a domain is any data type that implements this trait. Read more
source§

fn member(&self, val: &Self::Carrier) -> Fallible<bool>

Predicate to test an element for membership in the domain. Not all possible values of ::Carrier are a member of the domain. Read more
source§

impl<DK: PartialEq + Domain, DV: PartialEq + Domain> PartialEq for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

source§

fn eq(&self, other: &MapDomain<DK, DV>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<DK: Domain, DV: Domain> StructuralPartialEq for MapDomain<DK, DV>
where DK::Carrier: Eq + Hash,

Auto Trait Implementations§

§

impl<DK, DV> Freeze for MapDomain<DK, DV>
where DK: Freeze, DV: Freeze,

§

impl<DK, DV> RefUnwindSafe for MapDomain<DK, DV>

§

impl<DK, DV> Send for MapDomain<DK, DV>

§

impl<DK, DV> Sync for MapDomain<DK, DV>

§

impl<DK, DV> Unpin for MapDomain<DK, DV>
where DK: Unpin, DV: Unpin,

§

impl<DK, DV> UnwindSafe for MapDomain<DK, DV>
where DK: UnwindSafe, DV: 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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V