/*
Copyright (C) 2019-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/
/*
WARNING: This file was generated by the dkct program (see
http://dktools.sourceforge.net/ for details).
Changes you make here will be lost if dkct is run again!
You should modify the original source and run dkct on it.
Original source: dk4bm.ctr
*/
#ifndef DK4BM_H_INCLUDED
/** Avoid multiple inclusions. */
#define DK4BM_H_INCLUDED 1
#line 9 "dk4bm.ctr"
/** @file dk4bm.h Bit matrix.
Among other things a bit matrix can be used to represent a directed
graph. A 1-bit in row i column j indicates a directed
edge from i to j (row number represents source node,
column number represents destination node).
Alternatively you may choose reverse representation:
A 1-bit in row i column j indicates a directed edge from j
to i (row number represents destination node number, column number
represents source node number).
In a dependency graph it means: i depends on j.
After expanding the matrix you can check whether or not there is a path
from any node to any other, either direct or
indirect (path consisting of a sequence of direct edges).
*/
#ifndef DK4CONF_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4conf.h"
#else
#include
#endif
#endif
#ifndef DK4ERROR_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4error.h"
#else
#include
#endif
#endif
/** Bit matrix structure.
*/
typedef struct {
unsigned char **data; /**< Bits grouped in bytes. */
size_t rows; /**< Number of rows. */
size_t columns; /**< Number of columns. */
size_t bytes_per_row; /**< Bytes per row. */
} dk4_bit_matrix_t;
#ifdef __cplusplus
extern "C" {
#endif
/** Open bit matrix.
CRT on Windows: Optional.
@param rows Number of rows.
@param columns Number of columns.
@param erp Error report, may be NULL.
@return Valid pointer on success, NULL on error.
Use dk4bm_close() to close the bit matrix when done with it.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if the number of rows or columns is 0,
- DK4_E_MATH_OVERFLOW
if a numeric overflow occurs in size calculation (number of rows and/or
columns too large),
- DK4_E_MEMORY_ALLOCATION_FAILED
if not enough memory available.
*/
dk4_bit_matrix_t *
dk4bm_open(
size_t rows,
size_t columns,
dk4_er_t *erp
);
/** Create a full copy of a bit matrix as new bit matrix.
CRT on Windows: Optional.
@param psrc Source bit matrix.
@param erp Error report, may be NULL.
@return Valid pointer on success, NULL on error.
Use dk4bm_close() to close the bit matrix when done with it.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if a NULL pointer is passed as psrc or the row or column number
in psrc is 0,
- DK4_E_MATH_OVERFLOW
if a numeric overflow occurs in size calculation (number of rows and/or
columns too large),
- DK4_E_MEMORY_ALLOCATION_FAILED
if not enough memory available.
*/
dk4_bit_matrix_t *
dk4bm_open_copy(
dk4_bit_matrix_t const *psrc,
dk4_er_t *erp
);
/** Set one bit in matrix.
CRT on Windows: Optional.
@param pmb Bit matrix to modify.
@param row Row position to modify.
@param column Column position to modify.
@param value Value (non-zero to set bit, 0 to reset bit).
@param erp Error report, may be NULL.
@return 1 on success, 0 on error.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if pmb is NULL or the row/column specification is out of range.
*/
int
dk4bm_set(
dk4_bit_matrix_t *pmb,
size_t row,
size_t column,
int value,
dk4_er_t *erp
);
/** Get bit value from matrix.
CRT on Windows: Optional.
@param pdest Address of destination variable, set to 1 or 0.
@param pmb Bit matrix to retrieve bit from.
@param row Row position of bit to find.
@param column Column position of bit to find.
@param erp Error report, may be NULL.
@return 1 on success, 0 on error.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if pdest or pmb is NULL or the row/column specification is out of range.
*/
int
dk4bm_get(
int *pdest,
dk4_bit_matrix_t const *pmb,
size_t row,
size_t column,
dk4_er_t *erp
);
/** Expand bit matrix.
CRT on Windows: Optional.
@param pmb Bit matrix to expand.
@param erp Error report, may be NULL.
@return 1 on success, 0 on error.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if pmb is NULL or not a square matrix.
*/
int
dk4bm_expand(
dk4_bit_matrix_t *pmb,
dk4_er_t *erp
);
/** Close bit matrix, release resources.
CRT on Windows: Optional.
@param pbm Bit matrix to close.
@param san Flag: Sanitize memory.
*/
void
dk4bm_close(
dk4_bit_matrix_t *pbm,
int san
);
#ifdef __cplusplus
}
#endif
#endif