Data Structures | |
| struct | nm_bv |
| Bit Vector. More... | |
Typedefs | |
| typedef struct nm_bv | nm_bv_t |
| Bit Vector. | |
Functions | |
| void | nm_bv_free (nm_bv_t *bv) |
| Free the memory associated with a bit vector. | |
| int | nm_bv_copy (nm_bv_t *dst, nm_bv_t *src) |
| Copy a bit vector. | |
| int | nm_bv_set (nm_bv_t *bv, int bit) |
| Set a bit in the bit vector. | |
| int | nm_bv_set_count (nm_bv_t *bv) |
| Get the count of set bits in the vector. | |
| int | nm_bv_reset (nm_bv_t *bv, int bit) |
| Reset a bit in the bit vector. | |
| int | nm_bv_test (nm_bv_t *bv, int bit) |
| Tests a bit in the bit vector. | |
| int | nm_bv_first (nm_bv_t *bv, nm_bv_iter_t *iter) |
| Returns the first set bit in the bit vector. | |
| int | nm_bv_next (nm_bv_t *bv, nm_bv_iter_t *iter) |
| Returns the next set bit in the bit vector. | |
| int | nm_sz_to_bv (const char *sz, nm_bv_t *bv, const char *rangesep, const char *sep) |
| Convert a string to a bit vector. | |
| int | nm_bv_to_sz (nm_bv_t *bv, char *sz, int maxlen, const char *rangesep, const char *sep) |
| Convert a bit vector to a string. | |
Bit Vector.
This data structure implements a bit vector. The structure can be defined on the stack or globally, but must be initialized to all zeroes before calling the set or reset bit functions. The bit vector array memory is allocate as needed by the set and reset functions.
Copy a bit vector.
| dst | Destination bit vector | |
| src | Source bit vector |
| int nm_bv_first | ( | nm_bv_t * | bv, | |
| nm_bv_iter_t * | iter | |||
| ) |
Returns the first set bit in the bit vector.
Searches the bit vector for the first set bit and returns it's index.
| bv | Pointer to the bit vector. | |
| iter | Iterator to use to track current search position. |
| void nm_bv_free | ( | nm_bv_t * | bv | ) |
Free the memory associated with a bit vector.
| bv | Pointer to the bit vector |
| int nm_bv_next | ( | nm_bv_t * | bv, | |
| nm_bv_iter_t * | iter | |||
| ) |
Returns the next set bit in the bit vector.
Searches the bit vector from the current position for the next set bit and returns it's index.
| bv | Pointer to the bit vector. | |
| iter | Iterator used in nm_bv_first. |
| int nm_bv_reset | ( | nm_bv_t * | bv, | |
| int | bit | |||
| ) |
Reset a bit in the bit vector.
Reset's the specified bit in the bit vector. If the requested bit is greater than the current max, the bit vector is grown to accomodate the new bit.
| bv | Pointer to the bit vector. | |
| bit | Bit number to set. If a negative number is specified, all bits in the vector will be reset. |
| int nm_bv_set | ( | nm_bv_t * | bv, | |
| int | bit | |||
| ) |
Set a bit in the bit vector.
Set's the specified bit in the bit vector. If the requested bit is greater than the current max, the bit vector is grown to accomodate the new bit.
| bv | Pointer to the bit vector. | |
| bit | Bit number to set. |
| int nm_bv_set_count | ( | nm_bv_t * | bv | ) |
Get the count of set bits in the vector.
Returns the count of one bits in the vector.
| bv | Pointer to the bit vector. |
| int nm_bv_test | ( | nm_bv_t * | bv, | |
| int | bit | |||
| ) |
Tests a bit in the bit vector.
Tests if the specified bit in the bit vector is set.
| bv | Pointer to the bit vector. | |
| bit | Bit number to test. |
non-zero Success
| int nm_bv_to_sz | ( | nm_bv_t * | bv, | |
| char * | sz, | |||
| int | maxlen, | |||
| const char * | rangesep, | |||
| const char * | sep | |||
| ) |
Convert a bit vector to a string.
Generate a string that contains numbers representing the set-bits in the vector. Ranges of there or more consecutive bits are collapsed into a range string. The parameter rangesep specifies the string to use between the first and last bits in the range. The sep parameter specifies the string to place between bits number and/or ranges.
| bv | The input bit vector | |
| sz | The output string buffer | |
| maxlen | The maximum number of characters to place in the output string | |
| rangesep | The string that separates the boundaries of a range. | |
| sep | The separator character |
!0 To indicate an invalid bit vector or string.
| int nm_sz_to_bv | ( | const char * | sz, | |
| nm_bv_t * | bv, | |||
| const char * | rangesep, | |||
| const char * | sep | |||
| ) |
Convert a string to a bit vector.
Parse the input string and set the bits specified in the string in the provided bit vector. The parser supports specifying a range of values. The rangesep parameter specifies the string to use to separate the min and max values in a range. The sep value separates ranges and/or singular set members.
| sz | The input string. | |
| bv | The bit vector to fill | |
| rangesep | The string that separates the boundaries of a range. | |
| sep | The separator character |
!0 To indicate an invalid string.
1.5.6