#include "tifa_config.h"
#include <inttypes.h>
#include "bitstring_t.h"
Go to the source code of this file.
Data Structures | |
struct | struct_binary_matrix_t |
Defines a matrix of bits. More... | |
struct | struct_byte_matrix_t |
Defines a matrix of bytes. More... | |
Defines | |
#define | _TIFA_MATRIX_H_ |
#define | NO_SUCH_ROW UINT32_MAX |
Typedefs | |
typedef struct struct_binary_matrix_t | binary_matrix_t |
Equivalent to struct struct_binary_matrix_t . | |
typedef struct struct_byte_matrix_t | byte_matrix_t |
Equivalent to struct struct_byte_matrix_t . | |
Functions | |
binary_matrix_t * | alloc_binary_matrix (uint32_t nrows, uint32_t ncols) |
Allocates and returns a new binary_matrix_t . | |
binary_matrix_t * | clone_binary_matrix (const binary_matrix_t *const matrix) |
Allocates and returns a cloned binary_matrix_t . | |
void | reset_binary_matrix (binary_matrix_t *const matrix) |
Sets a binary_matrix_t to zero. | |
void | free_binary_matrix (binary_matrix_t *const matrix) |
Clears a binary_matrix_t . | |
void | print_binary_matrix (const binary_matrix_t *const matrix) |
Prints a binary_matrix_t . | |
static uint8_t | get_matrix_bit (uint32_t row, uint32_t col, const binary_matrix_t *const matrix) |
Returns the value of a given bit in a binary_matrix_t . | |
static void | set_matrix_bit_to_one (uint32_t row, uint32_t col, binary_matrix_t *const matrix) |
Sets to one the value of a given bit in a binary_matrix_t . | |
static void | set_matrix_bit_to_zero (uint32_t row, uint32_t col, binary_matrix_t *const matrix) |
Sets to zero the value of a given bit in a binary_matrix_t . | |
static void | flip_matrix_bit (uint32_t row, uint32_t col, binary_matrix_t *const matrix) |
Flips the value of a given bit in a binary_matrix_t . | |
static uint32_t | first_row_with_one_on_col (uint32_t col, const binary_matrix_t *const matrix) |
Returns the index of the first row of a binary_matrix_t with a one in a given column. | |
byte_matrix_t * | alloc_byte_matrix (uint32_t nrows, uint32_t ncols) |
Allocates and returns a new byte_matrix_t . | |
byte_matrix_t * | clone_byte_matrix (const byte_matrix_t *const matrix) |
Allocates and returns a cloned byte_matrix_t . | |
void | reset_byte_matrix (byte_matrix_t *const matrix) |
Sets a byte_matrix_t to zero. | |
void | free_byte_matrix (byte_matrix_t *const matrix) |
Clears a byte_matrix_t . | |
void | print_byte_matrix (const byte_matrix_t *const matrix) |
Prints a byte_matrix_t . |
Definition in file matrix.h.
#define NO_SUCH_ROW UINT32_MAX |
Value returned by the first_row_with_one_on_col(col, matrix)
function if no row of the matrix has a bit 1 in its col-th
column.
Definition at line 53 of file matrix.h.
Referenced by first_row_with_one_on_col().
binary_matrix_t* alloc_binary_matrix | ( | uint32_t | nrows, | |
uint32_t | ncols | |||
) |
Allocates and returns a new binary_matrix_t
.
Allocates and returns a new binary_matrix_t
such that:
nrows_alloced
field is set to nrows. ncols_alloced
field is set to the minimum number of TIFA_BITSTRING_T
integers needed to store ncols bits. nrows
field is set to nrows. ncols
field is set to ncols. data
array of arrays is completely filled with zeroes.[in] | nrows | The maximum number of rows of the binary_matrix_t to allocate. |
[in] | ncols | The maximum number of bits per row of the binary_matrix_t to allocate. |
binary_matrix_t
structure. Note that this matrix may hold more that ncols
bits per column if ncols
is not a multiple of 8 * sizeof(TIFA_BITSTRING_T)
. byte_matrix_t* alloc_byte_matrix | ( | uint32_t | nrows, | |
uint32_t | ncols | |||
) |
Allocates and returns a new byte_matrix_t
.
Allocates and returns a new byte_matrix_t
such that:
nrows_alloced
field is set to nrows. ncols_alloced
field is set to ncols. nrows
field is set to nrows. ncols
field is set to ncols. data
array of arrays is completely filled with zeroes.[in] | nrows | The maximum number of rows of the byte_matrix_t to allocate. |
[in] | ncols | The maximum number of columns byte_matrix_t to allocate. |
byte_matrix_t
structure. binary_matrix_t* clone_binary_matrix | ( | const binary_matrix_t *const | matrix | ) |
Allocates and returns a cloned binary_matrix_t
.
Allocates and returns a clone of the binary_matrix_t
pointed by matrix
.
[in] | matrix | A pointer to the binary matrix to clone. |
binary_matrix_t
clone. byte_matrix_t* clone_byte_matrix | ( | const byte_matrix_t *const | matrix | ) |
Allocates and returns a cloned byte_matrix_t
.
Allocates and returns a clone of the byte_matrix_t
pointed by matrix
.
[in] | matrix | A pointer to the byte matrix to clone. |
byte_matrix_t
clone. static uint32_t first_row_with_one_on_col | ( | uint32_t | col, | |
const binary_matrix_t *const | matrix | |||
) | [inline, static] |
Returns the index of the first row of a binary_matrix_t
with a one in a given column.
Returns the index of the first row of a binary_matrix_t
which has a one on its col
-th column. It returns NO_SUCH_ROW if no such row is found.
[in] | col | The column of the matrix. |
[in] | matrix | A pointer to the binary_matrix_t . |
row
between 0 and matrix->nrows
-1 such that (matrix->data[row][col] == 1)
i
, (matrix->data[i][col] != 1)
.first_row_with_one_on_col
exactly as in matrix.c
, but the future maintainer would have the burden to check and update code scattered around several files should the inner structure of binary_matrix_t
be modified.This can be seen as a moot point: after all, the TIFA code does not strictly enforce type encapsulation. Indeed, some parts of the code do assume (a minimal!) knowledge of the internal structures of some types (have a look at siqs.c for instance). That does not make it the right thing to do though. Unless when facing a real bottleneck, let's try to keep the "programmer's omniscience" to a manageable level...
Definition at line 316 of file matrix.h.
References struct_binary_matrix_t::data, NO_SUCH_ROW, and struct_binary_matrix_t::nrows.
static void flip_matrix_bit | ( | uint32_t | row, | |
uint32_t | col, | |||
binary_matrix_t *const | matrix | |||
) | [inline, static] |
Flips the value of a given bit in a binary_matrix_t
.
Flips the value of the bit at the row
-th row and the col
-th column of the binary_array_t
pointed by array
.
[in] | row | The row of the bit to flip. |
[in] | col | The column of the bit to flip. |
[in] | matrix | A pointer to the binary_matrix_t . |
Definition at line 265 of file matrix.h.
References struct_binary_matrix_t::data.
void free_binary_matrix | ( | binary_matrix_t *const | matrix | ) |
Clears a binary_matrix_t
.
Clears a binary_matrix_t
, or, more precisely, clears the memory space used by the arrays pointed by the data
field of a binary_matrix_t
. Also set its nrows_alloced
, ncols_alloced
, nrows
and ncols
fields to zero.
[in] | matrix | A pointer to the binary_matrix_t to clear. |
void free_byte_matrix | ( | byte_matrix_t *const | matrix | ) |
Clears a byte_matrix_t
.
Clears a byte_matrix_t
, or, more precisely, clears the memory space used by the arrays pointed by the data
field of a byte_matrix_t
. Also set its nrows_alloced
, ncols_alloced
, nrows
and ncols
fields to zero.
[in] | matrix | A pointer to the byte_matrix_t to clear. |
static uint8_t get_matrix_bit | ( | uint32_t | row, | |
uint32_t | col, | |||
const binary_matrix_t *const | matrix | |||
) | [inline, static] |
Returns the value of a given bit in a binary_matrix_t
.
Returns the value of the bit at the row
-th row and the col
-th column of the binary_array_t
pointed by array
, as either 0 or 1.
[in] | row | The row of the bit to read. |
[in] | col | The column of the bit to read. |
[in] | matrix | A pointer to the binary_matrix_t . |
row
,col
) position: either 0 or 1. Definition at line 186 of file matrix.h.
References struct_binary_matrix_t::data.
void print_binary_matrix | ( | const binary_matrix_t *const | matrix | ) |
Prints a binary_matrix_t
.
Prints a binary_matrix_t
's on the standard output.
[in] | matrix | A pointer to the binary_matrix_t to print. |
void print_byte_matrix | ( | const byte_matrix_t *const | matrix | ) |
Prints a byte_matrix_t
.
Prints a byte_matrix_t
's on the standard output.
[in] | matrix | A pointer to the byte_matrix_t to print. |
void reset_binary_matrix | ( | binary_matrix_t *const | matrix | ) |
Sets a binary_matrix_t
to zero.
Sets the binary_matrix_t matrix
to the zero matrix.
[in] | matrix | A pointer to the binary_matrix_t to reset. |
void reset_byte_matrix | ( | byte_matrix_t *const | matrix | ) |
Sets a byte_matrix_t
to zero.
Sets the byte_matrix_t matrix
to the zero matrix.
[in] | matrix | A pointer to the byte_matrix_t to reset. |
static void set_matrix_bit_to_one | ( | uint32_t | row, | |
uint32_t | col, | |||
binary_matrix_t *const | matrix | |||
) | [inline, static] |
Sets to one the value of a given bit in a binary_matrix_t
.
Sets to one the value of the bit at the row
-th row and the col
-th column of the binary_array_t
pointed by array
.
[in] | row | The row of the bit to set. |
[in] | col | The column of the bit to set. |
[in] | matrix | A pointer to the binary_matrix_t . |
Definition at line 214 of file matrix.h.
References struct_binary_matrix_t::data.
static void set_matrix_bit_to_zero | ( | uint32_t | row, | |
uint32_t | col, | |||
binary_matrix_t *const | matrix | |||
) | [inline, static] |
Sets to zero the value of a given bit in a binary_matrix_t
.
Sets to zero the value of the bit at the row
-th row and the col
-th column of the binary_array_t
pointed by array
.
[in] | row | The row of the bit to set. |
[in] | col | The column of the bit to set. |
[in] | matrix | A pointer to the binary_matrix_t . |
Definition at line 240 of file matrix.h.
References struct_binary_matrix_t::data.