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

 Circuit ()=default
 Circuit (const Circuit &)=default
 Circuit (Circuit &&)=default
Circuit & operator= (const Circuit &)=default
Circuit & operator= (Circuit &&)=default
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.
gate_t getGate (const gate_uuid &u)
 Return (or create) the gate associated with UUID u.
std::pair< gate_t, bool > findOrAddGate (const gate_uuid &u)
 Return (or create) the gate associated with UUID u, and whether it was created.
uuid getUUID (gate_t g) const
 Return the UUID string associated with gate g.
bool getUUID (gate_t g, gate_uuid &u) const
 Read the UUID of gate g into u.
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.
bool hasGate (const gate_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 Types

enum  : unsigned char { NO_NAME , UUID_NAME , OTHER_NAME }
 What a gate is named by, in name_kind. More...

Protected Member Functions

unsigned char nameKind (gate_t g) const
 What gate g is named by.
void bindName (gate_t g, const gate_uuid &u)
 Name gate g by the UUID u.
void bindName (gate_t g, const uuid &u)
 Name gate g by u, a UUID in its text form or another string.
void pointName (gate_t g, gate_t target)
 Make the name of gate g, if any, name gate target.
void dropName (gate_t g)
 Remove the name of gate g, if any.
void moveName (gate_t from, gate_t to)
 Give the name of gate from, if any, to gate to.
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< gate_uuid, gate_t, gate_uuid_hash > uuid2id
 UUID → gate index.
std::vector< gate_uuid > id2uuid
 UUID of each gate (if UUID_NAME).
std::vector< unsigned char > name_kind
 What each gate is named by.
std::unordered_map< std::string, gate_t > name2id
 Other name → gate index.
std::unordered_map< gate_t, std::string > id2name
 Gate index → other name.
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).
  • Maps between gate UUIDs and gate_t IDs.
Template Parameters
gateTypeEnumeration of gate kinds for this circuit variant.

Definition at line 172 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 175 of file Circuit.h.

Member Enumeration Documentation

◆ anonymous enum

template<class gateType>
anonymous enum : unsigned char
protected

What a gate is named by, in name_kind.

Enumerator
NO_NAME 

No name.

UUID_NAME 

A UUID, in id2uuid.

OTHER_NAME 

Another string, in id2name.

Definition at line 179 of file Circuit.h.

Constructor & Destructor Documentation

◆ Circuit() [1/3]

template<class gateType>
Circuit< gateType >::Circuit ( )
default
Here is the caller graph for this function:

◆ Circuit() [2/3]

template<class gateType>
Circuit< gateType >::Circuit ( const Circuit< gateType > & )
default
Here is the call graph for this function:

◆ Circuit() [3/3]

template<class gateType>
Circuit< gateType >::Circuit ( Circuit< gateType > && )
default
Here is the call graph for this function:

◆ ~Circuit()

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

Definition at line 245 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 168 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 195 of file Circuit.hpp.

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

◆ bindName() [1/2]

template<class gateType>
void Circuit< gateType >::bindName ( gate_t g,
const gate_uuid & u )
protected

Name gate g by the UUID u.

Definition at line 78 of file Circuit.hpp.

Here is the caller graph for this function:

◆ bindName() [2/2]

template<class gateType>
void Circuit< gateType >::bindName ( gate_t g,
const uuid & u )
protected

Name gate g by u, a UUID in its text form or another string.

Definition at line 93 of file Circuit.hpp.

Here is the call graph for this function:

◆ dropName()

template<class gateType>
void Circuit< gateType >::dropName ( gate_t g)
protected

Remove the name of gate g, if any.

Definition at line 127 of file Circuit.hpp.

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

◆ findOrAddGate()

template<class gateType>
std::pair< gate_t, bool > Circuit< gateType >::findOrAddGate ( const gate_uuid & u)

Return (or create) the gate associated with UUID u, and whether it was created.

Definition at line 39 of file Circuit.hpp.

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

◆ getGate() [1/2]

template<class gateType>
gate_t Circuit< gateType >::getGate ( const gate_uuid & u)
inline

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 268 of file Circuit.h.

Here is the call graph for this function:

◆ getGate() [2/2]

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 50 of file Circuit.hpp.

Here is the call graph for this function:
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 301 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 252 of file Circuit.h.

Here is the caller graph for this function:

◆ getUUID() [1/2]

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 65 of file Circuit.hpp.

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

◆ getUUID() [2/2]

template<class gateType>
bool Circuit< gateType >::getUUID ( gate_t g,
gate_uuid & u ) const
inline

Read the UUID of gate g into u.

Returns
false if g is not named by a UUID.

Definition at line 289 of file Circuit.h.

Here is the call 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 311 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 321 of file Circuit.h.

◆ hasGate() [1/2]

template<class gateType>
bool Circuit< gateType >::hasGate ( const gate_uuid & u) const
inline

Test whether a gate with UUID u exists.

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

Definition at line 353 of file Circuit.h.

◆ hasGate() [2/2]

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 30 of file Circuit.hpp.

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

◆ moveName()

template<class gateType>
void Circuit< gateType >::moveName ( gate_t from,
gate_t to )
protected

Give the name of gate from, if any, to gate to.

Definition at line 145 of file Circuit.hpp.

Here is the call graph for this function:

◆ nameKind()

template<class gateType>
unsigned char Circuit< gateType >::nameKind ( gate_t g) const
inlineprotected

What gate g is named by.

Definition at line 195 of file Circuit.h.

Here is the caller graph for this function:

◆ operator=() [1/2]

template<class gateType>
Circuit & Circuit< gateType >::operator= ( Circuit< gateType > && )
default
Here is the call graph for this function:

◆ operator=() [2/2]

template<class gateType>
Circuit & Circuit< gateType >::operator= ( const Circuit< gateType > & )
default
Here is the call graph for this function:

◆ pointName()

template<class gateType>
void Circuit< gateType >::pointName ( gate_t g,
gate_t target )
protected

Make the name of gate g, if any, name gate target.

Definition at line 111 of file Circuit.hpp.

Here is the call 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 187 of file Circuit.hpp.

Here is the call graph for this function:
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.

Definition at line 179 of file Circuit.hpp.

Here is the call graph for this function:

◆ 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 223 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 215 of file Circuit.h.

◆ id2name

template<class gateType>
std::unordered_map<gate_t, std::string> Circuit< gateType >::id2name
protected

Gate index → other name.

Definition at line 192 of file Circuit.h.

◆ id2uuid

template<class gateType>
std::vector<gate_uuid> Circuit< gateType >::id2uuid
protected

UUID of each gate (if UUID_NAME).

Definition at line 189 of file Circuit.h.

◆ name2id

template<class gateType>
std::unordered_map<std::string, gate_t> Circuit< gateType >::name2id
protected

Other name → gate index.

Definition at line 191 of file Circuit.h.

◆ name_kind

template<class gateType>
std::vector<unsigned char> Circuit< gateType >::name_kind
protected

What each gate is named by.

Definition at line 190 of file Circuit.h.

◆ uuid2id

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

UUID → gate index.

Definition at line 188 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 216 of file Circuit.h.


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