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