59 lines
2.6 KiB
C
59 lines
2.6 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: LinkedList.h
|
|
* Description:
|
|
* This file contains the Linked List 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_LINKED_LIST
|
|
#define FLEDASTY_LINKED_LIST
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "../Utils/Error.h"
|
|
|
|
typedef struct FledastyLinkedListNode{
|
|
void *value;
|
|
struct FledastyLinkedListNode *next;
|
|
} FledastyLinkedListNode;
|
|
|
|
typedef struct {
|
|
size_t size, element_byte_size;
|
|
FledastyLinkedListNode *start, *end;
|
|
} FledastyLinkedList;
|
|
|
|
FledastyError fledasty_linked_list_initialize(FledastyLinkedList *new_linked_list, void *values, const size_t values_size, const size_t element_byte_size);
|
|
FledastyError fledasty_linked_list_destroy(FledastyLinkedList *current_linked_list);
|
|
|
|
FledastyError fledasty_linked_list_append(FledastyLinkedList *current_linked_list, void *value);
|
|
|
|
FledastyError fledasty_linked_list_insert_at_index(FledastyLinkedList *current_linked_list, const size_t index, void *value);
|
|
FledastyError fledasty_linked_list_insert_before_value(FledastyLinkedList *current_linked_list, void *before_value, void *value);
|
|
FledastyError fledasty_linked_list_insert_after_value(FledastyLinkedList *current_linked_list, void *after_value, void *value);
|
|
|
|
FledastyError fledasty_linked_list_remove_at_index(FledastyLinkedList *current_linked_list, const size_t index);
|
|
FledastyError fledasty_linked_list_remove_value(FledastyLinkedList *current_linked_list, void *value);
|
|
|
|
FledastyError fledasty_linked_list_clear(FledastyLinkedList *current_linked_list);
|
|
|
|
bool fledasty_linked_list_has_value(const FledastyLinkedList *current_linked_list, void *value);
|
|
static inline bool fledasty_linked_list_is_empty(const FledastyLinkedList *current_linked_list) { return current_linked_list->size == 0; }
|
|
|
|
#endif
|