relate_executor/graph/
access.rs1use relate_core::{NodeId, RelId, Value};
6
7use crate::redo::PullKind;
8
9use super::chain::{Chain, VerRef};
10use super::id_vec::IdVec;
11use super::Graph;
12
13pub(super) fn visible_version<Live>(vers: &Chain<Live>, ts: u64) -> Option<VerRef<'_, Live>> {
17 vers.visible_at(ts)
18}
19
20pub(super) fn live_version<Live>(vers: &Chain<Live>) -> Option<VerRef<'_, Live>> {
28 vers.live()
29}
30
31fn visible_ids<Live>(map: &IdVec<Chain<Live>>, ts: u64) -> Vec<i64> {
34 let mut ids = Vec::new();
35 map.for_each(|id, vers| {
36 if visible_version(vers, ts).is_some() {
37 ids.push(id);
38 }
39 });
40 ids.sort();
41 ids
42}
43
44impl Graph {
45 pub fn node_value(&self, id: NodeId) -> Value {
46 self.node(id).map(Value::from_node).unwrap_or(Value::Null)
47 }
48
49 pub fn rel_value(&self, id: RelId) -> Value {
50 self.rel(id)
51 .map(Value::from_relationship)
52 .unwrap_or(Value::Null)
53 }
54
55 pub fn pull_identity_get(&self, source: &str, kind: PullKind, remote_id: &str) -> Option<i64> {
56 self.pull_identity.get(source, kind, remote_id)
57 }
58
59 pub fn pull_identity_put(
60 &self,
61 source: String,
62 kind: PullKind,
63 remote_id: String,
64 local_id: i64,
65 ) {
66 self.pull_identity.put(source, kind, remote_id, local_id);
67 }
68
69 pub fn drop_pull_identity(&self, kind: PullKind, local_id: i64) {
70 self.pull_identity.remove(kind, local_id);
71 }
72
73 pub fn all_rel_ids(&self) -> Vec<RelId> {
74 self.all_rel_ids_at(self.read_ts())
75 }
76
77 pub fn all_rel_ids_at(&self, ts: u64) -> Vec<RelId> {
78 visible_ids(&self.rels, ts)
79 }
80
81 pub fn all_node_ids(&self) -> Vec<NodeId> {
82 self.all_node_ids_at(self.read_ts())
83 }
84
85 pub fn all_node_ids_at(&self, ts: u64) -> Vec<NodeId> {
86 visible_ids(&self.nodes, ts)
87 }
88}