Skip to main content

Module cache

Module cache 

Source
Expand description

Per-graph property cache (ALGO-CORE-001f).

Counterpart of igraph_i_property_cache_t from references/igraph/src/graph/caching.{h,c} and the igraph_i_property_cache_* developer-facing API in references/igraph/include/igraph_interface.h:89-94.

Stores the value of a small set of boolean graph properties (e.g. is_dag, is_forest, has_loop) so that repeated calls don’t recompute. The cache lives on Graph itself and is invalidated on any structural mutation; selective invalidation (e.g. adding an edge cannot make a connected graph disconnected) mirrors upstream’s igraph_i_property_cache_invalidate_conditionally.

§Interior mutability

igraph C updates the cache through a const igraph_t * pointer — computing a property is not considered “modification” of the graph. We mirror this with Cell<u32>: a property compute function takes &Graph and may still populate the cache. Single-threaded for now; future multi-thread support would swap to AtomicU32.

§Storage layout

Two u32s, bit i corresponding to CachedProperty discriminant i:

  • known — bit set iff property i has a cached value;
  • values — bit set iff cached value of i is true.

Reading values is only meaningful when the matching known bit is set; get therefore returns Option<bool> rather than a raw pair. This matches the C struct in references/igraph/src/graph/caching.h:29-34 exactly (one bit per property in known, one byte per property in C value[] — we bit-pack since Rust gives us free integer arithmetic).

Enums§

CachedProperty
The set of boolean graph properties that may be cached.