70 lines
2.5 KiB
C
70 lines
2.5 KiB
C
/*
|
|
* This code is part of the strategy game operational-space.
|
|
* operational-space comes with ABSOLUTELY NO WARRANTY and is licensed under GPL-2.0.
|
|
* Copyright (C) 2024 VegOwOtenks, Sleppo04
|
|
*
|
|
* 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.
|
|
*/
|
|
#ifndef COMMONHASHMAP_H
|
|
#define COMMONHASHMAP_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
#include "../siphash/siphash.h"
|
|
#include "../allocator-interface/allocator-interface.h"
|
|
|
|
typedef struct HashMapEntry {
|
|
void* key;
|
|
size_t key_length;
|
|
struct HashMapEntry* next;
|
|
char value[];
|
|
} hashmapentry_t;
|
|
|
|
typedef struct HashMapConfig {
|
|
double load_factor;
|
|
double growth_factor;
|
|
size_t value_size;
|
|
allocator_t* allocator;
|
|
siphashconfig_t siphash_config;
|
|
} hashmapconfig_t;
|
|
|
|
typedef struct HashMap {
|
|
size_t capacity;
|
|
size_t used;
|
|
struct HashMapEntry** buckets;
|
|
struct HashMapConfig config;
|
|
} hashmap_t;
|
|
|
|
typedef int (*HashMapVisitFunction) (void* context, void* key, size_t key_length, void* value);
|
|
|
|
struct HashMapConfig HashMap_DefaultConfig(void);
|
|
|
|
int HashMap_Create(hashmap_t* destination, struct HashMapConfig* config, size_t initial_capacity);
|
|
void HashMap_Destroy(hashmap_t* hashmap);
|
|
|
|
int HashMap_Put(hashmap_t* hashmap, const void* key, size_t key_length, void* value);
|
|
int HashMap_Remove(hashmap_t* hashmap, const void* key, size_t key_length);
|
|
|
|
int HashMap_Get(hashmap_t* hashmap, const void* key, size_t key_length, void* value_storage);
|
|
|
|
int HashMap_Update(hashmap_t* hashmap, const void* key, size_t key_length, void* new_value);
|
|
|
|
int HashMap_ValueByIndex(hashmap_t* hashmap, size_t index, void* store_here);
|
|
int HashMap_EntryByIndex(hashmap_t* hashmap, size_t index, hashmapentry_t** store_here);
|
|
int HashMap_ForEach(hashmap_t* hashmap, HashMapVisitFunction visitor, void* context);
|
|
size_t HashMap_Size(hashmap_t* hashmap);
|
|
|
|
#endif /* SRC_COMMON_HASHMAP_HASHMAP_H_ */
|