pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src/libpspp ChangeLog hash.c hash.h


From: John Darrington
Subject: [Pspp-cvs] pspp/src/libpspp ChangeLog hash.c hash.h
Date: Sun, 15 Oct 2006 01:51:02 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Changes by:     John Darrington <jmd>   06/10/15 01:51:02

Modified files:
        src/libpspp    : ChangeLog hash.c hash.h 

Log message:
        Added a pooled version of hsh_create

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/ChangeLog?cvsroot=pspp&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/hash.c?cvsroot=pspp&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/pspp/src/libpspp/hash.h?cvsroot=pspp&r1=1.3&r2=1.4

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/src/libpspp/ChangeLog,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- ChangeLog   31 Jul 2006 22:50:01 -0000      1.35
+++ ChangeLog   15 Oct 2006 01:51:02 -0000      1.36
@@ -1,3 +1,8 @@
+Sun Oct 15 09:49:50 WST 2006 John Darrington <address@hidden>
+
+       * hash.c hash.h: Added hsh_create_pool, a hash which uses a pool
+       for its memory allocation.
+
 Mon Jul 31 15:49:46 2006  Ben Pfaff  <address@hidden>
 
        * compiler.h: (macro CONST_FUNCTION) New macro.

Index: hash.c
===================================================================
RCS file: /sources/pspp/pspp/src/libpspp/hash.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- hash.c      14 Oct 2006 00:25:21 -0000      1.6
+++ hash.c      15 Oct 2006 01:51:02 -0000      1.7
@@ -31,6 +31,8 @@
 #include "compiler.h"
 #include "misc.h"
 #include "str.h"
+#include "pool.h"
+
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -159,14 +161,26 @@
        so that most hsh_*() functions may no longer be called. */
     bool hash_ordered;
 #endif
+
+    struct pool *pool;         /* The pool used for this hash table */
   };
 
+struct hsh_table *
+hsh_create (int size, hsh_compare_func *compare, hsh_hash_func *hash,
+            hsh_free_func *free, void *aux)
+{
+  return hsh_create_pool (NULL, size, compare, hash, free, aux);
+}
+
+
+
 /* Creates a hash table with at least M entries.  COMPARE is a
    function that compares two entries and returns 0 if they are
    identical, nonzero otherwise; HASH returns a nonnegative hash value
    for an entry; FREE destroys an entry. */
 struct hsh_table *
-hsh_create (int size, hsh_compare_func *compare, hsh_hash_func *hash,
+hsh_create_pool (struct pool *pool, int size, 
+                hsh_compare_func *compare, hsh_hash_func *hash,
             hsh_free_func *free, void *aux)
 {
   struct hsh_table *h;
@@ -175,12 +189,13 @@
   assert (compare != NULL);
   assert (hash != NULL);
   
-  h = xmalloc (sizeof *h);
+  h = pool_malloc (pool, sizeof *h);
+  h->pool = pool;
   h->used = 0;
   if (size < 4)
     size = 4;
   h->size = next_power_of_2 (size);
-  h->entries = xnmalloc (h->size, sizeof *h->entries);
+  h->entries = pool_nmalloc (pool, h->size, sizeof *h->entries);
   for (i = 0; i < h->size; i++)
     h->entries[i] = NULL;
   h->aux = aux;
@@ -227,8 +242,8 @@
         for (i = 0; i < h->size; i++)
           if (h->entries[i] != NULL)
             h->free (h->entries[i], h->aux);
-      free (h->entries);
-      free (h);
+      pool_free (h->pool, h->entries);
+      pool_free (h->pool, h);
     }
 }
 
@@ -289,7 +304,7 @@
   end = begin + h->size;
 
   h->size = new_size;
-  h->entries = xnmalloc (h->size, sizeof *h->entries);
+  h->entries = pool_nmalloc (h->pool, h->size, sizeof *h->entries);
   for (i = 0; i < h->size; i++)
     h->entries[i] = NULL;
   for (table_p = begin; table_p < end; table_p++) 
@@ -298,7 +313,7 @@
       if (entry != NULL)
         h->entries[locate_empty_entry (h, entry)] = entry;
     }
-  free (begin);
+  pool_free (h->pool, begin);
 
 #ifndef NDEBUG
   h->hash_ordered = true;
@@ -406,7 +421,7 @@
   void **copy;
 
   assert (h != NULL);
-  copy = xnmalloc ((h->used + 1), sizeof *copy);
+  copy = pool_nmalloc (h->pool, (h->used + 1), sizeof *copy);
   copy_if (h->entries, h->size, sizeof *h->entries, copy, not_null, NULL);
   copy[h->used] = NULL;
   return copy;

Index: hash.h
===================================================================
RCS file: /sources/pspp/pspp/src/libpspp/hash.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- hash.h      14 Oct 2006 00:25:21 -0000      1.3
+++ hash.h      15 Oct 2006 01:51:02 -0000      1.4
@@ -44,6 +44,13 @@
 struct hsh_table *hsh_create (int m, hsh_compare_func *,
                               hsh_hash_func *, hsh_free_func *,
                              void *aux);
+
+struct pool;
+struct hsh_table *hsh_create_pool (struct pool *pool, int m, 
+                                  hsh_compare_func *,
+                                  hsh_hash_func *, hsh_free_func *,
+                                  void *aux);
+
 void hsh_clear (struct hsh_table *);
 void hsh_destroy (struct hsh_table *);
 void *const *hsh_sort (struct hsh_table *);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]