chiark / gitweb /
Headers: Guard inclusion of mLib headers.
[mLib] / hash.c
diff --git a/hash.c b/hash.c
index 96c150bf7c9ca09a9c20eea77f5f1e68e4657979..d4df9b7ce074882b2a1b45e5bcdf2496d210c174 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id: hash.c,v 1.1 1999/08/02 14:45:48 mdw Exp $
  *
  * General hashtable infrastructure
  *
  * (c) 1999 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * mLib is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with mLib; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: hash.c,v $
- * Revision 1.1  1999/08/02 14:45:48  mdw
- * Break low-level hashtable code out from sym.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <stdio.h>
 #include <string.h>
 
 #include "alloc.h"
+#include "arena.h"
 #include "bits.h"
 #include "exc.h"
 #include "hash.h"
-#include "track.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
 void hash_create(hash_table *t, size_t n)
 {
   hash_base **v;
-  TRACK_CTX("hashtable creation");
-  TRACK_PUSH;
-  t->v = xmalloc(n * sizeof(hash_base *));
+
+  t->a = arena_global;
+  t->v = x_alloc(t->a, n * sizeof(hash_base *));
   t->mask = n - 1;
   for (v = t->v; n; v++, n--)
     *v = 0;
-  TRACK_POP;
 }
 
 /* --- @hash_destroy@ --- *
@@ -83,13 +72,7 @@ void hash_create(hash_table *t, size_t n)
  *             responsibility of the implementation.
  */
 
-void hash_destroy(hash_table *t)
-{
-  TRACK_CTX("hashtable destruction");
-  TRACK_PUSH;
-  free(t->v);
-  TRACK_POP;
-}
+void hash_destroy(hash_table *t) { x_free(t->a, t->v); }
 
 /* --- @hash_bin@ --- *
  *
@@ -103,9 +86,7 @@ void hash_destroy(hash_table *t)
  */
 
 hash_base **hash_bin(hash_table *t, uint32 hash)
-{
-  return (HASH_BIN(t, hash));
-}
+  { return (HASH_BIN(t, hash)); }
 
 /* --- @hash_extend@ --- *
  *
@@ -123,15 +104,11 @@ int hash_extend(hash_table *t)
   uint32 m = t->mask + 1;
   size_t i;
 
-  /* --- Push in a tracking context --- */
-
-  TRACK_CTX("hashtable extension");
-  TRACK_PUSH;
-
   /* --- Allocate a new hash bin vector --- */
 
-  if ((v = realloc(t->v, m * 2 * sizeof(hash_base *))) == 0) {
-    TRACK_POP;
+  if ((v = A_REALLOC(t->a, t->v,
+                    2 * m * sizeof(hash_base *),
+                    m * sizeof(hash_base *))) == 0) {
     return (0);
   }
   t->v = v;
@@ -156,7 +133,6 @@ int hash_extend(hash_table *t)
     *q = 0;
   }
 
-  TRACK_POP;
   return (1);
 }