File: Bit_Set/*

Bit_Set should have both a length and a size (like Vector) so it can
grow intelligently.  Doing this makes everything more efficient after
doing a clear on a set, and it makes it possible to have a more
efficient operator=, which doesn't re-allocate it's storage every time.

BITSPERBYTE is guarenteed to be a power of two.  Instead of dividing by
and taking the ramainder of BITSPERBYTE all the time, shift and mask.
(Some compilers are too dumb to realize that a divide by 8 is a shift by 3)
Add to Bit_Set.h the following, and use everywhere instead of / and %
#DEFINE BIT_OFFSET(n) (n & 7)
#DEFINE BIT_BYTE(n) (n >> 3)

The bit_set_position union reverses the order of byte and offset, and
causes the code which deals with current position to be horrably
inefficient.  Make current_position a long, and define the following:
#define MAKE_POSITION(byte, offset) ((byte << 3) | offset)
#define POSITION_TRAVERSED #x80000000
#define IS_POSITION_VALID(position) (position < 0)

*** NOTE: INVALID is -1, which sets the traversed flag.
***       Does this cause problems? 

This makes setting the current position to an index a simple store, and
the value method becomes
inline int Bit_Set::value () {
#if ERROR_CHECKING
  if (this->current_position == INVALID)	// If INVALID current position
    this->value_error ();			// Raise exception
#endif
  return this->current_position & ~POSITION_TRAVERSED;
}


resize, Bit_Set (int n) //constructor
  Replace
    int num = (n / BITSPERBYTE) + ((n % BITSPERBYTE) ? 1 : 0); // Round up
  With
    int num = (n+BITSPERBYTE-1) / BITSPERBYTE; // Round up

~Bit_Set ()
  Make this inline

find
  After fixing the bugs, make this inline.

put (int n), remove(), remove (int n), 
  Make this inline.

search
  Instead of:
    for (int i = 0; i < this->size && i < b.size; i++) // For each byte in set
  use
    int smallest = min(this->size, b.size);
  This saves an extra test each time around the loop

operator-(), operator-(Bit_Set), operator|, operator^, operator&
  These all allocate a set on the heap, which is never deleted.
  They pass their result by value.  Allocate on the stack instead.

operator|, operator^, operator&
 Replace this:
  Bit_Set* result;				// Temporary variable
  if (this->size > b.size) {			// Determine longest storage
    result = new Bit_Set (this->size);		// Allocate storage
    result->size = this->size;			// Update size allocation
  }
  else {					// Else the other one is bigger
    result = new Bit_Set (b.size);		// Allocate storage equal to b
    result->size = b.size;			// Update size allocation
  }

 With this:
  Bit_Set result(max(this->size, b.size)*BITSPERBYTE);	// Temporary variable
 result->size will be set by the constructor.

operator|
 replace:
  for (int i = 0; i < this->size; i++)		// For each byte in first set
    result->data[i] = this->data[i];		// Copy to result bit set
  for (i = 0; i < b.size; i++)			// For each byte in second set
    result->data[i] |= b.data[i];		// Set any bits not already set
 with
  int min_size = min(this->size, b.size);
  for (int i = 0; i < min_size; i++)		// For each byte
    result->data[i] = this->data[i] | b.data[i];// OR into result bit set
  if (this->size < b.size)
    for (; i < this->size; i++)			// For each byte in first set
      result->data[i] = this.data[i];		// Copy to result bit set
  else
    for (; i < b.size; i++)			// For each byte in second set
      result->data[i] = b.data[i];		// Copy to result bit set
 This avoids referencing the byte array memory twice.

operator- operator^ operator&
  do the same kind of thing as noted for the above operator|

BETTER YET:
  Write a MACRO (in the .C file) which does a generic boolean operation
  on two bit sets, then invoke it 4 times, for | - ^ &, and some
  appropriate parameter which will tell it what to do with the
  part of one set which is longer than the other.

EVEN BETTER YET:
  Make the above macro work in terms of unsigned int's instead of bytes.
  This will get maximal efficiency out of the hardware. (which is what
  you use bit set for, right :-)

MACRO generate_set_operator(result, a, b, op, a_excess, b_excess) {
  int a_size = a.size / sizeof(int);
  int b_size = b.size / sizeof(int);
  int r_size = result.size / sizeof(int);
  unsigned int* a_data = (int*) a.data;
  unsigned int* b_data = (int*) b.data;
  unsigned int* res = (int*) result.data;
  int min_size = min(a_size, b_size);
  for (int i = 0; i < min_size; i++)
    res[i] = a_data[i] op b_data[i];    // operate on common sets
  if (a_size > b_size)
    for (; i < r_size; i++)
      res[i] = excess_a;		// operate on excess a's
  else
    for (; i < r_size; i++)
      res->data[i] = excess_b;		// operate on excess b's
}

for operator|
  generate_set_operator(result, this, b, |, a_data[i], b_data[i])
for operator-
  generate_set_operator(result, this, b, &~, a_data[i], 0)
for operator^
  generate_set_operator(result, this, b, ^, a_data[i], b_data[i])
for operator&
  generate_set_operator(result, this, b, ^, 0, 0)


operator|= operator^=
  These conses an extra set when it doesn't need to :( YUCK )

operator|= operator-= operator^= operator&=
  Write a macro to implement these, similar to the one above.
  Perhaps the same macro will work for both sets of operators?

operator<<
  Since Bit_Set's are thought of as a set of int's, shouldn't it print
  as a set of int's? (i.e. [1 3 4] instead of [00001101])
  Re-write this to use reset, next and value.
