]> mj.ucw.cz Git - libucw.git/commitdiff
Enables the user to give non-global memory pool to hash table or KMP.
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 19 Apr 2006 12:56:42 +0000 (14:56 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 19 Apr 2006 12:56:42 +0000 (14:56 +0200)
lib/hashtable.h
lib/kmp-new.h

index 0419a47ce6468162833f9de277b29792dca2c0a3..c96f0a61c687bd501cbbfe80d2e19ca2795426be 100644 (file)
@@ -93,6 +93,7 @@
  *                     deallocation is not supported by mempools, so delete/remove
  *                     will leak pool memory.
  *  HASH_AUTO_POOL=size        Create a pool of the given block size automatically.
+ *  HASH_PARAM_POOL    Allocate all nodes from mempool given as a parameter to init().
  *  HASH_ZERO_FILL     New entries should be initialized to all zeroes.
  *  HASH_TABLE_ALLOC   The hash table itself will be allocated and freed using
  *                     the same allocation functions as the nodes instead of
@@ -154,7 +155,7 @@ struct P(table) {
   uns hash_size;
   uns hash_count, hash_max, hash_min, hash_hard_max;
   P(bucket) **ht;
-#ifdef HASH_AUTO_POOL
+#if defined(HASH_AUTO_POOL) || defined(HASH_PARAM_POOL)
   struct mempool *pool;
 #endif
 };
@@ -330,6 +331,15 @@ static inline void P(free) (TAUC void *x UNUSED) { }
 static inline void P(init_alloc) (TAU) { }
 static inline void P(cleanup_alloc) (TAU) { }
 
+#elif defined(HASH_PARAM_POOL)
+/* Use mempools given as a parameter to init() */
+#include "lib/mempool.h"
+static inline void * P(alloc) (TAUC unsigned int size) { return mp_alloc_fast(T.pool, size); }
+static inline void P(free) (TAUC void *x UNUSED) { }
+static inline void P(init_alloc) (TAU) { }
+static inline void P(cleanup_alloc) (TAU) { }
+#define HASH_USE_POOL
+
 #elif defined(HASH_AUTO_POOL)
 /* Use our own pools */
 #include "lib/mempool.h"
@@ -392,7 +402,11 @@ static void P(alloc_table) (TAU)
     T.hash_min = 0;
 }
 
+#ifndef HASH_PARAM_POOL
 static void P(init) (TA)
+#else
+static void P(init) (TAC struct mempool *pool)
+#endif
 {
   T.hash_count = 0;
   T.hash_size = HASH_DEFAULT_SIZE;
@@ -402,6 +416,9 @@ static void P(init) (TA)
   T.hash_hard_max = 1 << 28;
 #endif
   P(alloc_table)(TT);
+#ifdef HASH_PARAM_POOL
+  T.pool = pool;
+#endif
   P(init_alloc)(TT);
 }
 
@@ -649,6 +666,7 @@ do {                                                                                        \
 #undef HASH_PREFIX
 #undef HASH_USE_POOL
 #undef HASH_AUTO_POOL
+#undef HASH_PARAM_POOL
 #undef HASH_WANT_CLEANUP
 #undef HASH_WANT_DELETE
 #undef HASH_WANT_FIND
index 8588105197d01ce1fc8ecbe13f1b48b69d819364..741efba9e37325b59a885b999478e9845e7ba3f5 100644 (file)
@@ -138,8 +138,10 @@ P(hash_init_key) (struct P(hash_table) *t UNUSED, struct P(state) *s, struct P(s
 #define HASH_GIVE_HASHFN
 #define HASH_GIVE_EQ
 #define HASH_GIVE_INIT_KEY
-#ifdef KMP_USE_POOL
+#if defined(KMP_USE_POOL)
 #define HASH_USE_POOL KMP_USE_POOL
+#elif defined(KMP_PARAM_POOL)
+#define HASH_PARAM_POOL
 #else
 #define HASH_AUTO_POOL 4096
 #endif
@@ -208,7 +210,7 @@ P(get_char) (struct P(context) *ctx UNUSED, P(source_t) *src, P(char_t) *c)
   else
 # endif
 #   ifdef KMP_TOLOWER
-    cc = Clocase(c);
+    cc = Clocase(cc);
 #   endif
 #   ifdef KMP_UNACCENT
 #   error Do not know how to unaccent ASCII characters
@@ -274,10 +276,18 @@ enter_new:
 }
 
 static void
-P(init) (struct P(context) *ctx)
+P(init) (struct P(context) *ctx
+#   ifdef KMP_PARAM_POOL
+    , struct mempool *pool
+#   endif    
+    )
 {
   bzero(ctx, sizeof(*ctx));
-  P(hash_init)(&ctx->hash);
+  P(hash_init)(&ctx->hash
+#     ifdef KMP_PARAM_POOL
+      , pool
+#     endif      
+      );
 }
 
 #ifdef KMP_WANT_CLEANUP
@@ -359,6 +369,7 @@ P(build) (struct P(context) *ctx)
 #undef KMP_NO_DUPS
 #undef KMP_BUILD_STATE
 #undef KMP_USE_POOL
+#undef KMP_PARAM_POOL
 
 #ifdef KMP_WANT_SEARCH
 #  undef KMP_WANT_SEARCH