55 lines
No EOL
2 KiB
C
55 lines
No EOL
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.c
|
|
* Description:
|
|
* This file contains the functions for modifying the Hash Table. It includes functions
|
|
* to get, Insert, Remove, check if has key and check if empty.
|
|
*
|
|
* Author: Mineplay
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
#include "../../Include/Fledasty/Core/HashTable.h"
|
|
|
|
#include <Hallocy/Core/Allocator.h>
|
|
#include <Hallocy/Core/Memory.h>
|
|
#include <Hallocy/Utils/Error.h>
|
|
|
|
FledastyError fledasty_hash_table_initialize(FledastyHashtable *new_hash_table, size_t element_byte_size, size_t (*hash_function)(void *key)) {
|
|
if (new_hash_table == NULL || hash_function == NULL) {
|
|
return FLEDASTY_ERROR_INVALID_POINTER;
|
|
}
|
|
|
|
new_hash_table->element_byte_size = element_byte_size;
|
|
new_hash_table->hash_function = hash_function;
|
|
|
|
new_hash_table->size = 0;
|
|
new_hash_table->capacity = 1024;
|
|
new_hash_table->Table = (FledastyHashTablePair**)hallocy_calloc(sizeof(FledastyHashTablePair*), new_hash_table->capacity);
|
|
|
|
return FLEDASTY_ERROR_NONE;
|
|
}
|
|
|
|
FledastyError fledasty_hash_table_destroy(FledastyHashtable *current_hash_table) {
|
|
if (current_hash_table == NULL) {
|
|
return FLEDASTY_ERROR_INVALID_POINTER;
|
|
}
|
|
|
|
for (size_t i = 0; i < current_hash_table->capacity; i += 1) {
|
|
hallocy_free(current_hash_table->Table[i]);
|
|
}
|
|
|
|
hallocy_free(current_hash_table->Table);
|
|
return FLEDASTY_ERROR_NONE;
|
|
} |