#ifndef _COLLECTIONS_H #define _COLLECTIONS_H #include typedef struct bit_set* BitSet; /** Creates a new BitSet. * @param size The size of the new bit set * @param arena The arena to use for memory management. */ BitSet set_new(int size); BitSet set_clone(BitSet original); #define FOR_EACH(i, s) for(i = set_next(s, 0); i >= 0; i = set_next(s, i + 1)) #define FIRST_IN(s) set_next(s, 0) #define set_contains(s, i) set_contains_function(s, i) // #define set_contains(s, i) ((s)->bits[(i)>>5] & (1<<((i)&31))) /** Sets the nth bit in the set. */ void set_add(BitSet set, int n); /** Set the bit 'from' to the value in 'to', leaving the bit 'from' unset. */ void set_moveBit(BitSet set, int to, int from); /** Mark this set as immutable henceforth */ void set_fix(BitSet set); /** Tests whether two BitSets are equal */ int set_equals(BitSet set1, BitSet set2); /** Unsets the nth bit in the set. */ void set_remove(BitSet set, int n); /** Tests the nth bit in the set. */ int set_contains_function(BitSet set, int n); /** Prints a representation of set to file.*/ void set_print(FILE* file, BitSet set); /** Sets all the bits in set to 0. */ void set_clear(BitSet set); /** Returns the index of the set bit with the lowest index, * such that index >= from */ int set_next(BitSet set, int from); /** Sets all the bits in set that are set in pattern. Bits not set in pattern are unaltered in set. */ void set_addSet(BitSet set, const BitSet pattern); /** Unsets all the bits in set that are set in pattern. Bits not set in pattern are unaltered in set. */ void set_removeSet(BitSet set, const BitSet pattern); /** Return true (non-zero) if set is empty */ int set_empty(BitSet set); /** Returns the number of set bits in this set */ int set_size(BitSet set); /** Returns a new set which is the intersection of set1 and set2 */ BitSet set_intersection(BitSet set1, BitSet set2); /** Returns a new set which is the union of set1 and set2 */ BitSet set_union(BitSet set1, BitSet set2); /** A list structure based on an array of elements */ typedef struct array_list* ArrayList; /** Creates a new ArrayList. The initial capacity of the list is capacity or four, * whichever is greater. * @param capacity The initial capacity to allocate for this list. * @param arena The arena to use for memory management. */ ArrayList list_new(int capacity); /** Returns a null terminated array representation of this list. * Alterations to the array will invalidate the list and vice-versa. void** list_array(ArrayList list);*/ /** Adds an item to the list. */ void list_add(ArrayList list, void* item); /** Removes an item from the list. */ void list_remove(ArrayList list, int item); /** Returns the size of the list. */ int list_size(ArrayList list); /** Returns the nth item of the list. */ void* list_get(ArrayList list, int n); /** Sets the nth of the list. Must be within bounds. */ void list_set(ArrayList list, int n, void* item); void list_sort(ArrayList list, int (*compare)(const void*, const void*)); void list_print(ArrayList list, FILE* out, void (*print)(FILE*, void*)); #endif