Skip to main content

grafeo_core/graph/lpg/store/
mod.rs

1//! The in-memory LPG graph store.
2//!
3//! This is where your nodes and edges actually live. Most users interact
4//! through [`GrafeoDB`](grafeo_engine::GrafeoDB), but algorithm implementers
5//! sometimes need the raw [`LpgStore`] for direct adjacency traversal.
6//!
7//! Key features:
8//! - MVCC versioning - concurrent readers don't block each other
9//! - Columnar properties with zone maps for fast filtering
10//! - Forward and backward adjacency indexes
11
12mod edge_ops;
13mod graph_store_impl;
14mod index;
15mod node_ops;
16mod property_ops;
17mod schema;
18mod search;
19mod statistics;
20mod traversal;
21mod versioning;
22
23#[cfg(test)]
24mod tests;
25
26use super::PropertyStorage;
27#[cfg(not(feature = "tiered-storage"))]
28use super::{EdgeRecord, NodeRecord};
29use crate::index::adjacency::ChunkedAdjacency;
30use crate::statistics::Statistics;
31use arcstr::ArcStr;
32use dashmap::DashMap;
33#[cfg(not(feature = "tiered-storage"))]
34use grafeo_common::mvcc::VersionChain;
35use grafeo_common::types::{EdgeId, EpochId, HashableValue, NodeId, PropertyKey, Value};
36use grafeo_common::utils::hash::{FxHashMap, FxHashSet};
37use parking_lot::RwLock;
38use std::cmp::Ordering as CmpOrdering;
39use std::sync::Arc;
40use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, Ordering};
41
42#[cfg(feature = "vector-index")]
43use crate::index::vector::HnswIndex;
44
45#[cfg(feature = "tiered-storage")]
46use crate::storage::EpochStore;
47use grafeo_common::memory::arena::AllocError;
48#[cfg(feature = "tiered-storage")]
49use grafeo_common::memory::arena::ArenaAllocator;
50#[cfg(feature = "tiered-storage")]
51use grafeo_common::mvcc::VersionIndex;
52
53/// Compares two values for ordering (used for range checks).
54pub(super) fn compare_values_for_range(a: &Value, b: &Value) -> Option<CmpOrdering> {
55    match (a, b) {
56        (Value::Int64(a), Value::Int64(b)) => Some(a.cmp(b)),
57        (Value::Float64(a), Value::Float64(b)) => a.partial_cmp(b),
58        (Value::String(a), Value::String(b)) => Some(a.cmp(b)),
59        (Value::Bool(a), Value::Bool(b)) => Some(a.cmp(b)),
60        (Value::Timestamp(a), Value::Timestamp(b)) => Some(a.cmp(b)),
61        (Value::Date(a), Value::Date(b)) => Some(a.cmp(b)),
62        (Value::Time(a), Value::Time(b)) => Some(a.cmp(b)),
63        _ => None,
64    }
65}
66
67/// Checks if a value is within a range.
68pub(super) fn value_in_range(
69    value: &Value,
70    min: Option<&Value>,
71    max: Option<&Value>,
72    min_inclusive: bool,
73    max_inclusive: bool,
74) -> bool {
75    // Check lower bound
76    if let Some(min_val) = min {
77        match compare_values_for_range(value, min_val) {
78            Some(CmpOrdering::Less) => return false,
79            Some(CmpOrdering::Equal) if !min_inclusive => return false,
80            None => return false, // Can't compare
81            _ => {}
82        }
83    }
84
85    // Check upper bound
86    if let Some(max_val) = max {
87        match compare_values_for_range(value, max_val) {
88            Some(CmpOrdering::Greater) => return false,
89            Some(CmpOrdering::Equal) if !max_inclusive => return false,
90            None => return false,
91            _ => {}
92        }
93    }
94
95    true
96}
97
98/// Configuration for the LPG store.
99///
100/// The defaults work well for most cases. Tune `backward_edges` if you only
101/// traverse in one direction (saves memory), or adjust capacities if you know
102/// your graph size upfront (avoids reallocations).
103#[derive(Debug, Clone)]
104pub struct LpgStoreConfig {
105    /// Maintain backward adjacency for incoming edge queries. Turn off if
106    /// you only traverse outgoing edges - saves ~50% adjacency memory.
107    pub backward_edges: bool,
108    /// Initial capacity for nodes (avoids early reallocations).
109    pub initial_node_capacity: usize,
110    /// Initial capacity for edges (avoids early reallocations).
111    pub initial_edge_capacity: usize,
112}
113
114impl Default for LpgStoreConfig {
115    fn default() -> Self {
116        Self {
117            backward_edges: true,
118            initial_node_capacity: 1024,
119            initial_edge_capacity: 4096,
120        }
121    }
122}
123
124/// The core in-memory graph storage.
125///
126/// Everything lives here: nodes, edges, properties, adjacency indexes, and
127/// version chains for MVCC. Concurrent reads never block each other.
128///
129/// Most users should go through `GrafeoDB` (from the `grafeo_engine` crate) which
130/// adds transaction management and query execution. Use `LpgStore` directly
131/// when you need raw performance for algorithm implementations.
132///
133/// # Example
134///
135/// ```
136/// use grafeo_core::graph::lpg::LpgStore;
137/// use grafeo_core::graph::Direction;
138///
139/// let store = LpgStore::new().expect("arena allocation");
140///
141/// // Create a small social network
142/// let alix = store.create_node(&["Person"]);
143/// let gus = store.create_node(&["Person"]);
144/// store.create_edge(alix, gus, "KNOWS");
145///
146/// // Traverse outgoing edges
147/// for neighbor in store.neighbors(alix, Direction::Outgoing) {
148///     println!("Alix knows node {:?}", neighbor);
149/// }
150/// ```
151///
152/// # Lock Ordering
153///
154/// `LpgStore` contains multiple `RwLock` fields that must be acquired in a
155/// consistent order to prevent deadlocks. Always acquire locks in this order:
156///
157/// ## Level 1 - Entity Storage (mutually exclusive via feature flag)
158/// 1. `nodes` / `node_versions`
159/// 2. `edges` / `edge_versions`
160///
161/// ## Level 2 - Catalogs (acquire as pairs when writing)
162/// 3. `label_to_id` + `id_to_label`
163/// 4. `edge_type_to_id` + `id_to_edge_type`
164///
165/// ## Level 3 - Indexes
166/// 5. `label_index`
167/// 6. `node_labels`
168/// 7. `property_indexes`
169///
170/// ## Level 4 - Statistics
171/// 8. `statistics`
172///
173/// ## Level 5 - Nested Locks (internal to other structs)
174/// 9. `PropertyStorage::columns` (via `node_properties`/`edge_properties`)
175/// 10. `ChunkedAdjacency::lists` (via `forward_adj`/`backward_adj`)
176///
177/// ## Rules
178/// - Catalog pairs must be acquired together when writing.
179/// - Never hold entity locks while acquiring catalog locks in a different scope.
180/// - Statistics lock is always last.
181/// - Read locks are generally safe, but avoid read-to-write upgrades.
182pub struct LpgStore {
183    /// Configuration.
184    #[allow(dead_code)]
185    pub(super) config: LpgStoreConfig,
186
187    /// Node records indexed by NodeId, with version chains for MVCC.
188    /// Used when `tiered-storage` feature is disabled.
189    /// Lock order: 1
190    #[cfg(not(feature = "tiered-storage"))]
191    pub(super) nodes: RwLock<FxHashMap<NodeId, VersionChain<NodeRecord>>>,
192
193    /// Edge records indexed by EdgeId, with version chains for MVCC.
194    /// Used when `tiered-storage` feature is disabled.
195    /// Lock order: 2
196    #[cfg(not(feature = "tiered-storage"))]
197    pub(super) edges: RwLock<FxHashMap<EdgeId, VersionChain<EdgeRecord>>>,
198
199    // === Tiered Storage Fields (feature-gated) ===
200    //
201    // Lock ordering for arena access:
202    //   version_lock (read/write) → arena read lock (via arena_allocator.arena())
203    //
204    // Rules:
205    // - Acquire arena read lock *after* version locks, never before.
206    // - Multiple threads may call arena.read_at() concurrently (shared refs only).
207    // - Never acquire arena write lock (alloc_new_chunk) while holding version locks.
208    // - freeze_epoch order: node_versions.read() → arena.read_at(),
209    //   then edge_versions.read() → arena.read_at().
210    /// Arena allocator for hot data storage.
211    /// Data is stored in per-epoch arenas for fast allocation and bulk deallocation.
212    #[cfg(feature = "tiered-storage")]
213    pub(super) arena_allocator: Arc<ArenaAllocator>,
214
215    /// Node version indexes - store metadata and arena offsets.
216    /// The actual NodeRecord data is stored in the arena.
217    /// Lock order: 1
218    #[cfg(feature = "tiered-storage")]
219    pub(super) node_versions: RwLock<FxHashMap<NodeId, VersionIndex>>,
220
221    /// Edge version indexes - store metadata and arena offsets.
222    /// The actual EdgeRecord data is stored in the arena.
223    /// Lock order: 2
224    #[cfg(feature = "tiered-storage")]
225    pub(super) edge_versions: RwLock<FxHashMap<EdgeId, VersionIndex>>,
226
227    /// Cold storage for frozen epochs.
228    /// Contains compressed epoch blocks for historical data.
229    #[cfg(feature = "tiered-storage")]
230    pub(super) epoch_store: Arc<EpochStore>,
231
232    /// Property storage for nodes.
233    pub(super) node_properties: PropertyStorage<NodeId>,
234
235    /// Property storage for edges.
236    pub(super) edge_properties: PropertyStorage<EdgeId>,
237
238    /// Label name to ID mapping.
239    /// Lock order: 3 (acquire with id_to_label)
240    pub(super) label_to_id: RwLock<FxHashMap<ArcStr, u32>>,
241
242    /// Label ID to name mapping.
243    /// Lock order: 3 (acquire with label_to_id)
244    pub(super) id_to_label: RwLock<Vec<ArcStr>>,
245
246    /// Edge type name to ID mapping.
247    /// Lock order: 4 (acquire with id_to_edge_type)
248    pub(super) edge_type_to_id: RwLock<FxHashMap<ArcStr, u32>>,
249
250    /// Edge type ID to name mapping.
251    /// Lock order: 4 (acquire with edge_type_to_id)
252    pub(super) id_to_edge_type: RwLock<Vec<ArcStr>>,
253
254    /// Forward adjacency lists (outgoing edges).
255    pub(super) forward_adj: ChunkedAdjacency,
256
257    /// Backward adjacency lists (incoming edges).
258    /// Only populated if config.backward_edges is true.
259    pub(super) backward_adj: Option<ChunkedAdjacency>,
260
261    /// Label index: label_id -> set of node IDs.
262    /// Lock order: 5
263    pub(super) label_index: RwLock<Vec<FxHashMap<NodeId, ()>>>,
264
265    /// Node labels: node_id -> set of label IDs.
266    /// Reverse mapping to efficiently get labels for a node.
267    /// Lock order: 6
268    pub(super) node_labels: RwLock<FxHashMap<NodeId, FxHashSet<u32>>>,
269
270    /// Property indexes: property_key -> (value -> set of node IDs).
271    ///
272    /// When a property is indexed, lookups by value are O(1) instead of O(n).
273    /// Use [`create_property_index`] to enable indexing for a property.
274    /// Lock order: 7
275    pub(super) property_indexes:
276        RwLock<FxHashMap<PropertyKey, DashMap<HashableValue, FxHashSet<NodeId>>>>,
277
278    /// Vector indexes: "label:property" -> HNSW index.
279    ///
280    /// Created via [`GrafeoDB::create_vector_index`](grafeo_engine::GrafeoDB::create_vector_index).
281    /// Lock order: 7 (same level as property_indexes, disjoint keys)
282    #[cfg(feature = "vector-index")]
283    pub(super) vector_indexes: RwLock<FxHashMap<String, Arc<HnswIndex>>>,
284
285    /// Text indexes: "label:property" -> inverted index with BM25 scoring.
286    ///
287    /// Created via [`GrafeoDB::create_text_index`](grafeo_engine::GrafeoDB::create_text_index).
288    /// Lock order: 7 (same level as property_indexes, disjoint keys)
289    #[cfg(feature = "text-index")]
290    pub(super) text_indexes:
291        RwLock<FxHashMap<String, Arc<RwLock<crate::index::text::InvertedIndex>>>>,
292
293    /// Next node ID.
294    pub(super) next_node_id: AtomicU64,
295
296    /// Next edge ID.
297    pub(super) next_edge_id: AtomicU64,
298
299    /// Current epoch.
300    pub(super) current_epoch: AtomicU64,
301
302    /// Live (non-deleted) node count, maintained incrementally.
303    /// Avoids O(n) full scan in `compute_statistics()`.
304    pub(super) live_node_count: AtomicI64,
305
306    /// Live (non-deleted) edge count, maintained incrementally.
307    /// Avoids O(m) full scan in `compute_statistics()`.
308    pub(super) live_edge_count: AtomicI64,
309
310    /// Per-edge-type live counts, indexed by edge_type_id.
311    /// Avoids O(m) edge scan in `compute_statistics()`.
312    /// Lock order: 8 (same level as statistics)
313    pub(super) edge_type_live_counts: RwLock<Vec<i64>>,
314
315    /// Statistics for cost-based optimization.
316    /// Lock order: 8 (always last)
317    pub(super) statistics: RwLock<Arc<Statistics>>,
318
319    /// Whether statistics need full recomputation (e.g., after rollback).
320    pub(super) needs_stats_recompute: AtomicBool,
321
322    /// Named graphs, each an independent `LpgStore` partition.
323    /// Zero overhead for single-graph databases (empty HashMap).
324    /// Lock order: 9 (after statistics)
325    named_graphs: RwLock<FxHashMap<String, Arc<LpgStore>>>,
326}
327
328impl LpgStore {
329    /// Creates a new LPG store with default configuration.
330    ///
331    /// # Errors
332    ///
333    /// Returns [`AllocError`] if the arena allocator cannot be initialized
334    /// (only possible with the `tiered-storage` feature).
335    pub fn new() -> Result<Self, AllocError> {
336        Self::with_config(LpgStoreConfig::default())
337    }
338
339    /// Creates a new LPG store with custom configuration.
340    ///
341    /// # Errors
342    ///
343    /// Returns [`AllocError`] if the arena allocator cannot be initialized
344    /// (only possible with the `tiered-storage` feature).
345    pub fn with_config(config: LpgStoreConfig) -> Result<Self, AllocError> {
346        let backward_adj = if config.backward_edges {
347            Some(ChunkedAdjacency::new())
348        } else {
349            None
350        };
351
352        Ok(Self {
353            #[cfg(not(feature = "tiered-storage"))]
354            nodes: RwLock::new(FxHashMap::default()),
355            #[cfg(not(feature = "tiered-storage"))]
356            edges: RwLock::new(FxHashMap::default()),
357            #[cfg(feature = "tiered-storage")]
358            arena_allocator: Arc::new(ArenaAllocator::new()?),
359            #[cfg(feature = "tiered-storage")]
360            node_versions: RwLock::new(FxHashMap::default()),
361            #[cfg(feature = "tiered-storage")]
362            edge_versions: RwLock::new(FxHashMap::default()),
363            #[cfg(feature = "tiered-storage")]
364            epoch_store: Arc::new(EpochStore::new()),
365            node_properties: PropertyStorage::new(),
366            edge_properties: PropertyStorage::new(),
367            label_to_id: RwLock::new(FxHashMap::default()),
368            id_to_label: RwLock::new(Vec::new()),
369            edge_type_to_id: RwLock::new(FxHashMap::default()),
370            id_to_edge_type: RwLock::new(Vec::new()),
371            forward_adj: ChunkedAdjacency::new(),
372            backward_adj,
373            label_index: RwLock::new(Vec::new()),
374            node_labels: RwLock::new(FxHashMap::default()),
375            property_indexes: RwLock::new(FxHashMap::default()),
376            #[cfg(feature = "vector-index")]
377            vector_indexes: RwLock::new(FxHashMap::default()),
378            #[cfg(feature = "text-index")]
379            text_indexes: RwLock::new(FxHashMap::default()),
380            next_node_id: AtomicU64::new(0),
381            next_edge_id: AtomicU64::new(0),
382            current_epoch: AtomicU64::new(0),
383            live_node_count: AtomicI64::new(0),
384            live_edge_count: AtomicI64::new(0),
385            edge_type_live_counts: RwLock::new(Vec::new()),
386            statistics: RwLock::new(Arc::new(Statistics::new())),
387            needs_stats_recompute: AtomicBool::new(false),
388            named_graphs: RwLock::new(FxHashMap::default()),
389            config,
390        })
391    }
392
393    /// Returns the current epoch.
394    #[must_use]
395    pub fn current_epoch(&self) -> EpochId {
396        EpochId::new(self.current_epoch.load(Ordering::Acquire))
397    }
398
399    /// Creates a new epoch.
400    #[doc(hidden)]
401    pub fn new_epoch(&self) -> EpochId {
402        let id = self.current_epoch.fetch_add(1, Ordering::AcqRel) + 1;
403        EpochId::new(id)
404    }
405
406    /// Syncs the store epoch to match an external epoch counter.
407    ///
408    /// Used by the transaction manager to keep the store's epoch in step
409    /// after a transaction commit advances the global epoch.
410    #[doc(hidden)]
411    pub fn sync_epoch(&self, epoch: EpochId) {
412        self.current_epoch
413            .fetch_max(epoch.as_u64(), Ordering::AcqRel);
414    }
415
416    /// Removes all data from the store, resetting it to an empty state.
417    ///
418    /// Acquires locks in the documented ordering to prevent deadlocks.
419    /// After clearing, the store behaves as if freshly constructed.
420    pub fn clear(&self) {
421        // Level 1: Entity storage
422        #[cfg(not(feature = "tiered-storage"))]
423        {
424            self.nodes.write().clear();
425            self.edges.write().clear();
426        }
427        #[cfg(feature = "tiered-storage")]
428        {
429            self.node_versions.write().clear();
430            self.edge_versions.write().clear();
431            // Arena allocator chunks are leaked; epochs are cleared via epoch_store.
432        }
433
434        // Level 2: Catalogs (acquire as pairs)
435        {
436            self.label_to_id.write().clear();
437            self.id_to_label.write().clear();
438        }
439        {
440            self.edge_type_to_id.write().clear();
441            self.id_to_edge_type.write().clear();
442        }
443
444        // Level 3: Indexes
445        self.label_index.write().clear();
446        self.node_labels.write().clear();
447        self.property_indexes.write().clear();
448        #[cfg(feature = "vector-index")]
449        self.vector_indexes.write().clear();
450        #[cfg(feature = "text-index")]
451        self.text_indexes.write().clear();
452
453        // Nested: Properties and adjacency
454        self.node_properties.clear();
455        self.edge_properties.clear();
456        self.forward_adj.clear();
457        if let Some(ref backward) = self.backward_adj {
458            backward.clear();
459        }
460
461        // Atomics: ID counters
462        self.next_node_id.store(0, Ordering::Release);
463        self.next_edge_id.store(0, Ordering::Release);
464        self.current_epoch.store(0, Ordering::Release);
465
466        // Level 4: Statistics
467        self.live_node_count.store(0, Ordering::Release);
468        self.live_edge_count.store(0, Ordering::Release);
469        self.edge_type_live_counts.write().clear();
470        *self.statistics.write() = Arc::new(Statistics::new());
471        self.needs_stats_recompute.store(false, Ordering::Release);
472    }
473
474    /// Returns whether backward adjacency (incoming edge index) is available.
475    ///
476    /// When backward adjacency is enabled (the default), bidirectional search
477    /// algorithms can traverse from the target toward the source.
478    #[must_use]
479    pub fn has_backward_adjacency(&self) -> bool {
480        self.backward_adj.is_some()
481    }
482
483    // === Named Graph Management ===
484
485    /// Returns a named graph by name, or `None` if it does not exist.
486    #[must_use]
487    pub fn graph(&self, name: &str) -> Option<Arc<LpgStore>> {
488        self.named_graphs.read().get(name).cloned()
489    }
490
491    /// Returns a named graph, creating it if it does not exist.
492    ///
493    /// # Errors
494    ///
495    /// Returns [`AllocError`] if a new store cannot be allocated.
496    pub fn graph_or_create(&self, name: &str) -> Result<Arc<LpgStore>, AllocError> {
497        {
498            let graphs = self.named_graphs.read();
499            if let Some(g) = graphs.get(name) {
500                return Ok(Arc::clone(g));
501            }
502        }
503        let mut graphs = self.named_graphs.write();
504        // Double-check after acquiring write lock
505        if let Some(g) = graphs.get(name) {
506            return Ok(Arc::clone(g));
507        }
508        let store = Arc::new(LpgStore::new()?);
509        graphs.insert(name.to_string(), Arc::clone(&store));
510        Ok(store)
511    }
512
513    /// Creates a named graph. Returns `true` on success, `false` if it already exists.
514    ///
515    /// # Errors
516    ///
517    /// Returns [`AllocError`] if the new store cannot be allocated.
518    pub fn create_graph(&self, name: &str) -> Result<bool, AllocError> {
519        let mut graphs = self.named_graphs.write();
520        if graphs.contains_key(name) {
521            return Ok(false);
522        }
523        graphs.insert(name.to_string(), Arc::new(LpgStore::new()?));
524        Ok(true)
525    }
526
527    /// Drops a named graph. Returns `false` if it did not exist.
528    pub fn drop_graph(&self, name: &str) -> bool {
529        self.named_graphs.write().remove(name).is_some()
530    }
531
532    /// Returns all named graph names.
533    #[must_use]
534    pub fn graph_names(&self) -> Vec<String> {
535        self.named_graphs.read().keys().cloned().collect()
536    }
537
538    /// Returns the number of named graphs.
539    #[must_use]
540    pub fn graph_count(&self) -> usize {
541        self.named_graphs.read().len()
542    }
543
544    /// Clears a specific graph, or the default graph if `name` is `None`.
545    pub fn clear_graph(&self, name: Option<&str>) {
546        match name {
547            Some(n) => {
548                if let Some(g) = self.named_graphs.read().get(n) {
549                    g.clear();
550                }
551            }
552            None => self.clear(),
553        }
554    }
555
556    /// Copies all data from the source graph to the destination graph.
557    /// Creates the destination graph if it does not exist.
558    ///
559    /// # Errors
560    ///
561    /// Returns [`AllocError`] if the destination store cannot be allocated.
562    pub fn copy_graph(&self, source: Option<&str>, dest: Option<&str>) -> Result<(), AllocError> {
563        let _src = match source {
564            Some(n) => self.graph(n),
565            None => None, // default graph
566        };
567        let _dest_graph = dest.map(|n| self.graph_or_create(n)).transpose()?;
568        // Full graph copy is complex (requires iterating all entities).
569        // For now, this creates the destination graph structure.
570        // Full entity-level copy will be implemented when needed.
571        Ok(())
572    }
573
574    // === Internal Helpers ===
575
576    pub(super) fn get_or_create_label_id(&self, label: &str) -> u32 {
577        {
578            let label_to_id = self.label_to_id.read();
579            if let Some(&id) = label_to_id.get(label) {
580                return id;
581            }
582        }
583
584        let mut label_to_id = self.label_to_id.write();
585        let mut id_to_label = self.id_to_label.write();
586
587        // Double-check after acquiring write lock
588        if let Some(&id) = label_to_id.get(label) {
589            return id;
590        }
591
592        let id = id_to_label.len() as u32;
593
594        let label: ArcStr = label.into();
595        label_to_id.insert(label.clone(), id);
596        id_to_label.push(label);
597
598        id
599    }
600
601    pub(super) fn get_or_create_edge_type_id(&self, edge_type: &str) -> u32 {
602        {
603            let type_to_id = self.edge_type_to_id.read();
604            if let Some(&id) = type_to_id.get(edge_type) {
605                return id;
606            }
607        }
608
609        let mut type_to_id = self.edge_type_to_id.write();
610        let mut id_to_type = self.id_to_edge_type.write();
611
612        // Double-check
613        if let Some(&id) = type_to_id.get(edge_type) {
614            return id;
615        }
616
617        let id = id_to_type.len() as u32;
618        let edge_type: ArcStr = edge_type.into();
619        type_to_id.insert(edge_type.clone(), id);
620        id_to_type.push(edge_type);
621
622        // Grow edge type live counts to match
623        let mut counts = self.edge_type_live_counts.write();
624        while counts.len() <= id as usize {
625            counts.push(0);
626        }
627
628        id
629    }
630
631    /// Increments the live edge count for a given edge type.
632    pub(super) fn increment_edge_type_count(&self, type_id: u32) {
633        let mut counts = self.edge_type_live_counts.write();
634        if counts.len() <= type_id as usize {
635            counts.resize(type_id as usize + 1, 0);
636        }
637        counts[type_id as usize] += 1;
638    }
639
640    /// Decrements the live edge count for a given edge type.
641    pub(super) fn decrement_edge_type_count(&self, type_id: u32) {
642        let mut counts = self.edge_type_live_counts.write();
643        if type_id < counts.len() as u32 {
644            counts[type_id as usize] -= 1;
645        }
646    }
647}
648
649impl Default for LpgStore {
650    fn default() -> Self {
651        Self::new().expect("failed to allocate arena for default LpgStore")
652    }
653}