simplehash: Additional tweaks to make specifying an allocator work.
Even if we don't emit definitions for SH_ALLOCATE and SH_FREE, we still need prototypes. The user can't define them before including simplehash.h because SH_TYPE isn't available yet. For the allocator to be able to access private_data, it needs to become an argument to SH_CREATE. Previously we relied on callers to set that after returning from SH_CREATE, but SH_CREATE calls SH_ALLOCATE before returning. Dilip Kumar, reviewed by me.
This commit is contained in:
parent
3f3d60d3bb
commit
72257f9578
@ -330,8 +330,7 @@ BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
|
||||
else
|
||||
hashtable->hash_iv = 0;
|
||||
|
||||
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets);
|
||||
hashtable->hashtab->private_data = hashtable;
|
||||
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets, hashtable);
|
||||
|
||||
return hashtable;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ tbm_create_pagetable(TIDBitmap *tbm)
|
||||
Assert(tbm->status != TBM_HASH);
|
||||
Assert(tbm->pagetable == NULL);
|
||||
|
||||
tbm->pagetable = pagetable_create(tbm->mcxt, 128);
|
||||
tbm->pagetable = pagetable_create(tbm->mcxt, 128, NULL);
|
||||
|
||||
/* If entry1 is valid, push it into the hashtable */
|
||||
if (tbm->status == TBM_ONE_PAGE)
|
||||
|
@ -137,7 +137,8 @@ typedef struct SH_ITERATOR
|
||||
} SH_ITERATOR;
|
||||
|
||||
/* externally visible function prototypes */
|
||||
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements);
|
||||
SH_SCOPE SH_TYPE *SH_CREATE(MemoryContext ctx, uint32 nelements,
|
||||
void *private_data);
|
||||
SH_SCOPE void SH_DESTROY(SH_TYPE *tb);
|
||||
SH_SCOPE void SH_GROW(SH_TYPE *tb, uint32 newsize);
|
||||
SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE *tb, SH_KEY_TYPE key, bool *found);
|
||||
@ -280,6 +281,10 @@ SH_ENTRY_HASH(SH_TYPE *tb, SH_ELEMENT_TYPE * entry)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* default memory allocator function */
|
||||
static inline void *SH_ALLOCATE(SH_TYPE *type, Size size);
|
||||
static inline void SH_FREE(SH_TYPE *type, void *pointer);
|
||||
|
||||
#ifndef SH_USE_NONDEFAULT_ALLOCATOR
|
||||
|
||||
/* default memory allocator function */
|
||||
@ -309,13 +314,14 @@ SH_FREE(SH_TYPE *type, void *pointer)
|
||||
* the passed-in context.
|
||||
*/
|
||||
SH_SCOPE SH_TYPE *
|
||||
SH_CREATE(MemoryContext ctx, uint32 nelements)
|
||||
SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data)
|
||||
{
|
||||
SH_TYPE *tb;
|
||||
uint64 size;
|
||||
|
||||
tb = MemoryContextAllocZero(ctx, sizeof(SH_TYPE));
|
||||
tb->ctx = ctx;
|
||||
tb->private_data = private_data;
|
||||
|
||||
/* increase nelements by fillfactor, want to store nelements elements */
|
||||
size = Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR);
|
||||
|
Loading…
x
Reference in New Issue
Block a user