ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Circuit< gateType > Class Template Referenceabstract

Generic template base class for provenance circuits. More...

#include "Circuit.h"

Public Types

using uuid = std::string
 UUID type used in this circuit (always std::string).
 

Public Member Functions

virtual ~Circuit ()
 
std::vector< gate_t >::size_type getNbGates () const
 Return the total number of gates in the circuit.
 
gate_t getGate (const uuid &u)
 Return (or create) the gate associated with UUID u.
 
uuid getUUID (gate_t g) const
 Return the UUID string associated with gate g.
 
gateType getGateType (gate_t g) const
 Return the type of gate g.
 
std::vector< gate_t > & getWires (gate_t g)
 Return a mutable reference to the child-wire list of gate g.
 
const std::vector< gate_t > & getWires (gate_t g) const
 Return a const reference to the child-wire list of gate g.
 
virtual gate_t setGate (const uuid &u, gateType type)
 Create or update the gate associated with UUID u.
 
virtual gate_t setGate (gateType type)
 Allocate a new gate with type type and no UUID.
 
bool hasGate (const uuid &u) const
 Test whether a gate with UUID u exists.
 
void addWire (gate_t f, gate_t t)
 Add a directed wire from gate f (parent) to gate t (child).
 
virtual std::string toString (gate_t g) const =0
 Return a textual description of gate g for debugging.
 

Protected Member Functions

void setGateType (gate_t g, gateType t)
 Update the type of an existing gate.
 
virtual gate_t addGate ()
 Allocate a new gate with a default-initialised type.
 

Protected Attributes

std::unordered_map< uuid, gate_tuuid2id
 UUID string → gate index.
 
std::unordered_map< gate_t, uuidid2uuid
 Gate index → UUID string.
 
std::vector< gateType > gates
 Gate type for each gate.
 
std::vector< std::vector< gate_t > > wires
 Child wire lists for each gate.
 

Detailed Description

template<class gateType>
class Circuit< gateType >

Generic template base class for provenance circuits.

A Circuit stores:

  • A vector of gate types indexed by gate_t.
  • A vector of child-wire lists (also indexed by gate_t).
  • Bidirectional maps between gate UUIDs (strings) and gate_t IDs.
Template Parameters
gateTypeEnumeration of gate kinds for this circuit variant.

Definition at line 61 of file Circuit.h.

Member Typedef Documentation

◆ uuid

template<class gateType >
using Circuit< gateType >::uuid = std::string

UUID type used in this circuit (always std::string).

Definition at line 64 of file Circuit.h.

Constructor & Destructor Documentation

◆ ~Circuit()

template<class gateType >
virtual Circuit< gateType >::~Circuit ( )
inlinevirtual

Definition at line 95 of file Circuit.h.

Member Function Documentation

◆ addGate()

template<class gateType >
gate_t Circuit< gateType >::addGate ( )
protectedvirtual

Allocate a new gate with a default-initialised type.

Derived classes override this to perform additional initialisation (e.g. resizing auxiliary vectors).

Returns
The gate_t identifier of the newly created gate.

Reimplemented in BooleanCircuit, DotCircuit, and GenericCircuit.

Definition at line 56 of file Circuit.hpp.

Here is the caller graph for this function:

◆ addWire()

template<class gateType >
void Circuit< gateType >::addWire ( gate_t  f,
gate_t  t 
)

Add a directed wire from gate f (parent) to gate t (child).

Parameters
fSource (parent) gate.
tTarget (child) gate.

Definition at line 81 of file Circuit.hpp.

Here is the caller graph for this function:

◆ getGate()

template<class gateType >
gate_t Circuit< gateType >::getGate ( const uuid u)

Return (or create) the gate associated with UUID u.

If no gate with this UUID exists yet a new gate is allocated via addGate() and the UUID mapping is recorded.

Parameters
uUUID string.
Returns
Gate identifier for u.

Definition at line 33 of file Circuit.hpp.

Here is the caller graph for this function:

◆ getGateType()

template<class gateType >
gateType Circuit< gateType >::getGateType ( gate_t  g) const
inline

Return the type of gate g.

Parameters
gGate identifier.
Returns
The gate's type.

Definition at line 129 of file Circuit.h.

Here is the caller graph for this function:

◆ getNbGates()

template<class gateType >
std::vector< gate_t >::size_type Circuit< gateType >::getNbGates ( ) const
inline

Return the total number of gates in the circuit.

Returns
Number of gates.

Definition at line 102 of file Circuit.h.

Here is the caller graph for this function:

◆ getUUID()

template<class gateType >
Circuit< gateType >::uuid Circuit< gateType >::getUUID ( gate_t  g) const

Return the UUID string associated with gate g.

Parameters
gGate identifier.
Returns
UUID string, or empty if g has no UUID.

Definition at line 46 of file Circuit.hpp.

Here is the caller graph for this function:

◆ getWires() [1/2]

template<class gateType >
std::vector< gate_t > & Circuit< gateType >::getWires ( gate_t  g)
inline

Return a mutable reference to the child-wire list of gate g.

Parameters
gGate identifier.
Returns
Reference to the vector of child gate IDs.

Definition at line 139 of file Circuit.h.

Here is the caller graph for this function:

◆ getWires() [2/2]

template<class gateType >
const std::vector< gate_t > & Circuit< gateType >::getWires ( gate_t  g) const
inline

Return a const reference to the child-wire list of gate g.

Parameters
gGate identifier.
Returns
Const reference to the vector of child gate IDs.

Definition at line 149 of file Circuit.h.

◆ hasGate()

template<class gateType >
bool Circuit< gateType >::hasGate ( const uuid u) const

Test whether a gate with UUID u exists.

Parameters
uUUID string.
Returns
true if a gate with this UUID is present.

Definition at line 27 of file Circuit.hpp.

Here is the caller graph for this function:

◆ setGate() [1/2]

template<class gateType >
gate_t Circuit< gateType >::setGate ( const uuid u,
gateType  type 
)
virtual

Create or update the gate associated with UUID u.

If the UUID is already mapped the existing gate's type is updated. Otherwise a new gate is allocated.

Parameters
uUUID string to associate with the gate.
typeGate type.
Returns
Gate identifier.

Reimplemented in DotCircuit.

Definition at line 73 of file Circuit.hpp.

Here is the caller graph for this function:

◆ setGate() [2/2]

template<class gateType >
gate_t Circuit< gateType >::setGate ( gateType  type)
virtual

Allocate a new gate with type type and no UUID.

Parameters
typeGate type.
Returns
Gate identifier.

Reimplemented in DotCircuit.

Definition at line 65 of file Circuit.hpp.

◆ setGateType()

template<class gateType >
void Circuit< gateType >::setGateType ( gate_t  g,
gateType  t 
)
inlineprotected

Update the type of an existing gate.

Parameters
gGate to update.
tNew gate type.

Definition at line 78 of file Circuit.h.

Here is the caller graph for this function:

◆ toString()

template<class gateType >
virtual std::string Circuit< gateType >::toString ( gate_t  g) const
pure virtual

Return a textual description of gate g for debugging.

Pure virtual; each concrete circuit class provides its own formatting.

Parameters
gGate to describe.
Returns
Human-readable string.

Implemented in BooleanCircuit, DotCircuit, GenericCircuit, and WhereCircuit.

Member Data Documentation

◆ gates

template<class gateType >
std::vector<gateType> Circuit< gateType >::gates
protected

Gate type for each gate.

Definition at line 70 of file Circuit.h.

◆ id2uuid

template<class gateType >
std::unordered_map<gate_t, uuid> Circuit< gateType >::id2uuid
protected

Gate index → UUID string.

Definition at line 68 of file Circuit.h.

◆ uuid2id

template<class gateType >
std::unordered_map<uuid, gate_t> Circuit< gateType >::uuid2id
protected

UUID string → gate index.

Definition at line 67 of file Circuit.h.

◆ wires

template<class gateType >
std::vector<std::vector<gate_t> > Circuit< gateType >::wires
protected

Child wire lists for each gate.

Definition at line 71 of file Circuit.h.


The documentation for this class was generated from the following files: