home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxk / iihshkb.h__ / IIHSHKB.H
Encoding:
C/C++ Source or Header  |  1992-10-26  |  7.6 KB  |  216 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2. #ifndef _IIHSHKB_H
  3. #define _IIHSHKB_H
  4.  
  5. #include <stdlib.h>
  6. #include <iglobals.h>
  7.  
  8. class IHashKeyBagImpl {
  9. public:
  10.  
  11.   class Node {
  12.     friend class IHashKeyBagImpl;
  13.     Node* ivNext;
  14.   };
  15.  
  16.   class Operations {
  17.     virtual Node*    newNode              (void const* element) const = 0;
  18.     virtual Node*    copyNode             (void const* node) const = 0;
  19.     virtual void     deleteNode           (void* node) const = 0;
  20.  
  21.     virtual void*    newBlock             (size_t) const = 0;
  22.     virtual void     removeBlock          (void*, size_t) const = 0;
  23.  
  24.     virtual INumber  getHashvalue         (void const* key, INumber) const = 0;
  25.  
  26.     virtual void*    elementAt            (void* node) const = 0;
  27.     virtual void const*
  28.              constElementAt       (void const* node) const = 0;
  29.     virtual void const*
  30.              keyAt                (void const* node) const = 0;
  31.     virtual Boolean  isKeyEqualTo         (void const* node1,
  32.                        void const* node2) const = 0;
  33.     virtual Boolean  isKeyEqualToElement  (void const* node,
  34.                        void const* element) const = 0;
  35.     virtual Boolean  isKeyEqualToKey      (void const* node,
  36.                        void const* key) const = 0;
  37.     virtual void     copyFrom             (void* node,
  38.                        void const* element) const = 0;
  39.     virtual Boolean  constantFunctionIteration
  40.                                           (void *function,
  41.                                            void* env,
  42.                                            void const* node) = 0;
  43.     virtual Boolean  functionIteration    (void *function,
  44.                                            void* env,
  45.                                            void* node) = 0;
  46.     virtual Boolean  constantIteratorIteration
  47.                           (void* iterator,
  48.                                            void const* node) = 0;
  49.     virtual Boolean  iteratorIteration    (void* iterator,
  50.                                            void* node) = 0;
  51.  
  52.     virtual long     functionComparison   (void *compareFunction,
  53.                                            void const* node1,
  54.                                            void const* node2) = 0;
  55.     friend class IHashKeyBagImpl;
  56.   };
  57.  
  58.   class Cursor {
  59.   public:
  60.     INumber ivEntryNumber;
  61.     Node* ivNode;
  62.  
  63.     Cursor () : ivNode (0) {}
  64.  
  65.     Boolean operator== (Cursor const& cursor)
  66.     { return ivNode == cursor.ivNode &&
  67.              ivEntryNumber == cursor.ivEntryNumber; }
  68.     Boolean operator!= (Cursor const& cursor)
  69.     { return ! operator== (cursor); }
  70.   };
  71.  
  72. private :
  73.  
  74.    Operations*         ivOps;
  75.    INumber             ivNoEntries;
  76.    INumber             ivNoElements;
  77.    Node**              ivTable;
  78.    INumber*            ivCollList;
  79.  
  80.    void                createHashtable     (INumber);
  81.  
  82.    void                copyHashtable       (IHashKeyBagImpl const&);
  83.  
  84. public:
  85.  
  86.                        IHashKeyBagImpl      (INumber, Operations*);
  87.  
  88.                        IHashKeyBagImpl      (IHashKeyBagImpl const&, Operations*);
  89.  
  90.                       ~IHashKeyBagImpl      ();
  91.  
  92.    Boolean             add                 (void const* element,
  93.                                             INumber,
  94.                                             Cursor&);
  95.  
  96.    Boolean             add                 (void const* element,
  97.                                             INumber);
  98.  
  99.    void                addAllFrom          (IHashKeyBagImpl const&);
  100.  
  101.    IHashKeyBagImpl&     operator=           (IHashKeyBagImpl const&);
  102.  
  103.    void const*         elementAt           (Cursor const&) const;
  104.  
  105.    void*               elementAt           (Cursor const&);
  106.  
  107.    void const*         anyElement          () const;
  108.  
  109.    void                removeAt            (Cursor const&);
  110.  
  111.    INumber             removeAll           (void* predicate,
  112.                                             void* environment);
  113.  
  114.    void                replaceAt           (Cursor const&,
  115.                                             void const* element);
  116.  
  117.    void                removeAll           ();
  118.  
  119.    Boolean             isBounded           () const;
  120.  
  121.    INumber             maxNumberOfElements () const;
  122.  
  123.    INumber             numberOfElements    () const;
  124.  
  125.    Boolean             isEmpty             () const;
  126.  
  127.    Boolean             isFull              () const;
  128.  
  129.    Boolean             setToFirst          (Cursor&) const;
  130.  
  131.    Boolean             setToNext           (Cursor&) const;
  132.  
  133.    Boolean             allElementsDo       (void* function,
  134.                                             void* environment) const;
  135.  
  136.    Boolean             allElementsDo       (void* function,
  137.                                             void* environment);
  138.  
  139.    Boolean             allElementsDo       (void* iterator) const;
  140.  
  141.    Boolean             allElementsDo       (void* iterator);
  142.  
  143. // Keycollection methods
  144. public:
  145.    Boolean             containsAllKeysFrom (IHashKeyBagImpl const&) const;
  146.  
  147.    Boolean             containsElementWithKey
  148.                                            (void const* key, INumber)const;
  149.  
  150.    INumber             numberOfElementsWithKey
  151.                                            (void const* key, INumber) const;
  152.  
  153.    Boolean             locateElementWithKey(void const* key,
  154.                                             INumber,
  155.                                             Cursor&) const;
  156. private:
  157.    Boolean             locateElementWithKeyOfElement
  158.                                            (void const* element,
  159.                                             INumber,
  160.                                             Cursor&) const;
  161. public:
  162.    Boolean             replaceElementWithKey
  163.                                            (void const* element,
  164.                                             INumber,
  165.                                             Cursor&);
  166.  
  167.    Boolean             replaceElementWithKey
  168.                                            (void const* element,
  169.                                             INumber);
  170.  
  171.    Boolean             locateOrAddElementWithKey
  172.                                            (void const* element,
  173.                                             INumber,
  174.                                             Cursor&);
  175.  
  176.    Boolean             locateOrAddElementWithKey
  177.                                            (void const* element,
  178.                                             INumber);
  179.  
  180.    Boolean             addOrReplaceElementWithKey
  181.                                            (void const* element,
  182.                                             INumber,
  183.                                             Cursor&);
  184.  
  185.    Boolean             addOrReplaceElementWithKey
  186.                                            (void const* element,
  187.                                             INumber);
  188.  
  189.    Boolean             removeElementWithKey(void const* key, INumber);
  190.  
  191.    void const*         elementWithKey      (void const* key, INumber)const;
  192.  
  193.    void*               elementWithKey      (void const* key, INumber);
  194.  
  195.    Boolean             locateNextElementWithKey
  196.                                            (void const* key,
  197.                                             INumber,
  198.                                             Cursor&) const;
  199.  
  200.    INumber             removeAllElementsWithKey
  201.                                            (void const* key, INumber);
  202.  
  203.    INumber             numberOfDifferentKeys
  204.                        () const;
  205.  
  206.    Boolean             setToNextWithDifferentKey
  207.                        (Cursor&) const;
  208.  
  209.    INumber             noEntries           () const;
  210.  
  211.    Boolean             checkCursor         (Cursor const&) const;
  212.  
  213. };
  214.  
  215. #endif
  216.