Source
xxxxxxxxxx
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
static void __hashmap_ensure_free_entry(zbx_hashmap_t *hm, ZBX_HASHMAP_SLOT_T *slot);
/* because the number of slot entries is usually small, with 3/2 they grow too slow */
/* private hashmap functions */
static void __hashmap_ensure_free_entry(zbx_hashmap_t *hm, ZBX_HASHMAP_SLOT_T *slot)
{
if (NULL == slot->entries)
{
slot->entries_num = 0;
slot->entries_alloc = 6;
slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_malloc_func(NULL, slot->entries_alloc *
sizeof(ZBX_HASHMAP_ENTRY_T));
}
else if (slot->entries_num == slot->entries_alloc)
{
slot->entries_alloc = slot->entries_alloc * ARRAY_GROWTH_FACTOR;
slot->entries = (ZBX_HASHMAP_ENTRY_T *)hm->mem_realloc_func(slot->entries, slot->entries_alloc *
sizeof(ZBX_HASHMAP_ENTRY_T));
}
}
static void zbx_hashmap_init_slots(zbx_hashmap_t *hm, size_t init_size)
{
hm->num_data = 0;
if (0 < init_size)
{
hm->num_slots = next_prime(init_size);
hm->slots = (ZBX_HASHMAP_SLOT_T *)hm->mem_malloc_func(NULL, hm->num_slots * sizeof(ZBX_HASHMAP_SLOT_T));
memset(hm->slots, 0, hm->num_slots * sizeof(ZBX_HASHMAP_SLOT_T));
}
else
{
hm->num_slots = 0;
hm->slots = NULL;
}
}
/* public hashmap interface */