home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / SCL.EXE / SCL_HASH.H < prev    next >
C/C++ Source or Header  |  1994-08-06  |  3KB  |  120 lines

  1.  
  2. #ifndef SCL_HASH_H
  3. #define SCL_HASH_H
  4.  
  5. /*
  6. * NIST Utils Class Library
  7. * clutils/scl_hash.h
  8. * February, 1994
  9. * David Sauder
  10. * K. C. Morris
  11.  
  12. * Development of this software was funded by the United States Government,
  13. * and is not subject to copyright.
  14. */
  15.  
  16. /* $Id: scl_hash.h,v 2.0.1.1 1994/04/05 16:44:11 sauderd Exp $ */
  17.  
  18. /************************************************************************
  19. ** Hash_Table:    Hash_Table
  20. ** Description:    
  21. **    
  22. ** Largely based on code written by ejp@ausmelb.oz
  23. **
  24. ** Constants:
  25. **    HASH_TABLE_NULL    - the null Hash_Table
  26. **
  27. ************************************************************************/
  28.  
  29. /*
  30.  * This work was supported by the United States Government, and is
  31.  * not subject to copyright.
  32.  *
  33.  * $Log: scl_hash.h,v $
  34.  * Revision 2.0.1.1  1994/04/05  16:44:11  sauderd
  35.  * Changed the date from 1993 to 1994
  36.  *
  37.  * Revision 2.0.1.0  1994/02/04  21:32:20  sauderd
  38.  * Setting the first branch
  39.  *
  40.  * Revision 2.0  1994/02/04  21:32:18  sauderd
  41.  * STEP Class Library Release 2.0
  42.  *
  43.  * Revision 1.3  1994/09/30  20:58:22  sauderd
  44.  * Administrative stuff for the release.  Added the name of the file, library,
  45.  * the date, contact people, and $id $ for RCS.  Did general cleaning, etc.
  46.  *
  47.  * Revision 1.2  1992/12/15  14:07:52  kc
  48.  * made parameters to HASHfind and HASHinsert const
  49.  *
  50.  * Revision 1.1  1992/10/07  18:37:20  kc
  51.  * Initial revision
  52.  *
  53.  * Revision 1.1  1992/10/06  22:06:30  kc
  54.  * Initial revision
  55.  *
  56.  * Revision 1.1  1992/09/29  15:44:19  libes
  57.  * Initial revision
  58.  *
  59.  * Revision 1.1  1992/08/19  18:49:59  libes
  60.  * Initial revision
  61.  *
  62.  * Revision 1.2  1992/05/31  08:36:48  libes
  63.  * multiple files
  64.  * 
  65.  */
  66.  
  67. typedef enum { HASH_FIND, HASH_INSERT, HASH_DELETE } Action;
  68.  
  69. struct Element {
  70.     char        *key;
  71.     void        *data;
  72.     struct Element    *next;
  73.     struct Symbol    *symbol;/* for debugging hash conflicts */
  74.     char        type;    /* user-supplied type */
  75. };
  76.  
  77. struct Hash_Table {
  78.     short    p;        /* Next bucket to be split    */
  79.     short    maxp;        /* upper bound on p during expansion    */
  80.     long    KeyCount;    /* current # keys    */
  81.     short    SegmentCount;    /* current # segments    */
  82.     short    MinLoadFactor;
  83.     short    MaxLoadFactor;
  84. #define DIRECTORY_SIZE        256
  85. #define DIRECTORY_SIZE_SHIFT    8    /* log2(DIRECTORY_SIZE)    */
  86.     struct Element **Directory[DIRECTORY_SIZE];
  87. };
  88.  
  89. typedef struct {
  90.     int i;    /* segment index (i think) */
  91.     int j;    /* key index in segment (ditto) */
  92.     struct Element *p;    /* usually the next element to be returned */
  93.     struct Hash_Table *table;
  94.     char type;
  95.     struct Element *e;    /* originally thought of as a place for */
  96. /* the caller of HASHlist to temporarily stash the return value */
  97. /* to allow the caller (i.e., DICTdo) to be macroized, but now */
  98. /* conveniently used by HASHlist, which both stores the ultimate */
  99. /* value here as well as returns it via the return value of HASHlist */
  100. } HashEntry;
  101.  
  102. #ifdef __cplusplus
  103. extern "C" {
  104. #endif
  105.  
  106. struct Hash_Table    *HASHcreate(unsigned);
  107. void        *HASHfind(struct Hash_Table *,  char *);
  108. void        HASHinsert(struct Hash_Table *, char *,void *);
  109. void        HASHdestroy(struct Hash_Table *);
  110. struct Element    *HASHsearch(struct Hash_Table *,struct Element *, Action);
  111. void        HASHlistinit(struct Hash_Table *,HashEntry *);
  112. void        HASHlistinit_by_type(struct Hash_Table *,HashEntry *,char);
  113. struct Element    *HASHlist(HashEntry *);
  114.  
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118.  
  119. #endif /* SCL_HASH_H */
  120.