home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
- #ifndef _IIHSHKB_H
- #define _IIHSHKB_H
-
- #include <stdlib.h>
- #include <iglobals.h>
-
- class IHashKeyBagImpl {
- public:
-
- class Node {
- friend class IHashKeyBagImpl;
- Node* ivNext;
- };
-
- class Operations {
- virtual Node* newNode (void const* element) const = 0;
- virtual Node* copyNode (void const* node) const = 0;
- virtual void deleteNode (void* node) const = 0;
-
- virtual void* newBlock (size_t) const = 0;
- virtual void removeBlock (void*, size_t) const = 0;
-
- virtual INumber getHashvalue (void const* key, INumber) const = 0;
-
- virtual void* elementAt (void* node) const = 0;
- virtual void const*
- constElementAt (void const* node) const = 0;
- virtual void const*
- keyAt (void const* node) const = 0;
- virtual Boolean isKeyEqualTo (void const* node1,
- void const* node2) const = 0;
- virtual Boolean isKeyEqualToElement (void const* node,
- void const* element) const = 0;
- virtual Boolean isKeyEqualToKey (void const* node,
- void const* key) const = 0;
- virtual void copyFrom (void* node,
- void const* element) const = 0;
- virtual Boolean constantFunctionIteration
- (void *function,
- void* env,
- void const* node) = 0;
- virtual Boolean functionIteration (void *function,
- void* env,
- void* node) = 0;
- virtual Boolean constantIteratorIteration
- (void* iterator,
- void const* node) = 0;
- virtual Boolean iteratorIteration (void* iterator,
- void* node) = 0;
-
- virtual long functionComparison (void *compareFunction,
- void const* node1,
- void const* node2) = 0;
- friend class IHashKeyBagImpl;
- };
-
- class Cursor {
- public:
- INumber ivEntryNumber;
- Node* ivNode;
-
- Cursor () : ivNode (0) {}
-
- Boolean operator== (Cursor const& cursor)
- { return ivNode == cursor.ivNode &&
- ivEntryNumber == cursor.ivEntryNumber; }
- Boolean operator!= (Cursor const& cursor)
- { return ! operator== (cursor); }
- };
-
- private :
-
- Operations* ivOps;
- INumber ivNoEntries;
- INumber ivNoElements;
- Node** ivTable;
- INumber* ivCollList;
-
- void createHashtable (INumber);
-
- void copyHashtable (IHashKeyBagImpl const&);
-
- public:
-
- IHashKeyBagImpl (INumber, Operations*);
-
- IHashKeyBagImpl (IHashKeyBagImpl const&, Operations*);
-
- ~IHashKeyBagImpl ();
-
- Boolean add (void const* element,
- INumber,
- Cursor&);
-
- Boolean add (void const* element,
- INumber);
-
- void addAllFrom (IHashKeyBagImpl const&);
-
- IHashKeyBagImpl& operator= (IHashKeyBagImpl const&);
-
- void const* elementAt (Cursor const&) const;
-
- void* elementAt (Cursor const&);
-
- void const* anyElement () const;
-
- void removeAt (Cursor const&);
-
- INumber removeAll (void* predicate,
- void* environment);
-
- void replaceAt (Cursor const&,
- void const* element);
-
- void removeAll ();
-
- Boolean isBounded () const;
-
- INumber maxNumberOfElements () const;
-
- INumber numberOfElements () const;
-
- Boolean isEmpty () const;
-
- Boolean isFull () const;
-
- Boolean setToFirst (Cursor&) const;
-
- Boolean setToNext (Cursor&) const;
-
- Boolean allElementsDo (void* function,
- void* environment) const;
-
- Boolean allElementsDo (void* function,
- void* environment);
-
- Boolean allElementsDo (void* iterator) const;
-
- Boolean allElementsDo (void* iterator);
-
- // Keycollection methods
- public:
- Boolean containsAllKeysFrom (IHashKeyBagImpl const&) const;
-
- Boolean containsElementWithKey
- (void const* key, INumber)const;
-
- INumber numberOfElementsWithKey
- (void const* key, INumber) const;
-
- Boolean locateElementWithKey(void const* key,
- INumber,
- Cursor&) const;
- private:
- Boolean locateElementWithKeyOfElement
- (void const* element,
- INumber,
- Cursor&) const;
- public:
- Boolean replaceElementWithKey
- (void const* element,
- INumber,
- Cursor&);
-
- Boolean replaceElementWithKey
- (void const* element,
- INumber);
-
- Boolean locateOrAddElementWithKey
- (void const* element,
- INumber,
- Cursor&);
-
- Boolean locateOrAddElementWithKey
- (void const* element,
- INumber);
-
- Boolean addOrReplaceElementWithKey
- (void const* element,
- INumber,
- Cursor&);
-
- Boolean addOrReplaceElementWithKey
- (void const* element,
- INumber);
-
- Boolean removeElementWithKey(void const* key, INumber);
-
- void const* elementWithKey (void const* key, INumber)const;
-
- void* elementWithKey (void const* key, INumber);
-
- Boolean locateNextElementWithKey
- (void const* key,
- INumber,
- Cursor&) const;
-
- INumber removeAllElementsWithKey
- (void const* key, INumber);
-
- INumber numberOfDifferentKeys
- () const;
-
- Boolean setToNextWithDifferentKey
- (Cursor&) const;
-
- INumber noEntries () const;
-
- Boolean checkCursor (Cursor const&) const;
-
- };
-
- #endif