ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
CircuitCache.cpp File Reference

LRU circuit-gate cache implementation and C-linkage wrappers. More...

#include <src/CircuitCache.h>
#include "circuit_cache.h"
Include dependency graph for CircuitCache.cpp:

Go to the source code of this file.

Functions

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.
 
unsigned circuit_cache_get_children (pg_uuid_t token, pg_uuid_t **children)
 Retrieve the children of a cached gate.
 
gate_type circuit_cache_get_type (pg_uuid_t token)
 Retrieve the type of a cached gate.
 

Variables

constexpr unsigned MAX_CIRCUIT_CACHE_SIZE = 1 << 20
 Maximum total byte size of the in-process circuit gate cache (1 MiB).
 
static CircuitCache cache
 Process-local singleton circuit gate cache.
 

Detailed Description

LRU circuit-gate cache implementation and C-linkage wrappers.

Implements CircuitCache::insert() and CircuitCache::get(), and the three C-linkage wrapper functions declared in circuit_cache.h:

The cache is a process-local Boost multi-index container bounded by MAX_CIRCUIT_CACHE_SIZE bytes. On overflow, the oldest (FIFO) entry is evicted. The C wrappers manage a singleton CircuitCache instance and translate between pg_uuid_t / gate_type (C types) and the C++ CircuitCacheInfos structure.

Definition in file CircuitCache.cpp.

Function Documentation

◆ circuit_cache_create_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.

Records the gate identified by token with the given type and nb_children children. If the cache is full the oldest entry is evicted (and flushed to persistent storage) to make room.

Parameters
tokenUUID identifying the new gate.
typeGate type (e.g. gate_input, gate_plus).
nb_childrenNumber of child gates.
childrenArray of nb_children child UUIDs.
Returns
true if the gate was inserted, false if it was already present in the cache.

Definition at line 55 of file CircuitCache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ circuit_cache_get_children()

unsigned circuit_cache_get_children ( pg_uuid_t  token,
pg_uuid_t **  children 
)

Retrieve the children of a cached gate.

Looks up token in the cache and, on a hit, allocates an array of child UUIDs in the current memory context and writes its address to *children.

Parameters
tokenUUID of the gate to look up.
childrenOutput parameter: set to a freshly allocated array of child UUIDs on success; untouched on a cache miss.
Returns
Number of children found, or UINT_MAX on a cache miss.

Definition at line 60 of file CircuitCache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ circuit_cache_get_type()

gate_type circuit_cache_get_type ( pg_uuid_t  token)

Retrieve the type of a cached gate.

Parameters
tokenUUID of the gate to look up.
Returns
The gate_type of the gate, or gate_invalid on a miss.

Definition at line 76 of file CircuitCache.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cache

CircuitCache cache
static

Process-local singleton circuit gate cache.

Definition at line 53 of file CircuitCache.cpp.

◆ MAX_CIRCUIT_CACHE_SIZE

constexpr unsigned MAX_CIRCUIT_CACHE_SIZE = 1 << 20
constexpr

Maximum total byte size of the in-process circuit gate cache (1 MiB).

Definition at line 24 of file CircuitCache.cpp.