home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / som / include / thash.idl < prev    next >
Text File  |  1999-02-22  |  10KB  |  277 lines

  1. //#  @(#) 2.12 src/somuc/thash.idl, somuc, som2.1 12/26/95 15:37:44 [7/30/96 14:50:05]
  2. //
  3. //   COMPONENT_NAME: somuc
  4. //
  5. //   ORIGINS: 82, 81, 27
  6. //
  7. //
  8. //    25H7912  (C)  COPYRIGHT International Business Machines Corp. 1992,1996,1996  
  9. //   All Rights Reserved
  10. //   Licensed Materials - Property of IBM
  11. //   US Government Users Restricted Rights - Use, duplication or
  12. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  13. //
  14. //   Copyright ⌐ 1988, 1989 Apple Computer, Inc. All rights reserved.
  15.  
  16. /*
  17.  * CLASS_NAME: somf_THashTable
  18.  *
  19.  * DESCRIPTION: Every Hash Table has a set of entries which associate a
  20.  *              key to a value.  Hash tables provide for fast lookup of a
  21.  *              value when given a key even if there are a large number of
  22.  *              entries in the table.  Functions are provided for the usual
  23.  *              things (insert, delete, etc.) as well as for controlling when
  24.  *              rehashing will occur, and the growth of the table when a
  25.  *              rehash occurs.
  26.  *
  27.  */
  28.  
  29. #ifndef THash_idl
  30. #define THash_idl
  31.  
  32. #include "mcollect.idl"
  33.  
  34. interface THAssoc;
  35.  
  36. interface somf_THashTable : somf_MCollectible
  37. {
  38.   const long kDefaultHashTableSize = 23;
  39.   const long kDefaultGrowthRate = 20;
  40.   const long kDefaultRehashThreshold = 80;
  41.   enum  ETableClassification { kUnchecked, kNormal, kFast };
  42.  
  43.   //#   friend class THashTableIterator;
  44.  
  45.   somf_THashTable somfTHashTableInitFLLL(in somf_MCollectible::somf_MCollectibleCompareFn testfn,
  46.                       in long tablesize,
  47.                       in long rate,
  48.                       in long threshold);
  49.  
  50.   // Initializes the new hash table.
  51.   //#   THashTable(MCollectibleCompareFn testfn = &MCollectible::IsSame,
  52.   //#      long tablesize=kDefaultHashTableSize,
  53.   //#      long rate=kDefaultGrowthRate, long threshold=kDefaultRehashThreshold);
  54.  
  55.   somf_THashTable somfTHashTableInitFLL(in somf_MCollectible::somf_MCollectibleCompareFn testfn,
  56.                      in long tablesize,
  57.                      in long rate);
  58.  
  59.   // Initializes the new hash table.
  60.   //#   THashTable(MCollectibleCompareFn testfn = &MCollectible::IsSame,
  61.   //#      long tablesize=kDefaultHashTableSize,
  62.   //#      long rate=kDefaultGrowthRate, long threshold=kDefaultRehashThreshold);
  63.  
  64.   somf_THashTable somfTHashTableInitFL(in somf_MCollectible::somf_MCollectibleCompareFn testfn,
  65.                     in long tablesize);
  66.  
  67.   // Initializes the new hash table.
  68.   //#   THashTable(MCollectibleCompareFn testfn = &MCollectible::IsSame,
  69.   //#      long tablesize=kDefaultHashTableSize,
  70.   //#      long rate=kDefaultGrowthRate, long threshold=kDefaultRehashThreshold);
  71.  
  72.   somf_THashTable somfTHashTableInitH(in somf_THashTable h);
  73.  
  74.   // Initializes the new hash table.
  75.   //#   THashTable(const THashTable&);
  76.  
  77.   void somfAssign(in somf_THashTable source);
  78.  
  79.   // Assign the instance of this equal to the instance of source.
  80.   //#   const THashTable&  operator=(const THashTable&);
  81.  
  82.   long somfCount();
  83.  
  84.   // Return the number of objects in this.
  85.   //#   long     Count() const;
  86.  
  87.   somf_MCollectible somfRemove(in somf_MCollectible key);
  88.  
  89.   // Remove obj from this.  Return the object which was actually removed
  90.   // (which if you are using an IsSame test function may not be the same
  91.   // as the object passed in only "equal").
  92.   //#   MCollectible*  Remove(const MCollectible& key);
  93.  
  94.   somf_MCollectible somfDelete(in somf_MCollectible key);
  95.  
  96.   // Remove key from this and deallocate the storage that these objects might
  97.   // have owned (that is, the destructor function is called for each object
  98.   // in the collection).  Return the object which was actually removed (which
  99.   // if you are using an IsSame test function may not be the same as the object
  100.   // passed in only "equal").
  101.   //#   MCollectible*  Delete(MCollectible* key);
  102.  
  103.   somf_MCollectible somfMember(in somf_MCollectible key);
  104.  
  105.   // Each object in this is compared to obj using the function testFn.  Return the
  106.   // object for which testFn returned TRUE.  Return SOMF_NIL if not object was found.
  107.   //#   MCollectible*  Member(const MCollectible& key) const;
  108.  
  109.   void somfRemoveAll();
  110.  
  111.   // Remove all of the objects from this.
  112.   //#   void     RemoveAll();
  113.  
  114.   void somfDeleteAll();
  115.  
  116.   // Remove all of the objects from this and deallocate the storage that these
  117.   // objects might have owned (that is, the destructor function is called
  118.   // for each object in the collection).
  119.   //#   void     DeleteAll();
  120.  
  121.   void somfDeleteAllKeys();
  122.  
  123.   // Remove all of the keys from this and deallocate the storage that these
  124.   // objects might have owned (that is, the destructor function is called
  125.   // for each object in the collection).
  126.   //#   void     DeleteAllKeys();
  127.  
  128.   void somfDeleteAllValues();
  129.  
  130.   // Remove all of the values from this and deallocate the storage that these
  131.   // objects might have owned (that is, the destructor function is called
  132.   // for each object in the collection).
  133.   //#   void     DeleteAllValues();
  134.  
  135.   somf_MCollectible somfAddMMB(in somf_MCollectible key,
  136.                 in somf_MCollectible value,
  137.                 in boolean replace);
  138.  
  139.   // Add key and value to this.  If replace = TRUE, replace a copy if it already
  140.   // exists.
  141.   //#   MCollectible*  Add(const MCollectible* key, MCollectible* value, Boolean replace = TRUE);
  142.  
  143.   somf_MCollectible somfAddMM(in somf_MCollectible key,
  144.                in somf_MCollectible value);
  145.  
  146.   // Add key and value to this.  Replace a copy if it already exists.
  147.   //#   MCollectible*  Add(const MCollectible* key, MCollectible* value, Boolean replace = TRUE);
  148.  
  149.   void somfGrow();
  150.  
  151.   // Grow the Hash Table
  152.   //#   void     Grow();
  153.  
  154.   somf_MCollectible somfRetrieve(in somf_MCollectible key);
  155.  
  156.   // Retrieve and return the value associated with key.
  157.   //#   MCollectible*  Retrieve(const MCollectible& key) const;
  158.  
  159.   void somfSetGrowthRate(in long rate);
  160.  
  161.   // Set the growth rate of the hash table.
  162.   //#   void     SetGrowthRate(long rate);
  163.  
  164.   void somfSetRehashThreshold(in long threshold);
  165.  
  166.   // Set the rehash threshold of the hash table.
  167.   //#   void     SetRehashThreshold(long threshold);
  168.  
  169.   long somfGetGrowthRate();
  170.  
  171.   // Return the growth rate of the hash table.
  172.   //#   long      GetGrowthRate() const;
  173.  
  174.   long somfGetRehashThreshold();
  175.  
  176.   // Return the rehash threshold of the hash table.
  177.   //#   long      GetRehashThreshold() const;
  178.  
  179.   void somfSetHashFunction(in somf_MCollectible::somf_MCollectibleHashFn fn);
  180.  
  181.   // Set the hash function to fn.
  182.   //#   void     SetHashFunction(MCollectibleHashFn);
  183.  
  184.   somf_MCollectible::somf_MCollectibleHashFn somfGetHashFunction();
  185.  
  186.   // Return the hash function.
  187.   //#   MCollectibleHashFn GetHashFunction() const;
  188.  
  189.   //#   override StreamOut;
  190.   //# // Stream stuff
  191.   //# //   virtual TStream&   operator>>=(TStream& towhere) const;
  192.   //#
  193.   //#   override StreamIn;
  194.   //# // Stream stuff
  195.   //# //   virtual TStream&   operator<<=(TStream& towhere);
  196.  
  197.   //#override somfClone;
  198.   //# There is no point in overriding somfClone, the code was fixed so it works
  199.   //# correctly.
  200.   //#   MCollectibleDeclarationsMacro(THashTable);
  201.  
  202.   //#
  203.   //# The following method has been commented out since the code for IsFastTable
  204.   //# is non-portable.  A Method that just returns FALSE doesn't have much use.
  205.   //#    Boolean     IsFastTable(const MCollectible* obj),private,nooverride,nomodify;
  206.   //# // private:
  207.   //# //   Boolean     IsFastTable(const MCollectible*) const;
  208.  
  209.  
  210.  
  211.  
  212. #ifdef __SOMIDL__
  213.   implementation {
  214.  
  215.     releaseorder: somfCount,somfRemove,somfDelete,somfMember,
  216.           somfRemoveAll,somfDeleteAll,somfDeleteAllKeys,
  217.           somfDeleteAllValues,somfAddMMB,somfAddMM,somfGrow,somfRetrieve,
  218.           somfSetGrowthRate,somfSetRehashThreshold,somfGetGrowthRate,
  219.           somfGetRehashThreshold,somfSetHashFunction,somfGetHashFunction,
  220.           somfFind,somfMakeNewTable,somfCopyIn,somfAssign,
  221.           somfTHashTableInitFLLL,somfTHashTableInitFLL,
  222.           somfTHashTableInitFL,somfTHashTableInitH;
  223.  
  224.     //# Class Modifiers
  225.     majorversion = 2;
  226.     minorversion = 1;
  227.     filestem = thash;
  228.     dllname = "somuc.dll";
  229.  
  230.  
  231.     //# Internal Instance Variables
  232.     long fTableSize;              // Actual physical size of the table
  233.     long fSize;                   // Number of entries in the table
  234.     long fGrowthRate;
  235.     long fRehashThreshold;
  236.     long fNextRehash;
  237.     THAssoc fTable;
  238.     somf_MCollectible::somf_MCollectibleCompareFn fTestfn;
  239.     somf_MCollectible::somf_MCollectibleHashFn fHashfn;
  240.     unsigned long fSeed;          // Count of operations on the table. Used by Iterator
  241.     ETableClassification fFast;
  242.  
  243.     //# Method Modifiers
  244.     somInit: override;
  245.     somUninit: override;
  246.     somfCount: nooverride, nomodify;
  247.     somfRemove: nooverride;
  248.     somfDelete: nooverride;
  249.     somfMember: nooverride, nomodify;
  250.     somfRemoveAll: nooverride;
  251.     somfDeleteAll: nooverride;
  252.     somfDeleteAllKeys: nooverride;
  253.     somfDeleteAllValues: nooverride;
  254.     somfAddMMB: nooverride;
  255.     somfAddMM: nooverride;
  256.     somfGrow: nooverride;
  257.     somfRetrieve: nooverride, nomodify;
  258.     somfSetGrowthRate: nooverride;
  259.     somfSetRehashThreshold: nooverride;
  260.     somfGetGrowthRate: nooverride, nomodify;
  261.     somfGetRehashThreshold: nooverride, nomodify;
  262.     somfSetHashFunction: nooverride;
  263.     somfGetHashFunction: nooverride, nomodify;
  264.     somfTHashTableInitFLLL: nooverride;
  265.     somfTHashTableInitFLL: nooverride;
  266.     somfTHashTableInitFL: nooverride;
  267.     somfTHashTableInitH: nooverride;
  268.  
  269.     //# Data Modifiers
  270.  
  271.  
  272.   };
  273. #endif /* __SOMIDL__ */
  274. };
  275.  
  276. #endif  /* THash_idl */
  277.