chiark / gitweb /
Change header file guard names.
[mLib] / sym.h
diff --git a/sym.h b/sym.h
index 94d43c51847047348f0d9e6e1765bae0cf122ee9..7dd9217c38e532cd06a2f9da8a336a3f20beda11 100644 (file)
--- a/sym.h
+++ b/sym.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sym.h,v 1.7 1999/06/01 09:49:33 mdw Exp $
+ * $Id: sym.h,v 1.10 1999/12/10 23:42:04 mdw Exp $
  *
  * Symbol table management
  *
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: sym.h,v $
+ * Revision 1.10  1999/12/10 23:42:04  mdw
+ * Change header file guard names.
+ *
+ * Revision 1.9  1999/08/02 16:53:48  mdw
+ * Improve type safety for sym_iter objects.
+ *
+ * Revision 1.8  1999/08/02 14:45:48  mdw
+ * Break low-level hashtable code out from sym.
+ *
  * Revision 1.7  1999/06/01 09:49:33  mdw
  * Allow things to be looked up by just their caller-supplied hashes.  This
  * actually needs to be thought through better.
@@ -54,8 +63,8 @@
  *
  */
 
-#ifndef SYM_H
-#define SYM_H
+#ifndef MLIB_SYM_H
+#define MLIB_SYM_H
 
 #ifdef __cplusplus
   extern "C" {
 
 #include <stddef.h>
 
-#ifndef BITS_H
+#ifndef MLIB_BITS_H
 #  include "bits.h"
 #endif
 
+#ifndef MLIB_HASH_H
+#  include "hash.h"
+#endif
+
 /*----- Type definitions --------------------------------------------------*/
 
 /* --- Symbol table --- *
@@ -79,9 +92,8 @@
  */
 
 typedef struct sym_table {
-  unsigned long mask;                  /* Bit mask for hashing purposes */
-  size_t c;                            /* Down counter for growing table */
-  struct sym_base **a;                 /* Array of hash bins */
+  hash_table t;
+  size_t load;
 } sym_table;
 
 /* --- A symbol table entry --- *
@@ -96,8 +108,7 @@ typedef struct sym_table {
 #define SYM_BUFSZ 16                   /* Size of local string buffer */
 
 typedef struct sym_base {
-  struct sym_base *next;               /* Next symbol in hash bin */
-  uint32 hash;                         /* Hash value for symbol's name */
+  hash_base b;
   union {
     char *p;                           /* Pointer to name string */
     char b[SYM_BUFSZ];                 /* Buffer containing a short name */
@@ -114,11 +125,7 @@ typedef struct sym_base {
 
 /* --- An iterator block --- */
 
-typedef struct sym_iter {
-  sym_table *t;                                /* Symbol table being iterated */
-  sym_base *n;                         /* Address of next item to return */
-  size_t i;                            /* Index of next hash bin to use */
-} sym_iter;
+typedef struct { hash_iter i; } sym_iter;
 
 /*----- External functions ------------------------------------------------*/
 
@@ -162,9 +169,7 @@ extern void sym_destroy(sym_table */*t*/);
  *             may be given, in which case the name may contain arbitrary
  *             binary data, or it may be given as a negative number, in
  *             which case the length of the name is calculated as
- *             @strlen(n) + 1@.  The name pointer @n@ may also be zero; in
- *             this case, @l@ is taken to be a raw hash, and any element
- *             with a matching hash is taken to be the one wanted.
+ *             @strlen(n) + 1@.
  *
  *             The return value is the address of a pointer to a @sym_base@
  *             block (which may have other things on the end, as above).  If
@@ -184,7 +189,7 @@ extern void *sym_find(sym_table */*t*/, const char */*n*/, long /*l*/,
 
 /* --- @sym_remove@ --- *
  *
- * Arguments:  @sym_table *i@ = pointer to a symbol table object
+ * Arguments:  @sym_table *t@ = pointer to a symbol table object
  *             @void *b@ = pointer to symbol table entry
  *
  * Returns:    ---
@@ -207,6 +212,8 @@ extern void sym_remove(sym_table */*t*/, void */*b*/);
  *             iterate through a symbol table.
  */
 
+#define SYM_MKITER(i_, t_) HASH_MKITER(&(i_)->i, &(t_)->t)
+
 extern void sym_mkiter(sym_iter */*i*/, sym_table */*t*/);
 
 /* --- @sym_next@ --- *
@@ -219,6 +226,12 @@ extern void sym_mkiter(sym_iter */*i*/, sym_table */*t*/);
  *             returned in any particular order.
  */
 
+#define SYM_NEXT(i_, p) do {                                           \
+  hash_base *_q;                                                       \
+  HASH_NEXT(&(i_)->i, _q);                                             \
+  (p) = (void *)_q;                                                    \
+} while (0)
+
 extern void *sym_next(sym_iter */*i*/);
 
 /*----- That's all, folks -------------------------------------------------*/