ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
circuit_cache.h
Go to the documentation of this file.
1/**
2 * @file circuit_cache.h
3 * @brief C-linkage interface to the in-process provenance circuit cache.
4 *
5 * The circuit cache is a bounded, LRU-evicting in-memory store that
6 * avoids repeated round-trips to the mmap-backed persistent circuit
7 * storage for recently accessed gates. It is implemented in C++ (see
8 * @c CircuitCache.h / @c CircuitCache.cpp) but exposed to the C parts of
9 * the extension through this header.
10 *
11 * Gates evicted from the cache are flushed to the background mmap worker
12 * via the shared-memory pipe. Lookups that miss the cache fall back to
13 * reading the mmap files directly.
14 */
15#ifndef CIRCUIT_CACHE_H
16#define CIRCUIT_CACHE_H
17
18#include "provsql_utils.h"
19
20/**
21 * @brief Insert a new gate into the circuit cache.
22 *
23 * Records the gate identified by @p token with the given @p type and
24 * @p nb_children children. If the cache is full the oldest entry is
25 * evicted (and flushed to persistent storage) to make room.
26 *
27 * @param token UUID identifying the new gate.
28 * @param type Gate type (e.g. @c gate_input, @c gate_plus).
29 * @param nb_children Number of child gates.
30 * @param children Array of @p nb_children child UUIDs.
31 * @return @c true if the gate was inserted, @c false if it was already
32 * present in the cache.
33 */
34bool circuit_cache_create_gate(pg_uuid_t token, gate_type type, unsigned nb_children, pg_uuid_t *children);
35
36/**
37 * @brief Retrieve the children of a cached gate.
38 *
39 * Looks up @p token in the cache and, on a hit, allocates an array of
40 * child UUIDs in the current memory context and writes its address to
41 * @p *children.
42 *
43 * @param token UUID of the gate to look up.
44 * @param children Output parameter: set to a freshly allocated array of
45 * child UUIDs on success; untouched on a cache miss.
46 * @return Number of children found, or @c UINT_MAX on a cache miss.
47 */
48unsigned circuit_cache_get_children(pg_uuid_t token, pg_uuid_t **children);
49
50/**
51 * @brief Retrieve the type of a cached gate.
52 *
53 * @param token UUID of the gate to look up.
54 * @return The @c gate_type of the gate, or @c gate_invalid on a miss.
55 */
57
58#endif /* CIRCUIT_CACHE_H */
gate_type circuit_cache_get_type(pg_uuid_t token)
Retrieve the type of a cached gate.
unsigned circuit_cache_get_children(pg_uuid_t token, pg_uuid_t **children)
Retrieve the children of a cached gate.
bool circuit_cache_create_gate(pg_uuid_t token, gate_type type, unsigned nb_children, pg_uuid_t *children)
Insert a new gate into the circuit cache.
Core types, constants, and utilities shared across ProvSQL.
gate_type
Possible gate type in the provenance circuit.
UUID structure.