SharedMeatAxe 1.0
Bit-String Handling

Bit strings can be written to and read from files. More...

Data Structures

class  BitString_t
 A bit string. More...
 

Functions

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

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.

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.

◆ 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.

◆ 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.

SharedMeatAxe 1.0 documentation