home *** CD-ROM | disk | FTP | other *** search
/ cs.rhul.ac.uk / www.cs.rhul.ac.uk.zip / www.cs.rhul.ac.uk / pub / rdp / rdp_cs3470.tar / rdp_supp / symbol.h < prev    next >
C/C++ Source or Header  |  1998-05-07  |  4KB  |  78 lines

  1. /*******************************************************************************
  2. *
  3. * RDP release 1.50 by Adrian Johnstone (A.Johnstone@rhbnc.ac.uk) 20 December 1997
  4. *
  5. * symbol.h - hash coded symbol table management
  6. *
  7. * This file may be freely distributed. Please mail improvements to the author.
  8. *
  9. *******************************************************************************/
  10. #ifndef SYMBOL_H
  11. #define SYMBOL_H
  12.  
  13. #include <stddef.h>
  14.  
  15. enum SYMBOL_FIND_OP{SYMBOL_NEW, SYMBOL_OLD, SYMBOL_ANY}; 
  16.  
  17. int symbol_compare_double(void * left, void * right); 
  18. int symbol_compare_double_reverse(void * left, void * right); 
  19. int symbol_compare_long(void * left, void * right); 
  20. int symbol_compare_long_reverse(void * left, void * right); 
  21. int symbol_compare_string(void * left, void * right); 
  22. int symbol_compare_string_reverse(void * left, void * right); 
  23.  
  24. void * symbol_find(const void * table, void * key, size_t key_size, size_t symbol_size, void * scope, enum SYMBOL_FIND_OP op); 
  25.  
  26. void symbol_free_scope(const void * scope);  /* release all memory in a scope */
  27. void symbol_free_symbol(void * symbol);  /* release memory allocated to symbol */
  28. void symbol_free_table(void * table);  /* release all memory in a table */
  29.  
  30. void * symbol_get_scope(const void * table);  /* return current scope */
  31.  
  32. unsigned symbol_hash_double(unsigned hash_prime, void * data); 
  33. unsigned symbol_hash_long(unsigned hash_prime, void * data); 
  34. unsigned symbol_hash_mem(unsigned hash_prime, void * data); 
  35. unsigned symbol_hash_string(unsigned hash_prime, void * data);  /* hash a null terminated string */
  36.  
  37. void * symbol_insert_key(const void * table, void * key, size_t key_size, size_t symbol_size);  /* lookup key in table. Return NULL if not found */
  38. void * symbol_insert_symbol(const void * table, void * symbol);  /* insert a symbol at head of hash list */
  39.  
  40. void * symbol_lookup_key(const void * table, void * key, void * scope);  /* lookup key in table. Return NULL if not found */
  41.  
  42. void * symbol_new_scope(void * table, char * str);  /* make a new scope symbol */
  43. void * symbol_new_symbol(size_t size);  /* make a new symbol */
  44. void * symbol_new_table(char * name, 
  45. const unsigned symbol_hashsize, 
  46. const unsigned symbol_hashprime, 
  47. int(* compare)(void * left_symbol, void * right_symbol), 
  48. unsigned(* hash)(unsigned hash_prime, void * data), 
  49. void(* print)(const void * symbol));  /* create a new symbol table */
  50.  
  51. void * symbol_next_symbol(void * table, void * symbol);  /* lookup along table from s for next identical key. Return NULL if not found */
  52. void * symbol_next_symbol_in_scope(void * symbol);  /* Return next symbol in scope chain. Return NULL if at end */
  53.  
  54. void symbol_print_all_table(void);  /* diagnostic dump of all symbol tables */
  55. void symbol_print_all_table_statistics(const unsigned histogram_size);  /* dump all bucket usage histograms */
  56.  
  57. void symbol_print_double(const void * symbol);  /* print a pointer to a long */
  58. void symbol_print_long(const void * symbol);  /* print a pointer to a long */
  59. void symbol_print_string(const void * symbol);  /* print a pointer to a string */
  60.  
  61. void symbol_print_scope(const void * table, void * scope);  /* diagnostic print of a complete scope */
  62. void symbol_print_symbol(const void * table, const void * symbol);  /* print a single symbol */
  63. void symbol_print_table(const void * table);  /* diagnostic dump of symbol table */
  64. void symbol_print_table_statistics(const void * table, const unsigned histogram_size);  /* dump bucket usage histogram */
  65.  
  66. void symbol_set_scope(void * table, void * scope);  /* set new current scope */
  67.  
  68. void symbol_sort_table(void * table);  /* sort all scopes in a table into alphabetical order */
  69. void symbol_sort_scope(void * table, void * scope);  /* sort scope into alphabetical order */
  70.  
  71. void symbol_unlink_scope(void * data);  /* remove an entire scope */
  72. void symbol_unlink_symbol(void * data);  /* remove a symbol */
  73. void symbol_unlink_table(void * table);  /* remove an entire table */
  74.  
  75. #endif
  76.  
  77. /* End of symbol.h */
  78.