Initial commit, yay
This commit is contained in:
commit
25e26756cd
85 changed files with 7077 additions and 0 deletions
67
src/hashmap/hashmap.h
Normal file
67
src/hashmap/hashmap.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
struct HashMapConfig HashMap_DefaultConfig(void);
|
||||
|
||||
int HashMap_Create(hashmap_t* restrict destination, struct HashMapConfig* restrict config, size_t initial_capacity);
|
||||
void HashMap_Destroy(hashmap_t* restrict hashmap);
|
||||
|
||||
int HashMap_Put(hashmap_t* restrict hashmap, const void* key, size_t key_length, void* value);
|
||||
int HashMap_Remove(hashmap_t* restrict hashmap, const void* restrict key, size_t key_length);
|
||||
|
||||
int HashMap_Get(hashmap_t* restrict hashmap, const void* key, size_t key_length, void* value_storage);
|
||||
|
||||
int HashMap_Update(hashmap_t* restrict hashmap, const void* key, size_t key_length, void* new_value);
|
||||
|
||||
int HashMap_ValueByIndex(hashmap_t* restrict hashmap, size_t index, void* store_here);
|
||||
int HashMap_EntryByIndex(hashmap_t* restrict hashmap, size_t index, hashmapentry_t** store_here);
|
||||
size_t HashMap_Size(hashmap_t* restrict hashmap);
|
||||
|
||||
#endif /* SRC_COMMON_HASHMAP_HASHMAP_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue