Skip to main content

uqa_graph/
memory_store.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! In-memory implementation of [`GraphStore`].
8//!
9//! Vertex and edge records live in a global map, while each named graph owns a
10//! partition of membership and adjacency indexes. AGE-compatible graph ids and
11//! their per-graph label registries are managed separately.
12
13use std::collections::{BTreeMap, BTreeSet};
14
15use serde::{Deserialize, Serialize};
16use uqa_core::{Edge, EdgeId, Vertex, VertexId};
17
18use crate::store::{GraphStore, GraphStoreError, GraphStoreResult};
19use crate::types::Direction;
20
21mod graphid;
22mod partition;
23mod store;
24mod trait_impl;
25
26pub use graphid::{
27    graphid_label_id, graphid_sequence, make_graphid, GraphLabelInfo, GraphLabelRegistry,
28    LabelKind, EDGE_DEFAULT_LABEL_ID, FIRST_USER_LABEL_ID, GRAPHID_LABEL_SHIFT,
29    VERTEX_DEFAULT_LABEL_ID,
30};
31
32use graphid::usize_to_f64_exact;
33#[cfg(test)]
34use graphid::{MAX_GRAPHID_LABEL_ID, MAX_GRAPHID_SEQUENCE};
35use partition::Partition;
36
37#[derive(Debug, Default, Clone)]
38pub struct MemoryGraphStore {
39    vertices: BTreeMap<VertexId, Vertex>,
40    edges: BTreeMap<EdgeId, Edge>,
41    graphs: BTreeMap<String, Partition>,
42    vertex_membership: BTreeMap<VertexId, BTreeSet<String>>,
43    edge_membership: BTreeMap<EdgeId, BTreeSet<String>>,
44    label_registries: BTreeMap<String, GraphLabelRegistry>,
45    next_vertex_id: VertexId,
46    next_edge_id: EdgeId,
47}
48
49#[cfg(test)]
50mod tests;