// File:			bitset.hpp
// ----------------------------------------------------------------------
// Author:          Computer Science S-111 staff
// Modified by:     Russell Lowke, lowke@fas.harvard.edu
// TF:              Francis Crick
// Date modified:   7/24/2002
// Version:			1
//
// Description:
//     Header file for the bitset class, which can be used to represent sets
//     containing integer values from 0 to some maximum value.
//
// Computer Science S-111, Harvard University
//

#ifndef _BITSET_HPP
#define _BITSET_HPP

#include <cstdlib>
#include <iostream>
#include <iomanip>

class bitset {
	private:
		int   size;      // # bits; possible elements = 0, 1, ..., size - 1
		char *bits;
		int   nbyte;

		// private methods: used only within other methods of the class
		void set_bit(int offset);
		bool get_bit(int offset) const;
		void clear_bit(int offset);

	public:
		bitset();
		bitset(int size);
		bitset(int s, int i, int j);  // constructs a set of size s,
									  // in which elemets i through j inclusive
									  // are in the set *
									  
		bitset(const bitset& seta);   // copy constructor
		~bitset();                    // destructor

		void set_size(int size);
		void include(int i);
		void exclude(int i);
		bool member(int i) const;
		bool is_null() const;
		void clear();
		
		void include(int i, int j);		// adds values i through j to a set *
		int cardinality();				// returns the number of members *
		void invert();					// inverts all bits in a set *
		
		//
		// overloaded operators
		//
		const bitset& operator =(const bitset& seta);

		// set union
		friend bitset operator +(const bitset& seta, const bitset& setb);

		// set difference
		friend bitset operator -(const bitset& seta, const bitset& setb);

		// set intersection
		friend bitset operator *(const bitset& seta, const bitset& setb);

		friend bool operator ==(const bitset& seta, const bitset& setb);
		friend ostream& operator <<(ostream& os, bitset seta);
		friend istream& operator >>(istream& is, bitset& seta);
		
		// returns bool indicating whether the first parameter is a subset 
		// of the second.  By convention, any set is a subset of itself,
		// and the null set is a subset of any set. *
		friend bool operator < (const bitset& seta, const bitset& setb);

		// * methods added by Russell 7/23/2002
};

#endif // _BITSET_HPP
