MeatAxe  2.4
Bit-String Handling

Detailed Description

Bit strings can be written to and read from files.

The file format consists of a header followed by the data. The header contains three 32-bit integers. The first number is $-3$, the second number is the size of the bit string, and the third number is always zero. The file header is followed by the bit string data which is written as a sequence of 32-bit integers where bit 0 of the first integer contains the first bit of the string.

Data Structures

class  BitString_t
 A bit string. More...
 

Functions

int BsAnd (BitString_t *dest, const BitString_t *src)
 Intersection of two bit strings. More...
 
int BsIsValid (const BitString_t *bs)
 Check if a bit string is valid. More...
 
BitString_tBsAlloc (int size)
 Create a bit string. More...
 
int BsFree (BitString_t *bs)
 Free a bit string. More...
 
BitString_tBsDup (const BitString_t *src)
 Duplicate a bit string. More...
 
int BsIsSub (const BitString_t *a, const BitString_t *b)
 Bit string incidence relation. More...
 
int BsIntersectionCount (const BitString_t *a, const BitString_t *b)
 Intersection count. More...
 
int BsMinus (BitString_t *dest, const BitString_t *src)
 Difference of two bit strings. More...
 
int BsClearAll (BitString_t *bs)
 Clear a bit string This function clears all bits in a bit string. More...
 
int BsCompare (const BitString_t *a, const BitString_t *b)
 Compare two bit strings. More...
 
BitString_tBsCopy (BitString_t *dest, const BitString_t *src)
 Copy a bit string. More...
 
int BsOr (BitString_t *dest, const BitString_t *src)
 Union of two bit strings. More...
 
void BsPrint (const char *name, const BitString_t *bs)
 Print a bit string on stdout. More...
 
BitString_tBsRead (FILE *f)
 Read a bit string from a file. More...
 
int BsWrite (BitString_t *bs, FILE *f)
 Write a bit string to a file. More...
 
int BsSet (BitString_t *bs, int i)
 Set one bit in a bit string. More...
 
int BsClear (BitString_t *bs, int i)
 Clear one bit in a bit string. More...
 
int BsTest (const BitString_t *bs, int i)
 Test a bit in a bit string. More...
 

Function Documentation

◆ BsAlloc()

BitString_t* BsAlloc ( int  size)

Create a bit string.

This function creates a new bit string of the specified size. The new bit string is filled with zeros.

See also
BsFree()
Parameters
sizeSize of the bit string.
Returns
Pointer to the new bit string, or NULL on error.

◆ BsAnd()

int BsAnd ( BitString_t dest,
const BitString_t src 
)

Intersection of two bit strings.

This function performs a bitwise "and" operation on the operands and stores the result in dest. Both bit strings must have the same size.

Returns
0 on success, -1 on error.

◆ BsClear()

int BsClear ( BitString_t bs,
int  i 
)

Clear one bit in a bit string.

This function clears a single bit in a bit string. i is the index of the bit to clear, the first bit having index 0. i must be less than the bit string's size. It is not possible to change the size of an existing bit string.

See also
BsSet(BitString_t*,int)
Parameters
bsPointer to the bit string.
iIndex of the bit to clear (starting from 0).
Returns
0 on success, -1 on error.

◆ BsClearAll()

int BsClearAll ( BitString_t bs)

Clear a bit string This function clears all bits in a bit string.

Returns
0 on success, -1 on error.

◆ BsCompare()

int BsCompare ( const BitString_t a,
const BitString_t b 
)

Compare two bit strings.

Parameters
aFirst bit string.
bSecond bit string.
Returns
0 if the bit strings are equal. Otherwise the return value is different from zero.

◆ BsCopy()

BitString_t* BsCopy ( BitString_t dest,
const BitString_t src 
)

Copy a bit string.

See also
BsDup(BitString_t const *)
Parameters
destDestination bit string.
srcSource bit string.
Returns
dest on success, 0 on error.

◆ BsDup()

BitString_t* BsDup ( const BitString_t src)

Duplicate a bit string.

Returns an independent copy of the argument, or 0 on error.

◆ BsFree()

int BsFree ( BitString_t bs)

Free a bit string.

This function frees a bit string, releasing all associated memory.

See also
BsAlloc()

◆ BsIntersectionCount()

int BsIntersectionCount ( const BitString_t a,
const BitString_t b 
)

Intersection count.

This function calculates the cardinality of the intersection of two bit strings, i.e., the number of bits that are set in both a and b. The arguments must be bit strings of the same size.

Returns
Number of bits in the intersection of a and b, or -1 on error.

◆ BsIsSub()

int BsIsSub ( const BitString_t a,
const BitString_t b 
)

Bit string incidence relation.

This function returns 1 if and only if every bit which is set in a is also set in b. Both bit strings must have the same size.

Returns
1 if a⊆b, 0 if a⊈b, -1 on error.

◆ BsIsValid()

int BsIsValid ( const BitString_t bs)

Check if a bit string is valid.

This function checks if its argument, is a pointer to a valid bit string. If the bit string is o.k., the function returns 1. Otherwise, an error is signaled and, if the error handler does not terminate the program, the function returns 0.

Parameters
bsBit string to check.
Returns
1 if bs is a valid bit string, 0 otherwise.

◆ BsMinus()

int BsMinus ( BitString_t dest,
const BitString_t src 
)

Difference of two bit strings.

This function computes the (set theoretical) difference of two bit strings, i.e., a bit in the result is set if and only if it is set in dest but not in src. The result is stored in dest and overwrites the previous value. The arguments must be bit strings of the same size.

Returns
0 on success, -1 on error.

◆ BsOr()

int BsOr ( BitString_t dest,
const BitString_t src 
)

Union of two bit strings.

This function computes the union of two bit strings, i.e., the bitwise logical "or". The result is stored in dest and overwrites the previous value. Both bit strings must have the same size.

Returns
0 on success, -1 on error.

◆ BsPrint()

void BsPrint ( const char *  name,
const BitString_t bs 
)

Print a bit string on stdout.

This function writes a bit string in readable format, i.e., as a sequence of 0's and 1's, to stdout.

Parameters
nameName to print before the matrix, or 0.
bsThe bit string.

◆ BsRead()

BitString_t* BsRead ( FILE *  f)

Read a bit string from a file.

Parameters
fFile to read from. Must be open for reading.
Returns
The bit string, 0 on error.

◆ BsSet()

int BsSet ( BitString_t bs,
int  i 
)

Set one bit in a bit string.

This function sets a single bit in a bit string. i is the index of the bit to set, the first bit having index 0. i must be less than the bit string's size. It is not possible to change the size of an existing bit string.

See also
BsClear(BitString_t*,int)
Parameters
bsPointer to the bit string.
iIndex of the bit to set (starting from 0).
Returns
0 on success, -1 on error.

◆ BsTest()

int BsTest ( const BitString_t bs,
int  i 
)

Test a bit in a bit string.

Parameters
bsPointer to the bit string.
iIndex of the bit to test (starting from 0).
Returns
1 if the bit is set, 0 otherwise.

◆ BsWrite()

int BsWrite ( BitString_t bs,
FILE *  f 
)

Write a bit string to a file.

Parameters
bsThe bit string.
fFile to write to. Must be open for writing.
Returns
0 on success, -1 on error.

MeatAxe 2.4 documentation, generated on Mon Jun 7 2021 11:42:24