home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) IBM Corp. 1992 */
-
- #ifndef _IHSHKB_H
- #define _IHSHKB_H
-
- #include <iglobals.h>
- #include <icursor.h>
- #include <stdlib.h>
- #include <iihshkb.h>
-
- template < class Element, class Key, class ElementOps >
- class IGHashKeyBag {
-
- static ElementOps cvElementOps;
-
- class Node;
- class Operations;
- class Cursor;
-
- friend class Node;
- friend class Operations;
- friend class Cursor;
-
- class Node : public IHashKeyBagImpl::Node {
- friend class IGHashKeyBag < Element, Key, ElementOps >;
- friend class Cursor;
- friend class Operations;
-
- Element ivElement;
-
- Node (Element const& element)
- : ivElement (element) {};
-
- void* operator new (size_t s)
- { return cvElementOps.allocate (s); }
-
- void operator delete (void* p)
- { cvElementOps.deallocate (p); }
- };
-
- class Operations : public IHashKeyBagImpl::Operations {
-
- IHashKeyBagImpl::Node*
- newNode (void const* element) const;
- IHashKeyBagImpl::Node*
- copyNode (void const* node) const;
- void deleteNode (void* node) const;
-
- void* newBlock (size_t size) const;
- void removeBlock (void*, size_t size) const;
-
- INumber getHashvalue (void const* key, INumber) const;
-
- void* elementAt (void *node) const;
- void const* constElementAt (void const* node) const;
- void const* keyAt (void const* node) const;
- Boolean isKeyEqualTo (void const* node1,
- void const* node2) const;
- Boolean isKeyEqualToElement (void const* node,
- void const* element) const;
- Boolean isKeyEqualToKey (void const* node,
- void const* key) const;
- Boolean isEqualTo (void const* node1,
- void const* node2) const;
- Boolean isEqualToElement (void const* node,
- void const* element) const;
- void copyFrom (void* node,
- void const* element) const;
-
- Boolean constantFunctionIteration (void *function,
- void* env,
- void const* node);
- Boolean functionIteration (void *function,
- void* env,
- void* node);
- Boolean constantIteratorIteration (void* iterator,
- void const* node);
- Boolean iteratorIteration (void* iterator,
- void* node);
-
- long functionComparison (void *compareFunction,
- void const* node1,
- void const* node2);
- };
-
- // ivOps must be initialized (and therefore declared) before ivImpl
- // since the constructor of ivImpl uses ivOps.
- Operations ivOps;
- IHashKeyBagImpl ivImpl;
-
- public:
-
- class Cursor : public ICursor {
- protected:
- IGHashKeyBag < Element, Key, ElementOps > const* ivCollection;
- IHashKeyBagImpl::Cursor ivImpl;
- friend class IGHashKeyBag < Element, Key, ElementOps >;
-
- public:
- Cursor (IGHashKeyBag < Element, Key, ElementOps > const& collection)
- : ivCollection (&collection) {};
-
- Boolean setToFirst ();
- Boolean setToNext ();
- Boolean isValid () const;
- void invalidate ();
-
- Element const& element ()
- { return ivCollection->elementAt (*this); }
-
- Boolean operator== (Cursor const& cursor)
- { return ivCollection == cursor.ivCollection &&
- ivImpl == cursor.ivImpl; }
- Boolean operator!= (Cursor const& cursor)
- { return ! operator== (cursor); }
- };
-
- private:
-
- void checkNotEmpty () const;
- void checkCursorIsForThis (ICursor const&) const;
- void checkCursor (ICursor const&) const;
-
- public:
-
- IGHashKeyBag (INumber
- numberOfElements = 100,
- IBoundIndicator =
- IUnbounded);
-
- IGHashKeyBag (IGHashKeyBag < Element, Key, ElementOps > const&);
-
- IGHashKeyBag < Element, Key, ElementOps >& operator = (IGHashKeyBag < Element, Key, ElementOps > const&);
-
- ~IGHashKeyBag ();
-
- Boolean add (Element const&);
-
- Boolean add (Element const&,
- ICursor&);
-
- void addAllFrom (IGHashKeyBag < Element, Key, ElementOps > const&);
-
- Element const& elementAt (ICursor const&) const;
-
- Element& elementAt (ICursor const&);
-
- Element const& anyElement () const;
-
- void removeAt (ICursor const&);
-
- INumber removeAll (Boolean (*property)
- (Element const&, void*),
- void* additionalArgument = 0);
-
- void replaceAt (ICursor const&,
- Element const&);
-
- void removeAll ();
-
- Boolean isBounded () const;
-
- INumber maxNumberOfElements () const;
-
- INumber numberOfElements () const;
-
- Boolean isEmpty () const;
-
- Boolean isFull () const;
-
- ICursor* newCursor () const;
-
- Boolean setToFirst (ICursor&) const;
-
- Boolean setToNext (ICursor&) const;
-
- Boolean allElementsDo (Boolean (*function)
- (Element&, void*),
- void* additionalArgument = 0);
-
- Boolean allElementsDo (IIterator <Element>&);
-
- Boolean allElementsDo (Boolean (*function)
- (Element const&, void*),
- void* additionalArgument = 0)
- const;
-
- Boolean allElementsDo (IConstantIterator
- <Element>&) const;
-
- Key const& key (Element const&) const;
-
- Boolean containsElementWithKey (Key const&) const;
-
- Boolean containsAllKeysFrom (IGHashKeyBag < Element, Key, ElementOps > const&) const;
-
- Boolean locateElementWithKey (Key const&, ICursor&)
- const;
-
- Boolean replaceElementWithKey (Element const&);
-
- Boolean replaceElementWithKey (Element const&,
- ICursor&);
-
- Boolean locateOrAddElementWithKey (Element const&);
-
- Boolean locateOrAddElementWithKey (Element const&,
- ICursor&);
-
- Boolean addOrReplaceElementWithKey (Element const&);
-
- Boolean addOrReplaceElementWithKey (Element const&,
- ICursor&);
-
- Boolean removeElementWithKey (Key const&);
-
- Element const& elementWithKey (Key const&) const;
-
- Element& elementWithKey (Key const&);
-
- INumber numberOfElementsWithKey (Key const&) const;
-
- Boolean locateNextElementWithKey (Key const&,
- ICursor&) const;
-
- INumber removeAllElementsWithKey (Key const&);
-
- INumber numberOfDifferentKeys () const;
-
- Boolean setToNextWithDifferentKey (ICursor&) const;
-
- };
-
- template < class Element, class Key >
- class IHashKeyBag :
- public IGHashKeyBag < Element, Key, IKEHOps < Element, Key > > {
- public:
- IHashKeyBag (INumber n = 100, IBoundIndicator b = IUnbounded) :
- IGHashKeyBag < Element, Key, IKEHOps < Element, Key > > (n, b) {}
- };
-
- #include <ihshkb.if>
-
- #ifdef __IBMCPP__
- #include <ihshkb.c>
- #endif
-
- #endif