API Reference¶
Note
The full README is available on GitHub.
Enums
Functions
-
gate_t *gate_new(gate_kind_t kind, unsigned n)¶
Creates a new gate of the specified type with
n
inputs.- Parameters:
kind – The type of gate to create (e.g.
NAND
,AND
,OR
).n – The number of inputs for the gate.
- Returns:
Pointer to the created gate structure on success.
NULL
if memory allocation fails (errno
is set toENOMEM
).
-
void gate_delete(gate_t *g)¶
Deletes the specified gate.
Disconnects all input and output signals from the gate and frees its allocated memory. Does nothing if
g
isNULL
. After deletion, the pointerg
becomes invalid.- Parameters:
g – Pointer to the gate to delete.
-
int gate_connect_gate(gate_t *g_out, gate_t *g_in, unsigned k)¶
Connects the output of one gate to the input of another gate.
Connects the output of
g_out
to thek
-th input ofg_in
. Any signal previously connected to thek
-th input ofg_in
will be disconnected.- Parameters:
g_out – Pointer to the output gate.
g_in – Pointer to the input gate.
k – Index of the input in
g_in
to connect.
- Returns:
0 on success.
-1 if any pointer is
NULL
,k
is invalid, or memory allocation fails (errno
is set toEINVAL
orENOMEM
).
-
int gate_connect_signal(bool const *s, gate_t *g, unsigned k)¶
Connects a boolean signal to the input of a gate.
Connects a boolean signal
s
to thek
-th input of gateg
. Any signal previously connected to thek
-th input will be disconnected.- Parameters:
s – Pointer to the constant boolean signal.
g – Pointer to the gate.
k – Index of the input in
g
to connect.
- Returns:
0 on success.
-1 if any pointer is
NULL
,k
is invalid, or memory allocation fails (errno
is set toEINVAL
orENOMEM
).
-
ssize_t gate_evaluate(gate_t **g, bool *s, size_t m)¶
Evaluates the output signals of the specified gates and calculates the critical path length.
Computes the output signals of the gates in
g
and stores them in thes
array. Also calculates the maximum critical path length for the given gates.- Parameters:
g – Array of pointers to gates.
s – Array to store the output signals of the gates.
m – Size of the
g
ands
arrays.
- Returns:
Critical path length on success (also populates the
s
array). s[i] contains the value of the signal at the output of the gate pointed to by g[i].-1 if any pointer is
NULL
,m
is zero, operation failed or memory allocation fails (errno
is set toEINVAL
,ECANCELED
, orENOMEM
).
-
ssize_t gate_fan_out(gate_t const *g)¶
Returns the fan-out of the specified gate.
Calculates the number of inputs in other gates connected to the output of the given gate.
- Parameters:
g – Pointer to the gate.
- Returns:
The number of connected inputs on success.
-1 if
g
isNULL
(errno
is set toEINVAL
).
-
ssize_t gate_fan_in(gate_t const *g)¶
Returns the fan-in of the specified gate.
- Parameters:
g – Pointer to the gate.
- Returns:
The number of inputs of the gate.
-1 if
g
isNULL
(errno
is set toEINVAL
).
-
void *gate_input(gate_t const *g, unsigned k)¶
Retrieves the signal or gate connected to a specific input.
Returns a pointer to the boolean signal or gate connected to the
k
-th input of the gateg
. ReturnsNULL
if nothing is connected to the input.- Parameters:
g – Pointer to the gate.
k – Index of the input.
- Returns:
Pointer to a
bool*
orgate_t*
on success.NULL
if no connection exists (errno is set to 0) =NULL
ifg
isNULL
, ork
is invalid (errno
is set toEINVAL
).
-
gate_t *gate_output(gate_t const *g, ssize_t k)¶
Retrieves a gate connected to the output of the specified gate.
- Parameters:
g – Pointer to the gate.
k – Index of the connection to retrieve (from 0 to
gate_fan_out(g) - 1
).
- Returns:
Pointer to the connected gate.
NULL
if parameters are invalid or the output is not connected to any gate.