From f94c1261f691c6473cd27de2a8d9465f77e73b40 Mon Sep 17 00:00:00 2001 From: pgaddict Date: Thu, 29 Jun 2023 14:20:00 +0800 Subject: [PATCH 1/2] marco SET_DATA_PTR to quicly access hashset data region --- hashset.c | 8 ++++---- hashset.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hashset.c b/hashset.c index 91907abc..d786d379 100644 --- a/hashset.c +++ b/hashset.c @@ -82,7 +82,7 @@ int4hashset_resize(int4hashset_t * set) /* Calculate the pointer to the bitmap and values array */ bitmap = set->data; - values = (int32 *) (set->data + CEIL_DIV(set->capacity, 8)); + values = (int32 *) SET_DATA_PTR(set); for (i = 0; i < set->capacity; i++) { @@ -132,7 +132,7 @@ int4hashset_add_element(int4hashset_t *set, int32 value) position = hash % set->capacity; bitmap = set->data; - values = (int32 *) (set->data + CEIL_DIV(set->capacity, 8)); + values = (int32 *) SET_DATA_PTR(set); while (true) { @@ -204,7 +204,7 @@ int4hashset_contains_element(int4hashset_t *set, int32 value) position = hash % set->capacity; bitmap = set->data; - values = (int32 *) (set->data + CEIL_DIV(set->capacity, 8)); + values = (int32 *) SET_DATA_PTR(set); while (true) { @@ -238,7 +238,7 @@ int4hashset_extract_sorted_elements(int4hashset_t *set) /* Access the data array */ char *bitmap = set->data; - int32 *values = (int32 *)(set->data + CEIL_DIV(set->capacity, 8)); + int32 *values = (int32 *) SET_DATA_PTR(set); /* Counter for the number of extracted elements */ int32 nextracted = 0; diff --git a/hashset.h b/hashset.h index 86f5d1b0..2513ab55 100644 --- a/hashset.h +++ b/hashset.h @@ -42,6 +42,9 @@ typedef struct int4hashset_t { char data[FLEXIBLE_ARRAY_MEMBER]; } int4hashset_t; +#define SET_DATA_PTR(a) \ + (((char *) (a->data)) + CEIL_DIV(a->capacity, 8)) + int4hashset_t *int4hashset_allocate(int capacity, float4 load_factor, float4 growth_factor, int hashfn_id); int4hashset_t *int4hashset_resize(int4hashset_t * set); int4hashset_t *int4hashset_add_element(int4hashset_t *set, int32 value); -- 2.34.1