mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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:
@ -330,8 +330,7 @@ BuildTupleHashTable(int numCols, AttrNumber *keyColIdx,
|
|||||||
else
|
else
|
||||||
hashtable->hash_iv = 0;
|
hashtable->hash_iv = 0;
|
||||||
|
|
||||||
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets);
|
hashtable->hashtab = tuplehash_create(tablecxt, nbuckets, hashtable);
|
||||||
hashtable->hashtab->private_data = hashtable;
|
|
||||||
|
|
||||||
return hashtable;
|
return hashtable;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ tbm_create_pagetable(TIDBitmap *tbm)
|
|||||||
Assert(tbm->status != TBM_HASH);
|
Assert(tbm->status != TBM_HASH);
|
||||||
Assert(tbm->pagetable == NULL);
|
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 entry1 is valid, push it into the hashtable */
|
||||||
if (tbm->status == TBM_ONE_PAGE)
|
if (tbm->status == TBM_ONE_PAGE)
|
||||||
|
@ -137,7 +137,8 @@ typedef struct SH_ITERATOR
|
|||||||
} SH_ITERATOR;
|
} SH_ITERATOR;
|
||||||
|
|
||||||
/* externally visible function prototypes */
|
/* 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_DESTROY(SH_TYPE *tb);
|
||||||
SH_SCOPE void SH_GROW(SH_TYPE *tb, uint32 newsize);
|
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);
|
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
|
#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
|
#ifndef SH_USE_NONDEFAULT_ALLOCATOR
|
||||||
|
|
||||||
/* default memory allocator function */
|
/* default memory allocator function */
|
||||||
@ -309,13 +314,14 @@ SH_FREE(SH_TYPE *type, void *pointer)
|
|||||||
* the passed-in context.
|
* the passed-in context.
|
||||||
*/
|
*/
|
||||||
SH_SCOPE SH_TYPE *
|
SH_SCOPE SH_TYPE *
|
||||||
SH_CREATE(MemoryContext ctx, uint32 nelements)
|
SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data)
|
||||||
{
|
{
|
||||||
SH_TYPE *tb;
|
SH_TYPE *tb;
|
||||||
uint64 size;
|
uint64 size;
|
||||||
|
|
||||||
tb = MemoryContextAllocZero(ctx, sizeof(SH_TYPE));
|
tb = MemoryContextAllocZero(ctx, sizeof(SH_TYPE));
|
||||||
tb->ctx = ctx;
|
tb->ctx = ctx;
|
||||||
|
tb->private_data = private_data;
|
||||||
|
|
||||||
/* increase nelements by fillfactor, want to store nelements elements */
|
/* increase nelements by fillfactor, want to store nelements elements */
|
||||||
size = Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR);
|
size = Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR);
|
||||||
|
Reference in New Issue
Block a user