home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IIHSHKB.H < prev    next >
Text File  |  1993-09-22  |  9KB  |  224 lines

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