m4-patches
[Top][All Lists]
Advanced

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

FYI: 33-gary-hash-resize-function.patch


From: Gary V. Vaughan
Subject: FYI: 33-gary-hash-resize-function.patch
Date: Tue, 28 May 2002 23:06:23 +0100
User-agent: Mutt/1.2.5i

Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>
        * m4/hash.c (m4_hash_resize): New function.
        * m4/hash.h: Add prototype.
        * m4/symtab.c (m4_symtab_init):  Use it.  This could do with some
        benchmarking to find a good value for, say, autoconf.  This is
        already a little quicker than before for me.

Index: m4/hash.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/hash.c,v
retrieving revision 1.6
diff -u -p -u -r1.6 hash.c
--- m4/hash.c 28 May 2002 21:30:24 -0000 1.6
+++ m4/hash.c 28 May 2002 21:45:58 -0000
@@ -311,6 +311,38 @@ m4_hash_length (m4_hash *hash)
   return M4_HASH_LENGTH (hash);
 }
 
+/* Force the number of buckets to be the given value.  You probably ought
+   not to be using this function once the table has been in use, since
+   the maximum density algorithm will grow the number of buckets back to
+   what was there before if you try to shrink the table.  It is useful
+   to set a smaller or larger initial size if you know in advance what
+   order of magnitude of entries will be in the table.  Be aware that
+   the efficiency of the lookup and grow features require that the size
+   always be 1 less than a power of 2.  */
+void
+m4_hash_resize (m4_hash *hash, size_t size)
+{
+  m4_hash_node **original_buckets;
+  size_t original_size;
+
+  assert (hash);
+
+  original_size                = M4_HASH_SIZE (hash);
+  original_buckets     = M4_HASH_BUCKETS (hash);
+
+  M4_HASH_SIZE (hash)  = size;
+  M4_HASH_BUCKETS (hash)= XCALLOC (m4_hash_node *, size);
+
+  {
+    size_t i;
+    for (i = 0; i < original_size; ++i)
+      if (original_buckets[i])
+       m4_hash_bucket_insert (hash, original_buckets[i]);
+  }
+
+  XFREE (original_buckets);
+}
+
 /* If the node density breaks the threshold, increase the size of
    HASH and repopulate with the original nodes.  */
 void
Index: m4/hash.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/hash.h,v
retrieving revision 1.5
diff -u -p -u -r1.5 hash.h
--- m4/hash.h 28 May 2002 21:30:24 -0000 1.5
+++ m4/hash.h 28 May 2002 21:45:58 -0000
@@ -44,6 +44,7 @@ void          m4_hash_insert  (m4_hash *hash, con
 void *         m4_hash_remove  (m4_hash *hash, const void *key);
 void **                m4_hash_lookup  (m4_hash *hash, const void *key);
 size_t         m4_hash_length  (m4_hash *hash);
+void           m4_hash_resize  (m4_hash *hash, size_t size);
 void           m4_hash_exit    (void);
 
 
Index: m4/symtab.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/symtab.c,v
retrieving revision 1.28
diff -u -p -u -r1.28 symtab.c
--- m4/symtab.c 28 May 2002 21:30:24 -0000 1.28
+++ m4/symtab.c 28 May 2002 21:45:59 -0000
@@ -59,6 +59,7 @@ void
 m4_symtab_init (void)
 {
   m4_symtab = m4_hash_new (m4_hash_string_hash, m4_hash_string_cmp);
+  m4_hash_resize (m4_symtab, 2047);
 }
 
 /* The following function is used for the cases where we want to do

-- 
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/



reply via email to

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