Source
xxxxxxxxxx
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
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;