Category : C Source Code
Archive   : CPPOOPS.ZIP
Filename : BITSET.CXX

 
Output of file : BITSET.CXX contained in archive : CPPOOPS.ZIP
/* Bitset.c -- implementation of set of small integers

THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
"UNITED STATES GOVERNMENT WORK". IT WAS WRITTEN AS A PART OF THE
AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE. THIS MEANS IT
CANNOT BE COPYRIGHTED. THIS SOFTWARE IS FREELY AVAILABLE TO THE
PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.

Author:
K. E. Gorlen
Bg. 12A, Rm. 2017
Computer Systems Laboratory
Division of Computer Research and Technology
National Institutes of Health
Bethesda, Maryland 20892
Phone: (301) 496-5363
uucp: uunet!ncifcrf.gov!nih-csl!keith
Internet: keith%[email protected]
September, 1985

Function:

A Bitset is a set of small integers. It is implemented very efficiently
using a single word. Each bit of the word indicates if the integer
associated with the bit position is in the set. Bitsets are
particularly useful in conjunction with enum constants.

$Log: Bitset.c,v $
* Revision 1.2 88/01/16 23:38:00 keith
* Remove pre-RCS modification history
*
*/

#include "Bitset.hxx"
#ifdef OBJECTIO
#include "oopsIO.hxx"
#endif //OBJECTIO

#define THIS Bitset
#define BASE Object
DEFINE_CLASS(Bitset,Object,1,"$Header: Bitset.c,v 1.2 88/01/16 23:38:00 keith Exp $",NULL,NULL);

unsigned Bitset::capacity() { return sizeof(int)*8; }

Object* Bitset::copy() { return shallowCopy(); }

void Bitset::deepenShallowCopy() {}

unsigned Bitset::hash() { return m; }

bool Bitset::isEmpty() { return m==0; }

bool Bitset::isEqual(const Object& ob)
{
return ob.isSpecies(class_Bitset) && *this==*(Bitset*)&ob;
}

const Class* Bitset::species() { return &class_Bitset; }

#ifdef OBJECTIO
void Bitset::printOn(ostream& s)
{
Bitset t = *this;
s << "[";
for (register unsigned i =0; i if (t.includes(i)) {
s << i;
t -= i;
if (!t.isEmpty()) s << ",";
}
}
s << "]";
}
#endif //OBJECTIO

unsigned Bitset::size()
{
register unsigned l=m;
register unsigned n=0;
while (l != 0) {
l &= (l-1); // removes rightmost 1
n++;
}
return n;
}

#ifdef OBJECTIO
Bitset::Bitset(istream& strm, Bitset& where)
{
this = &where;
strm >> m;
}

void Bitset::storer(ostream& strm)
{
BASE::storer(strm);
strm << m << " ";
}

Bitset::Bitset(fileDescTy& fd, Bitset& where)
{
this = &where;
READ_OBJECT_AS_BINARY(fd);
}

void Bitset::storer(fileDescTy& fd)
{
BASE::storer(fd);
STORE_OBJECT_AS_BINARY(fd);
}

#endif //OBJECTIO


  3 Responses to “Category : C Source Code
Archive   : CPPOOPS.ZIP
Filename : BITSET.CXX

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/