home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWSET_H__
- #define __RWSET_H__
- pragma push_align_members(64);
-
- /*
- * Declarations for RWSet --- hash table lookup.
- *
- * $Header: E:/vcs/rw/rwset.h_v 1.2 18 Feb 1992 09:54:40 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave
- * P.O. Box 2328
- * Corvallis, OR 97339
- * Voice: (503) 754-3010 FAX: (503) 757-6650
- *
- * Copyright (C) 1989, 1990, 1991. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * Duplicates are not allowed.
- * Hash table look up with linear probing via double hashing.
- *
- * The table size must be a prime number, so that the linear probing
- * does not wrap around back onto itself.
- *
- * $Log: E:/vcs/rw/rwset.h_v $
- *
- * Rev 1.2 18 Feb 1992 09:54:40 KEFFER
- *
- * Rev 1.1 28 Oct 1991 09:08:22 keffer
- * Changed inclusions to <rw/xxx.h>
- *
- * Rev 1.0 28 Jul 1991 08:16:38 keffer
- * Tools.h++ V4.0.5 PVCS baseline version
- *
- */
-
- #include "rw/colclass.h"
- #include "rw/iterator.h"
-
- class RWExport RWSetIterator;
-
- class RWExport RWSet : public RWCollection {
- friend RWSetIterator;
- protected:
- enum hashStatus {empty, occupied, deleted};
- protected:
- typedef char infoType;
- RWCollectableP* table; // Pointer to an array of pointers to objects.
- infoType* info; // Array giving information about status of array indices.
- unsigned npts; // Size of above arrays.
- unsigned items; // Total number of stored objects.
- unsigned resizeThreshold; // Resize if items > resizeThreshold.
- static unsigned nextPrime(unsigned);
- protected:
- void copyOld(const RWSet&);
- virtual unsigned findIndex(const RWCollectable* a) const; // Return index of a.
- unsigned findIndexReference(const RWCollectable* a) const;
- RWCollectable* removeAtIndex(unsigned);
- static unsigned secondaryHash(unsigned i){ return 8-(i&0x7); }
- public:
-
- RWSet(unsigned N = RWCollection::DEFAULT_CAPACITY);
- RWSet (const RWSet&);
- ~RWSet();
-
- /******************** Member operators ****************************/
- void operator=(const RWSet&);
- RWBoolean operator<=(const RWSet&) const;
- RWBoolean operator==(const RWSet&) const;
- RWBoolean operator!=(const RWSet&) const;
-
- /****************** Virtual member functions *******************/
- virtual void apply(RWapplyCollectable, void*);
- //virtual unsigned binaryStoreSize() const;
- virtual void clear();
- //virtual void clearAndDestroy();
- //virtual int compareTo(const RWCollectable*) const;
- //virtual RWBoolean contains(const RWCollectable*) const;
- virtual unsigned entries() const {return items;}
- virtual RWCollectable* find(const RWCollectable*) const;
- //virtual unsigned hash() const;
- virtual RWCollectable* insert(RWCollectable*);
- virtual ClassID isA() const {return __RWSET;}
- virtual RWBoolean isEmpty() const {return items==0;}
- virtual RWBoolean isEqual(const RWCollectable*) const;
- virtual RWCollectable* newSpecies() const;
- virtual unsigned occurrencesOf(const RWCollectable*) const;
- virtual RWCollectable* remove(const RWCollectable*);
- //virtual void removeAndDestroy(const RWCollectable*);
- //virtual void restoreGuts(RWvistream&);
- //virtual void restoreGuts(RWFile&);
- //virtual void saveGuts(RWvostream&) const;
- //virtual void saveGuts(RWFile&) const;
-
- /********************** Special functions **********************************/
- void resize(unsigned n = 0); // Resize to n, or if n==0, next prime > 2*size
-
- #ifdef RDEBUG
- // Print status of hash table:
- friend ostream& operator<<(ostream&, const RWSet&);
- #endif
- };
-
- class RWExport RWSetIterator : public RWIterator {
- RWSet* theTable;
- int place; // Iterator position.
- public:
- RWSetIterator(RWSet& h);
-
- /*********** Virtual functions inherited from class RWIterator ***********/
- RWCollectable* findNext(const RWCollectable*); // Find next matching item
- RWCollectable* key() const; // Return current item
- RWCollectable* operator()(); // Advance iterator
- void reset();
- /******************* Special iterator functions *******************************/
- RWCollectable* remove(); // Remove current item
- RWCollectable* removeNext(const RWCollectable*); // Remove next matching item
- };
-
- inline void
- RWSetIterator::reset() {place=-1;}
-
- pragma pop_align_members();
- #endif /* __RWSET_H__ */
-