59 lines
2.8 KiB
C
59 lines
2.8 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: DynamicArray.h
|
|
* Description:
|
|
* This file contains the Dynamic Array structure and the functions for modifying it.
|
|
* It includes functions to append, Insert before, Insert after, Insert at index,
|
|
* Get, Remove element, Remove at index, Check if has element and Check if is empty.
|
|
*
|
|
* Author: Mineplay
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
#ifndef FLEDASTY_DYNAMIC_ARRAY
|
|
#define FLEDASTY_DYNAMIC_ARRAY
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "../Utils/Error.h"
|
|
|
|
typedef struct {
|
|
size_t size, capacity;
|
|
|
|
size_t element_byte_size;
|
|
unsigned char *buffer;
|
|
} FledastyDynamicArray;
|
|
|
|
FledastyError fledasty_dynamic_array_initialize(FledastyDynamicArray *new_dynamic_array, void *values, const size_t values_size, const size_t element_byte_size);
|
|
FledastyError fledasty_dynamic_array_destroy(FledastyDynamicArray *current_dynamic_array);
|
|
|
|
FledastyError fledasty_dynamic_array_append(FledastyDynamicArray *current_dynamic_array, void *value);
|
|
|
|
FledastyError fledasty_dynamic_array_insert_at_index(FledastyDynamicArray *current_dynamic_array, const size_t index, void *value);
|
|
FledastyError fledasty_dynamic_array_insert_before_value(FledastyDynamicArray *current_dynamic_array, void *before_value, void *value);
|
|
FledastyError fledasty_dynamic_array_insert_after_value(FledastyDynamicArray *current_dynamic_array, void *after_value, void *value);
|
|
|
|
void *fledasty_dynamic_array_get(const FledastyDynamicArray *current_dynamic_array, const size_t index);
|
|
|
|
FledastyError fledasty_dynamic_array_remove_at_index(FledastyDynamicArray *current_dynamic_array, const size_t index);
|
|
FledastyError fledasty_dynamic_array_remove_value(FledastyDynamicArray *current_dynamic_array, void *value);
|
|
|
|
FledastyError fledasty_dynamic_array_clear(FledastyDynamicArray *current_dynamic_array);
|
|
FledastyError fledasty_dynamic_array_shrink_to_fit(FledastyDynamicArray *current_dynamic_array);
|
|
|
|
bool fledasty_dynamic_array_has_value(const FledastyDynamicArray *current_dynamic_array, void *value);
|
|
inline static bool fledasty_dynamic_array_is_empty(const FledastyDynamicArray *current_dynamic_array) { return current_dynamic_array == NULL || current_dynamic_array->size == 0; }
|
|
|
|
#endif
|