506484c03bae4b9a7d61c5a56b928e773a0c83a7 angie Tue Apr 16 14:02:22 2019 -0700 Added hashNewLm/newHashLm so an external lm can be passed in and used for all hash allocations. diff --git src/inc/hash.h src/inc/hash.h index 4b690dc..120ce93 100644 --- src/inc/hash.h +++ src/inc/hash.h @@ -62,30 +62,31 @@ bits32 hashVal; }; struct hash { struct hash *next; /* Next in list. */ bits32 mask; /* Mask hashCrc with this to get it to fit table. */ struct hashEl **table; /* Hash buckets. */ int powerOfTwoSize; /* Size of table as a power of two. */ int size; /* Size of table. */ struct lm *lm; /* Local memory pool. */ int elCount; /* Count of elements. */ boolean autoExpand; /* Automatically expand hash */ float expansionFactor; /* Expand when elCount > size*expansionFactor */ int numResizes; /* number of times resize was called */ + boolean ownLm; /* TRUE if lm was allocated by newHashExt */ }; #define defaultExpansionFactor 1.0 #define hashMaxSize 28 struct hashCookie /* used by hashFirst/hashNext in tracking location in traversing hash */ { struct hash *hash; /* hash we are associated with */ int idx; /* current index in hash */ struct hashEl *nextEl; /* current element in hash */ }; bits32 hashString(char *string); @@ -224,30 +225,35 @@ /* Return the next value in the hash table, or NULL if no more. Do not modify * hash table while this is being used. */ char *hashNextName(struct hashCookie *cookie); /* Return the next name in the hash table, or NULL if no more. Do not modify * hash table while this is being used. */ struct hash *newHashExt(int powerOfTwoSize, boolean useLocalMem); /* Returns new hash table. Uses local memory optionally. */ #define hashNewExt(a) newHashExt(a) /* Synonym */ #define newHash(a) newHashExt(a, TRUE) /* Returns new hash table using local memory. */ #define hashNew(a) newHash(a) /* Synonym */ +struct hash *newHashLm(int powerOfTwoSize, struct lm *lm); +/* Returns new hash table using the given lm. Recommended lm block size is 256B to 64kB, + * depending on powerOfTwoSize. */ +#define hashNewLm(size, lm) newHashLm(size, lm) + void hashReverseAllBucketLists(struct hash *hash); /* Reverse all hash bucket list. You might do this to * get them back in the same order things were added to the hash */ void hashResize(struct hash *hash, int powerOfTwoSize); /* Resize the hash to a new size */ struct hash *hashFromSlNameList(void *list); /* Create a hash out of a list of slNames. */ struct hash *hashSetFromSlNameList(void *list); /* Create a hashSet (hash without values) out of a list of slNames. */ void freeHash(struct hash **pHash); /* Free up hash table. */