datex_core/runtime/
pointer_availability_lookup.rs1use crate::collections::HashMap;
2
3use crate::{
4 prelude::*, shared_values::PointerAddress,
5 values::core_values::endpoint::Endpoint,
6};
7
8#[derive(Debug, Clone, Default)]
9pub struct PointerAvailabilityLookup {
10 local_endpoint: Endpoint,
11 lookup: HashMap<Endpoint, Vec<PointerAddress>>,
12}
13
14impl PointerAvailabilityLookup {
15 pub fn new(origin: Endpoint) -> Self {
16 Self {
17 local_endpoint: origin,
18 lookup: HashMap::new(),
19 }
20 }
21 pub fn is_available_for_endpoint(
22 &self,
23 endpoint: &Endpoint,
24 pointer_address: &PointerAddress,
25 ) -> bool {
26 if endpoint.is_local_or_equals_endpoint(&self.local_endpoint)
27 && matches!(pointer_address, PointerAddress::SelfOwned(_))
28 {
29 return true;
30 }
31 false }
33 pub fn is_available_for_all_endpoints(
34 &self,
35 endpoints: &[Endpoint],
36 pointer_address: &PointerAddress,
37 ) -> bool {
38 for endpoint in endpoints {
39 if !self.is_available_for_endpoint(endpoint, pointer_address) {
40 return false;
41 }
42 }
43 true
44 }
45}