Azinix

var_set.c File Reference

Bit vectors. More...

#include "util.h"
#include "var_set.h"

Go to the source code of this file.

Functions

var_set_tvar_set_new (int size)
 Allocate a new var_set data structure of size `size'. Clears all the elements.
var_set_tvar_set_copy (var_set_t *set)
 Allocate a new var_set data structure with the same contents as `set'.
var_set_tvar_set_assign (var_set_t *result, var_set_t *set)
 Assign the contents of `result' to be the same as those of `set'.
void var_set_free (var_set_t *set)
 Free the var_set data structure `set'.
int var_set_n_elts (var_set_t *set)
 Return the number of bits in var_set `set' which are set (i.e. the cardinality of the set).
var_set_tvar_set_or (var_set_t *result, var_set_t *a, var_set_t *b)
 Compute the bitwise inclusive OR of `a' and `b', and store the result in `result'. Also, return a pointer to `result'.
var_set_tvar_set_and (var_set_t *result, var_set_t *a, var_set_t *b)
 Compute the bitwise AND of `a' and `b', and store the result in `result'. Also, return a pointer to `result'.
var_set_tvar_set_not (var_set_t *result, var_set_t *a)
 Compute the bitwise complement of `a', and store the result in `result'. Also, return a pointer to `result'.
int var_set_get_elt (var_set_t *set, int index)
 Return the value of the bit at position `index' in `set'.
void var_set_set_elt (var_set_t *set, int index)
 Set the value of the bit at position `index' in `set'.
void var_set_clear_elt (var_set_t *set, int index)
 Clear the value of the bit at position `index' in `set'.
void var_set_clear (var_set_t *set)
 Clear the value of all the bits in `set'.
int var_set_intersect (var_set_t *a, var_set_t *b)
 Return 1 if the var_sets `a' and `b' intersect (i.e. have bits set in the same position); otherwise, return 0.
int var_set_is_empty (var_set_t *a)
 Return 1 if every bit of var_set `a' is cleared; otherwise, return 0.
int var_set_is_full (var_set_t *a)
 Return 1 if every bit of var_set `a' is set; otherwise, return 0.
void var_set_print (FILE *fp, var_set_t *set)
 Print to `fp' the value of each bit in var_set `set'.
int var_set_equal (var_set_t *a, var_set_t *b)
 Return 1 if the var_sets `a' and `b' are equal at every bit position; otherwise, return 0.
int var_set_cmp (char *obj1, char *obj2)
 Return 0 if the var_sets `a' and `b' are equal at every bit position; otherwise, return 1.
unsigned int var_set_hash_with_modulus (var_set_t *set, unsigned int modulus)
 Compute a hash value for the var_set `set'.
unsigned int var_set_hash (var_set_t *set)
 Compute a hash value for the var_set `set'.


Detailed Description

Bit vectors.

The var_set_t data structure is essentially a bit array. Its size is static. The positions of the array are numbered from 0 to n-1, where n is the size of the var_set. When a bit is "set", its value is 1; when a bit is "clear", its value is 0.

Definition in file var_set.c.


Function Documentation

var_set_t* var_set_and ( var_set_t result,
var_set_t a,
var_set_t b 
)

Compute the bitwise AND of `a' and `b', and store the result in `result'. Also, return a pointer to `result'.

`a', `b', and `result' must be the same size.

Note that `result' can be the same as either or both of `a' and `b' (e.g. var_set_and(foo, foo, bar)).

Definition at line 160 of file var_set.c.

var_set_t* var_set_assign ( var_set_t result,
var_set_t set 
)

Assign the contents of `result' to be the same as those of `set'.

`result' and `set' must be the same size.

Definition at line 59 of file var_set.c.

void var_set_clear ( var_set_t set  ) 

Clear the value of all the bits in `set'.

Definition at line 251 of file var_set.c.

void var_set_clear_elt ( var_set_t set,
int  index 
)

Clear the value of the bit at position `index' in `set'.

`index' must be at least zero and less than the size of `set'.

Definition at line 240 of file var_set.c.

int var_set_cmp ( char *  obj1,
char *  obj2 
)

Return 0 if the var_sets `a' and `b' are equal at every bit position; otherwise, return 1.

`a' and `b' must be the same size.

Definition at line 344 of file var_set.c.

var_set_t* var_set_copy ( var_set_t set  ) 

Allocate a new var_set data structure with the same contents as `set'.

Definition at line 42 of file var_set.c.

int var_set_equal ( var_set_t a,
var_set_t b 
)

Return 1 if the var_sets `a' and `b' are equal at every bit position; otherwise, return 0.

`a' and `b' must be the same size.

Definition at line 325 of file var_set.c.

void var_set_free ( var_set_t set  ) 

Free the var_set data structure `set'.

Definition at line 72 of file var_set.c.

int var_set_get_elt ( var_set_t set,
int  index 
)

Return the value of the bit at position `index' in `set'.

`index' must be at least zero and less than the size of `set'.

Definition at line 206 of file var_set.c.

unsigned int var_set_hash ( var_set_t set  ) 

Compute a hash value for the var_set `set'.

Definition at line 378 of file var_set.c.

unsigned int var_set_hash_with_modulus ( var_set_t set,
unsigned int  modulus 
)

Compute a hash value for the var_set `set'.

This is to be used when var_sets are used as keys in the st package specifically, since st expects the hash function to take a key and a modulus

Definition at line 367 of file var_set.c.

int var_set_intersect ( var_set_t a,
var_set_t b 
)

Return 1 if the var_sets `a' and `b' intersect (i.e. have bits set in the same position); otherwise, return 0.

`a' and `b' must be the same size.

Definition at line 266 of file var_set.c.

int var_set_is_empty ( var_set_t a  ) 

Return 1 if every bit of var_set `a' is cleared; otherwise, return 0.

Definition at line 279 of file var_set.c.

int var_set_is_full ( var_set_t a  ) 

Return 1 if every bit of var_set `a' is set; otherwise, return 0.

Definition at line 291 of file var_set.c.

int var_set_n_elts ( var_set_t set  ) 

Return the number of bits in var_set `set' which are set (i.e. the cardinality of the set).

Definition at line 101 of file var_set.c.

var_set_t* var_set_new ( int  size  ) 

Allocate a new var_set data structure of size `size'. Clears all the elements.

Definition at line 21 of file var_set.c.

var_set_t* var_set_not ( var_set_t result,
var_set_t a 
)

Compute the bitwise complement of `a', and store the result in `result'. Also, return a pointer to `result'.

`a' and `result' must be the same size.

Note that `result' can be the same as `a' (e.g. var_set_not(foo, foo)).

Definition at line 183 of file var_set.c.

var_set_t* var_set_or ( var_set_t result,
var_set_t a,
var_set_t b 
)

Compute the bitwise inclusive OR of `a' and `b', and store the result in `result'. Also, return a pointer to `result'.

`a', `b', and `result' must be the same size.

Note that `result' can be the same as either or both of `a' and `b' (e.g. var_set_or(foo, foo, bar)).

Definition at line 136 of file var_set.c.

void var_set_print ( FILE *  fp,
var_set_t set 
)

Print to `fp' the value of each bit in var_set `set'.

Example output for a set of 4 elements: "1 0 1 1".

Definition at line 307 of file var_set.c.

void var_set_set_elt ( var_set_t set,
int  index 
)

Set the value of the bit at position `index' in `set'.

`index' must be at least zero and less than the size of `set'.

Definition at line 225 of file var_set.c.