home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / ifl / iflHashTable.z / iflHashTable
Encoding:
Text File  |  1998-10-20  |  9.2 KB  |  265 lines

  1.  
  2.  
  3.  
  4. iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))   IIIImmmmaaaaggggeeee FFFFoooorrrrmmmmaaaatttt LLLLiiiibbbbrrrraaaarrrryyyy CCCC++++++++ RRRReeeeffffeeeerrrreeeennnncccceeee MMMMaaaannnnuuuuaaaallll    iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee,,,, iiiiffffllllHHHHaaaasssshhhhEEEElllleeeemmmm - base classes from which hash table
  10.      implementations may be derived
  11.  
  12. IIIINNNNHHHHEEEERRRRIIIITTTTSSSS FFFFRRRROOOOMMMM
  13.      This is a base class.
  14.  
  15. HHHHEEEEAAAADDDDEEEERRRR FFFFIIIILLLLEEEE
  16.      #include <ifl/iflHashTable.h>
  17.  
  18. CCCCLLLLAAAASSSSSSSS DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  19.      This class implements an abstract hash-based lookup table.  To create a
  20.      hash table, a derived class must be defined that specifies the pure
  21.      virtual mmmmaaaattttcccchhhh() method.  In addition, a hash function must be defined and
  22.      used to fill in the _h_a_s_h_I_n_d_e_x field of any hash table elements (derived
  23.      from iflHashElem) that are to be inserted into the table.  The mmmmaaaattttcccchhhh()
  24.      method is then used to compare elements when a collision occurs on the
  25.      _h_a_s_h_I_n_d_e_x field.
  26.  
  27.      The iflHashElem class is defined as:
  28.  
  29.           struct iflHashElem {
  30.               unsigned int hashIndex;
  31.           };
  32.  
  33.      It is used as a base from which to derive classes of elements to be
  34.      inserted into a hash table derived from iflHashTable.  The constructor of
  35.      the derived class should fill in the _h_a_s_h_I_n_d_e_x field with an appropriate
  36.      unsigned integer value for the hash index.  The hash function used to map
  37.      a hash element to its hash index must be carefully chosed to minimize
  38.      collisions (different elements mapping to the same index) to get the best
  39.      performance from the hash table.
  40.  
  41. CCCCLLLLAAAASSSSSSSS MMMMEEEEMMMMBBBBEEEERRRR FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN SSSSUUUUMMMMMMMMAAAARRRRYYYY
  42.      CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  43.  
  44.           iflHashTable(int maxEntries=0)
  45.  
  46.      MMMMaaaannnniiiippppuuuullllaaaattttiiiinnnngggg
  47.  
  48.           void clear()
  49.           int insert(iflHashElem* elem)
  50.           int remove(iflHashElem* elem)
  51.  
  52.  
  53.      QQQQuuuueeeerrrryyyy
  54.  
  55.           iflHashElem* find(unsigned int index, const void* key)
  56.           iflHashElem* next(int& index)
  57.           float getFullFraction() const
  58.           void setFullFraction(const float frac)
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))   IIIImmmmaaaaggggeeee FFFFoooorrrrmmmmaaaatttt LLLLiiiibbbbrrrraaaarrrryyyy CCCC++++++++ RRRReeeeffffeeeerrrreeeennnncccceeee MMMMaaaannnnuuuuaaaallll    iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))
  71.  
  72.  
  73.  
  74.      KKKKeeeeyyyy mmmmaaaattttcccchhhhiiiinnnngggg
  75.  
  76.           virtual int match(const void* key,                   _p_r_o_t_e_c_t_e_d
  77.                             const iflHashElem* elem) = 0
  78.  
  79.  
  80.      PPPPeeeerrrrffffoooorrrrmmmmaaaannnncccceeee SSSSttttaaaattttiiiissssttttiiiiccccssss
  81.  
  82.           int lookCount;
  83.           int totalLook;
  84.           int maxLook;
  85.           void clearStats()
  86.  
  87.  
  88. FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNN DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNNSSSS
  89.      iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee(((())))
  90.  
  91.           iflHashTable(int maxEntries=0)
  92.  
  93.  
  94.           Creates an empty iflHashTable, with initial size large enough to
  95.           hold _m_a_x_E_n_t_r_i_e_s; the default value of zero will create a table with
  96.           131 slots.  By default the hash table will automatically grow when
  97.           it gets more than half full.  See sssseeeettttFFFFuuuullllllllFFFFrrrraaaaccccttttiiiioooonnnn() for more
  98.           details.
  99.  
  100.      cccclllleeeeaaaarrrr(((())))
  101.  
  102.           void clear()
  103.  
  104.  
  105.           Removes all elements currently in the hash table.
  106.  
  107.      ffffiiiinnnndddd(((())))
  108.  
  109.           iflHashElem* find(unsigned int index, const void* key)
  110.  
  111.  
  112.           Finds the element with hash index, _i_n_d_e_x, and key value, _k_e_y.
  113.  
  114.      ggggeeeettttFFFFuuuullllllllFFFFrrrraaaaccccttttiiiioooonnnn(((())))
  115.  
  116.           float getFullFraction() const
  117.  
  118.  
  119.           Returns the current fraction of the table, which when filled will
  120.           cause the hash table to be expanded.  The default value is .5 (50%).
  121.  
  122.      iiiinnnnsssseeeerrrrtttt(((())))
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))   IIIImmmmaaaaggggeeee FFFFoooorrrrmmmmaaaatttt LLLLiiiibbbbrrrraaaarrrryyyy CCCC++++++++ RRRReeeeffffeeeerrrreeeennnncccceeee MMMMaaaannnnuuuuaaaallll    iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))
  137.  
  138.  
  139.  
  140.           void insert(iflHashElem* elem)
  141.  
  142.  
  143.           Inserts the hash element, _e_l_e_m, into the hash table.  The _h_a_s_h_I_n_d_e_x
  144.           field must already be filled in.
  145.  
  146.      mmmmaaaattttcccchhhh(((())))
  147.  
  148.           virtual int match(const void* key,                   _p_r_o_t_e_c_t_e_d
  149.                             const iflHashElem* elem) = 0
  150.  
  151.  
  152.           This function is used to compare an element key, _k_e_y, with the key
  153.           of another element, _e_l_e_m.  This function must be defined in any
  154.           class derived from iflHashTable.
  155.  
  156.      nnnneeeexxxxtttt(((())))
  157.  
  158.           iflHashElem* next(int& index)
  159.  
  160.  
  161.           This function is used to iterate through the filled entries of a
  162.           hash table.  To start iterating, _i_n_d_e_x should be initiliazed to
  163.           zero.  The index should not be altered on subsequent calls, as
  164.           iflHashTable uses it to keep track of where it is in the table.  The
  165.           returned value is a pointer to the next hash element in the table,
  166.           or NULL, when there are no more entries left to iterate on in the
  167.           table.
  168.  
  169.      rrrreeeemmmmoooovvvveeee(((())))
  170.  
  171.           void remove(iflHashElem* elem)
  172.  
  173.  
  174.           This function is used to remove the hash table element, _e_l_e_m, from
  175.           the table.
  176.  
  177.      sssseeeettttFFFFuuuullllllllFFFFrrrraaaaccccttttiiiioooonnnn(((())))
  178.  
  179.           void setFullFraction(const float frac)
  180.  
  181.  
  182.           Sets the current fraction of the table, which when filled will cause
  183.           the hash table to be expanded.  The default value is .5 (50%).  If
  184.           _f_r_a_c is 1, the hash table will not grow, and iiiinnnnsssseeeerrrrtttt() will fail when
  185.           the table is full.
  186.  
  187.      cccclllleeeeaaaarrrrSSSSttttaaaattttssss(((())))
  188.  
  189.           void clearStats()
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))   IIIImmmmaaaaggggeeee FFFFoooorrrrmmmmaaaatttt LLLLiiiibbbbrrrraaaarrrryyyy CCCC++++++++ RRRReeeeffffeeeerrrreeeennnncccceeee MMMMaaaannnnuuuuaaaallll    iiiiffffllllHHHHaaaasssshhhhTTTTaaaabbbblllleeee((((3333))))
  203.  
  204.  
  205.  
  206.           Resets the lookCount, totalLook, and maxLook member variables to
  207.           zero.  lookCount holds a running total of the number of lookups
  208.           (calls to ffffiiiinnnndddd() or llllooooccccaaaatttteeee()).  totalLook holds the number of hashes
  209.           and rehashes accumulated over all lookups.  maxLook holds the
  210.           maximum number of rehashes ever required by a single lookup.
  211.  
  212. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  213.      iflDictionary
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.