Skip to content

Commit

Permalink
Moved get_sorted_dates() to a common hash source.
Browse files Browse the repository at this point in the history
  • Loading branch information
allinurl committed May 4, 2023
1 parent 3bdfb2f commit 02da4fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
23 changes: 23 additions & 0 deletions src/gkhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,29 @@ new_db (khash_t (igdb) *hash, uint32_t key) {
return db;
}

uint32_t *
get_sorted_dates (uint32_t *len) {
GKDB *db = get_db_instance (DB_INSTANCE);
khash_t (igkh) * hash = get_hdb (db, MTRC_DATES);
khiter_t key;
uint32_t *dates = NULL;
int i = 0;
uint32_t size = 0;

if (!hash)
return NULL;

size = kh_size (hash);
dates = xcalloc (size, sizeof (uint32_t));
for (key = kh_begin (hash); key != kh_end (hash); ++key)
if (kh_exist (hash, key))
dates[i++] = kh_key (hash, key);
qsort (dates, i, sizeof (uint32_t), cmp_ui32_asc);
*len = i;

return dates;
}

/* Insert a string key and the corresponding uint8_t value.
* Note: If the key exists, the value is not replaced.
*
Expand Down
1 change: 1 addition & 0 deletions src/gkhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ uint32_t ht_get_invalid (void);
uint32_t ht_get_processed (void);
uint32_t ht_get_processing_time (void);
uint8_t get_method_proto (const char *value);
uint32_t *get_sorted_dates (uint32_t * len);

void free_storage (void);
void init_pre_storage (Logs *logs);
Expand Down
23 changes: 0 additions & 23 deletions src/gkmhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,29 +1151,6 @@ ht_get_maxts_min_max (GModule module, uint64_t *min, uint64_t *max) {
get_iu64_min_max (cache, min, max);
}

uint32_t *
get_sorted_dates (uint32_t *len) {
GKDB *db = get_db_instance (DB_INSTANCE);
khash_t (igkh) * hash = get_hdb (db, MTRC_DATES);
khiter_t key;
uint32_t *dates = NULL;
int i = 0;
uint32_t size = 0;

if (!hash)
return NULL;

size = kh_size (hash);
dates = xcalloc (size, sizeof (uint32_t));
for (key = kh_begin (hash); key != kh_end (hash); ++key)
if (kh_exist (hash, key))
dates[i++] = kh_key (hash, key);
qsort (dates, i, sizeof (uint32_t), cmp_ui32_asc);
*len = i;

return dates;
}

static void
destroy_date_stores (int date) {
GKDB *db = get_db_instance (DB_INSTANCE);
Expand Down
1 change: 0 additions & 1 deletion src/gkmhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ uint32_t ht_insert_visitor (GModule module, uint32_t date, uint32_t key, uint32_

int invalidate_date (int date);
int rebuild_rawdata_cache (void);
uint32_t *get_sorted_dates (uint32_t * len);
void des_igkh (void *h);
void free_cache (GKHashModule * cache);
void init_storage (void);
Expand Down

0 comments on commit 02da4fd

Please sign in to comment.