home *** CD-ROM | disk | FTP | other *** search
- #ifndef __RWTVHSET_H__
- #define __RWTVHSET_H__
- pragma push_align_members(64);
-
- /*
- * RWTValHashSet<T>: A Set of values of type T, using a hashed lookup
- *
- * $Header: E:/vcs/rw/tvhset.h_v 1.2 17 Mar 1992 12:00:44 KEFFER $
- *
- ****************************************************************************
- *
- * Rogue Wave Software, Inc.
- * P.O. Box 2328
- * Corvallis, OR 97339
- *
- * Copyright (C) 1992. This software is subject to copyright
- * protection under the laws of the United States and other countries.
- *
- ***************************************************************************
- *
- * This class implements a parameterized Set of types T. In a Set,
- * only one instance of an object of a given value can be inserted into
- * the collection.
- *
- * The implementation uses a hash table.
- *
- * Example use of this class:
- *
- * #include <rw/cstring.h>
- * #include <rw/tvhset.h>
- *
- * unsigned myHash(const RWCString& s){ return s.hash(); }
- *
- * RWTValHashSet<RWCString> set(myHash); // A Set of RWCStrings
- *
- * set.insert("a string"); // Type conversion: char* to RWCString happens
- * set.insert("another string");
- * set.insert("a string"); // Rejected (already exists in collection)
- * set.contains("a string"); // Returns true.
- *
- *
- * Note that the constructor for RWTValHashSet<T> takes a function with
- * prototype
- *
- * unsigned hashFun(const T&);
- *
- * It should return a suitable hashing value for an instance of class T.
- * Usually, the definition for such a function is trivial because hashing
- * functions have been defined for all Rogue Wave supplied classes.
- *
- ***************************************************************************
- *
- * $Log: E:/vcs/rw/tvhset.h_v $
- *
- * Rev 1.2 17 Mar 1992 12:00:44 KEFFER
- *
- * Rev 1.1 04 Mar 1992 10:16:46 KEFFER
- *
- * Rev 1.0 02 Mar 1992 16:10:54 KEFFER
- * Initial revision.
- */
-
- //$DECLARE_TEMPLATE
-
- #include "rw/tvhasht.h"
-
- /****************************************************************
- * *
- * Declarations for RWTValHashSet<T> *
- * *
- ****************************************************************/
-
- template <class T> class RWExport RWTValHashSet : public RWTValHashTable<T> {
-
- public:
-
- RWTValHashSet(unsigned (*hashFun)(const T&), unsigned size = RWDEFAULT_CAPACITY) :
- RWTValHashTable<T>(hashFun, size) { }
-
- // Member functions:
- void insert(T val);
- unsigned occurrencesOf(T val) const;
- };
-
- //$IMPLEMENT_TEMPLATE
-
- /****************************************************************
- * *
- * Definitions for RWTValHashSet<T> *
- * *
- ****************************************************************/
-
- template <class T> void
- RWTValHashSet<T>::insert(T val)
- {
- int idx = (int)hashIndex(val);
- if (_table(idx)==rwnil) _table(idx) = new CHAIN;
- else if (_table(idx)->contains(val)) return;
- _table(idx)->insert(val);
- _nitems++;
- }
-
- template <class T> unsigned
- RWTValHashSet<T>::occurrencesOf(T val) const
- {
- // This works because only one instance is allowed ---
- return contains(val) ? 1 : 0;
- }
-
- pragma pop_align_members();
- #endif /* __RWTVHSET_H__ */
-