58 lines
No EOL
2.2 KiB
C
58 lines
No EOL
2.2 KiB
C
/*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* -----------------------------------------------------------------------------
|
|
* File: HashTable.h
|
|
* Description:
|
|
* This file contains the HashTable structure and the functions for modifying it.
|
|
* It includes functions to get, Insert, Remove, check if has key and check if
|
|
* empty.
|
|
*
|
|
* Author: Mineplay
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
#ifndef FLEDASTY_HASH_TABLE
|
|
#define FLEDASTY_HASH_TABLE
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "../Utils/Error.h"
|
|
#include "DynamicArray.h"
|
|
|
|
typedef struct {
|
|
void *key, *value;
|
|
} FledastyHashTablePair;
|
|
|
|
typedef struct {
|
|
size_t size, capacity;
|
|
|
|
size_t key_byte_size, value_byte_size;
|
|
FledastyDynamicArray *Table;
|
|
|
|
size_t (*hash_function)(void *key);
|
|
} FledastyHashTable;
|
|
|
|
FledastyError fledasty_hash_table_initialize(FledastyHashTable *new_hash_table, size_t key_byte_size, size_t value_byte_size, size_t (*hash_function)(void *key));
|
|
FledastyError fledasty_hash_table_destroy(FledastyHashTable *current_hash_table);
|
|
|
|
FledastyError fledasty_hash_table_insert(FledastyHashTable *current_hash_table, void *key, void *value);
|
|
void *fledasty_hash_table_get(const FledastyHashTable *current_hash_table, void *key);
|
|
FledastyError fledasty_hash_table_remove(FledastyHashTable *current_hash_table, void *key);
|
|
|
|
FledastyError fledasty_hash_table_clear(FledastyHashTable *current_hash_table);
|
|
|
|
bool fledasty_hash_table_has_key(const FledastyHashTable *current_hash_table, void *key);
|
|
static inline bool fledasty_hash_table_is_empty(const FledastyHashTable *current_hash_table) { return current_hash_table->size == 0; }
|
|
|
|
#endif |