Minor fixes all around

Changed some input parameter names
Updated TODO
Changed how hashtables initialization works. Now the given initial capacity will be guaranteed to be reached before the hashtable rehashes (load is now considered in the calculation).
This commit is contained in:
Leonardo committed 2019-06-13 00:40:55 -03:00
1 parent b6cbadd8e2
commit b0a2e42cfe
8 files changed
+1537 -1540

No files matched your search

+12 -12
View File
@@ -136,15 +136,15 @@ The iterator is a simple structure that is capable of going back and forwards. A
## [<span id="list_new"> \_new() </span>](#list_function_index)
Allocates and returns a new list with an internal capacity of `size`. If allocation fails, `NULL` is returned.
Allocates and returns a new list with an internal capacity of the specified value. If allocation fails, `NULL` is returned.
#### Declaration
> `FMOD SNAME *PFX##_new(size_t size);`
> `FMOD SNAME *PFX##_new(size_t capacity);`
#### Parameters
1. `size_t size` - The initial capacity for the list.
1. `size_t capacity` - The initial capacity for the list.
#### Returns
@@ -1028,15 +1028,15 @@ A Stack is used in algorithms like backtracking, depth-first search, expression
## [<span id="stack_new"> \_new() </span>](#stack_function_index)
Allocates and returns a new stack with an internal capacity of `size`. If allocation fails, `NULL` is returned.
Allocates and returns a new stack with an internal capacity of the specified value. If allocation fails, `NULL` is returned.
#### Declaration
> `FMOD SNAME *PFX##_new(size_t size);`
> `FMOD SNAME *PFX##_new(size_t capacity);`
#### Parameters
1. `size_t size` - The initial capacity for the stack.
1. `size_t capacity` - The initial capacity for the stack.
#### Returns
@@ -1545,15 +1545,15 @@ The queue is used in many applications where a resource is shared among multiple
## [<span id="queue_new"> \_new() </span>](#queue_function_index)
Allocates and returns a new queue with an internal capacity of `size`. If allocation fails, `NULL` is returned.
Allocates and returns a new queue with an internal capacity of the specified value. If allocation fails, `NULL` is returned.
#### Declaration
> `FMOD SNAME *PFX##_new(size_t size);`
> `FMOD SNAME *PFX##_new(size_t capacity);`
#### Parameters
1. `size_t size` - The initial capacity for the queue.
1. `size_t capacity` - The initial capacity for the queue.
#### Returns
@@ -2062,15 +2062,15 @@ A double-ended queue backed by a circular buffer. Elements can be added and remo
## [<span id="deque_new"> \_new() </span>](#deque_function_index)
Allocates and returns a new deque with an internal capacity of `size`. If allocation fails, `NULL` is returned.
Allocates and returns a new deque with an internal capacity of the specified value. If allocation fails, `NULL` is returned.
#### Declaration
> `FMOD SNAME *PFX##_new(size_t size);`
> `FMOD SNAME *PFX##_new(size_t capacity);`
#### Parameters
1. `size_t size` - The initial capacity for the deque.
1. `size_t capacity` - The initial capacity for the deque.
#### Returns
+6 -9
View File
@@ -25,27 +25,24 @@ Before 2.0
OK - Allow for struct to be a possible data type (instead of just pointer to struct)
OK - Set functions: is_subset, is_proper_subset, is_superset, is_proper_superset, is_disjointset
Iterator move and move_to
from_array - Creates a collection with all the elements in a specified array
to_array - Creates an array with all the elements inside the collection
1.6
from_array - Creates a collection with all the elements in a specified array
to_array - Creates an array with all the elements inside the collection
LinkedList - Insert/Remove/Append/Prepend/Extract
Resize buffer function
Add dispose method to each collection in order to automatically free its data
Add copy functions (copy of a collection)
2.0
Add multiset, multimap and new heap implementation
Add new heap collection implementation
Add stack based collections
2.1
Adapt multiset, multimap and new heap implementation to the current standards
Add variadic macros (generate only the necessary functions)
2.2
Add serialization functions
Header:
%d - Type specifier (LIST = 0, DEQUE = 1, STACK = 2, etc) for quick check
%llu - How many elements there are
%d - If data varies in size
%llu - Data size
2.3
Iterator functions (functions that operate relative to iterators position) like add or remove ranges
+6 -6
View File
@@ -80,7 +80,7 @@
\
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
FMOD SNAME *PFX##_new(size_t size); \
FMOD SNAME *PFX##_new(size_t capacity); \
FMOD void PFX##_clear(SNAME *_deque_); \
FMOD void PFX##_free(SNAME *_deque_); \
/* Collection Input and Output */ \
@@ -140,9 +140,9 @@
static SNAME##_iter PFX##_impl_it_start(SNAME *_deque_); \
static SNAME##_iter PFX##_impl_it_end(SNAME *_deque_); \
\
FMOD SNAME *PFX##_new(size_t size) \
FMOD SNAME *PFX##_new(size_t capacity) \
{ \
if (size < 1) \
if (capacity < 1) \
return NULL; \
\
SNAME *_deque_ = malloc(sizeof(SNAME)); \
@@ -150,7 +150,7 @@
if (!_deque_) \
return NULL; \
\
_deque_->buffer = malloc(sizeof(V) * size); \
_deque_->buffer = malloc(sizeof(V) * capacity); \
\
if (!_deque_->buffer) \
{ \
@@ -158,9 +158,9 @@
return NULL; \
} \
\
memset(_deque_->buffer, 0, sizeof(V) * size); \
memset(_deque_->buffer, 0, sizeof(V) * capacity); \
\
_deque_->capacity = size; \
_deque_->capacity = capacity; \
_deque_->count = 0; \
_deque_->front = 0; \
_deque_->back = 0; \
+635 -635
View File
File diff suppressed because it is too large. Load diff
+768 -768
View File
File diff suppressed because it is too large. Load diff
+99 -99
View File
@@ -36,100 +36,100 @@ typedef enum HeapOrder
HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, V)
/* HEADER ********************************************************************/
#define HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, V) \
\
/* Heap Structure */ \
typedef struct SNAME##_s \
{ \
/* Dynamic array of elements */ \
V *buffer; \
\
/* Current array capacity */ \
size_t capacity; \
\
/* Current amount of elements in the heap */ \
size_t count; \
\
/* Heap order (MaxHeap or MinHeap) */ \
enum HeapOrder HO; \
\
/* Element comparison function */ \
int (*cmp)(V, V); \
\
/* Function that returns an iterator to the start of the heap */ \
struct SNAME##_iter_s (*it_start)(struct SNAME##_s *); \
\
/* Function that returns an iterator to the end of the heap */ \
struct SNAME##_iter_s (*it_end)(struct SNAME##_s *); \
\
} SNAME, *SNAME##_ptr; \
\
/* Heap Iterator */ \
typedef struct SNAME##_iter_s \
{ \
/* Target heap */ \
struct SNAME##_s *target; \
\
/* Cursor's position (index) */ \
size_t cursor; \
\
/* If the iterator has reached the start of the iteration */ \
bool start; \
\
/* If the iterator has reached the end of the iteration */ \
bool end; \
\
} SNAME##_iter, *SNAME##_iter_ptr; \
\
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(V, V)); \
FMOD void PFX##_clear(SNAME *_heap_); \
FMOD void PFX##_free(SNAME *_heap_); \
/* Collection Input and Output */ \
FMOD bool PFX##_insert(SNAME *_heap_, V element); \
FMOD bool PFX##_remove(SNAME *_heap_, V *result); \
/* Conditional Input and Output */ \
FMOD bool PFX##_insert_if(SNAME *_heap_, V element, bool condition); \
FMOD bool PFX##_remove_if(SNAME *_heap_, V *result, bool condition); \
/* Element Access */ \
FMOD V PFX##_peek(SNAME *_heap_); \
FMOD V *PFX##_peek_ref(SNAME *_heap_); \
/* Collection State */ \
FMOD bool PFX##_contains(SNAME *_heap_, V element); \
FMOD bool PFX##_empty(SNAME *_heap_); \
FMOD bool PFX##_full(SNAME *_heap_); \
FMOD size_t PFX##_count(SNAME *_heap_); \
FMOD size_t PFX##_capacity(SNAME *_heap_); \
\
/* Iterator Functions */ \
/* Iterator Allocation and Deallocation */ \
FMOD SNAME##_iter *PFX##_iter_new(SNAME *target); \
FMOD void PFX##_iter_free(SNAME##_iter *iter); \
/* Iterator Initialization */ \
FMOD void PFX##_iter_init(SNAME##_iter *iter, SNAME *target); \
/* Iterator State */ \
FMOD bool PFX##_iter_start(SNAME##_iter *iter); \
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
/* Iterator Movement */ \
FMOD void PFX##_iter_to_start(SNAME##_iter *iter); \
FMOD void PFX##_iter_to_end(SNAME##_iter *iter); \
FMOD bool PFX##_iter_next(SNAME##_iter *iter); \
FMOD bool PFX##_iter_prev(SNAME##_iter *iter); \
/* Iterator Access */ \
FMOD V PFX##_iter_value(SNAME##_iter *iter); \
FMOD size_t PFX##_iter_index(SNAME##_iter *iter); \
\
/* Default Value */ \
static inline V PFX##_impl_default_value(void) \
{ \
V _empty_value_; \
\
memset(&_empty_value_, 0, sizeof(V)); \
\
return _empty_value_; \
} \
\
#define HEAP_GENERATE_HEADER(PFX, SNAME, FMOD, V) \
\
/* Heap Structure */ \
typedef struct SNAME##_s \
{ \
/* Dynamic array of elements */ \
V *buffer; \
\
/* Current array capacity */ \
size_t capacity; \
\
/* Current amount of elements in the heap */ \
size_t count; \
\
/* Heap order (MaxHeap or MinHeap) */ \
enum HeapOrder HO; \
\
/* Element comparison function */ \
int (*cmp)(V, V); \
\
/* Function that returns an iterator to the start of the heap */ \
struct SNAME##_iter_s (*it_start)(struct SNAME##_s *); \
\
/* Function that returns an iterator to the end of the heap */ \
struct SNAME##_iter_s (*it_end)(struct SNAME##_s *); \
\
} SNAME, *SNAME##_ptr; \
\
/* Heap Iterator */ \
typedef struct SNAME##_iter_s \
{ \
/* Target heap */ \
struct SNAME##_s *target; \
\
/* Cursor's position (index) */ \
size_t cursor; \
\
/* If the iterator has reached the start of the iteration */ \
bool start; \
\
/* If the iterator has reached the end of the iteration */ \
bool end; \
\
} SNAME##_iter, *SNAME##_iter_ptr; \
\
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
FMOD SNAME *PFX##_new(size_t capacity, HeapOrder HO, int (*compare)(V, V)); \
FMOD void PFX##_clear(SNAME *_heap_); \
FMOD void PFX##_free(SNAME *_heap_); \
/* Collection Input and Output */ \
FMOD bool PFX##_insert(SNAME *_heap_, V element); \
FMOD bool PFX##_remove(SNAME *_heap_, V *result); \
/* Conditional Input and Output */ \
FMOD bool PFX##_insert_if(SNAME *_heap_, V element, bool condition); \
FMOD bool PFX##_remove_if(SNAME *_heap_, V *result, bool condition); \
/* Element Access */ \
FMOD V PFX##_peek(SNAME *_heap_); \
FMOD V *PFX##_peek_ref(SNAME *_heap_); \
/* Collection State */ \
FMOD bool PFX##_contains(SNAME *_heap_, V element); \
FMOD bool PFX##_empty(SNAME *_heap_); \
FMOD bool PFX##_full(SNAME *_heap_); \
FMOD size_t PFX##_count(SNAME *_heap_); \
FMOD size_t PFX##_capacity(SNAME *_heap_); \
\
/* Iterator Functions */ \
/* Iterator Allocation and Deallocation */ \
FMOD SNAME##_iter *PFX##_iter_new(SNAME *target); \
FMOD void PFX##_iter_free(SNAME##_iter *iter); \
/* Iterator Initialization */ \
FMOD void PFX##_iter_init(SNAME##_iter *iter, SNAME *target); \
/* Iterator State */ \
FMOD bool PFX##_iter_start(SNAME##_iter *iter); \
FMOD bool PFX##_iter_end(SNAME##_iter *iter); \
/* Iterator Movement */ \
FMOD void PFX##_iter_to_start(SNAME##_iter *iter); \
FMOD void PFX##_iter_to_end(SNAME##_iter *iter); \
FMOD bool PFX##_iter_next(SNAME##_iter *iter); \
FMOD bool PFX##_iter_prev(SNAME##_iter *iter); \
/* Iterator Access */ \
FMOD V PFX##_iter_value(SNAME##_iter *iter); \
FMOD size_t PFX##_iter_index(SNAME##_iter *iter); \
\
/* Default Value */ \
static inline V PFX##_impl_default_value(void) \
{ \
V _empty_value_; \
\
memset(&_empty_value_, 0, sizeof(V)); \
\
return _empty_value_; \
} \
\
/* SOURCE ********************************************************************/
#define HEAP_GENERATE_SOURCE(PFX, SNAME, FMOD, V) \
\
@@ -143,9 +143,9 @@ typedef enum HeapOrder
static SNAME##_iter PFX##_impl_it_start(SNAME *_heap_); \
static SNAME##_iter PFX##_impl_it_end(SNAME *_heap_); \
\
FMOD SNAME *PFX##_new(size_t size, HeapOrder HO, int (*compare)(V, V)) \
FMOD SNAME *PFX##_new(size_t capacity, HeapOrder HO, int (*compare)(V, V)) \
{ \
if (size < 1) \
if (capacity < 1) \
return NULL; \
\
if (HO != MinHeap && HO != MaxHeap) \
@@ -156,7 +156,7 @@ typedef enum HeapOrder
if (!_heap_) \
return NULL; \
\
_heap_->buffer = malloc(sizeof(V) * size); \
_heap_->buffer = malloc(sizeof(V) * capacity); \
\
if (!_heap_->buffer) \
{ \
@@ -164,9 +164,9 @@ typedef enum HeapOrder
return NULL; \
} \
\
memset(_heap_->buffer, 0, sizeof(V) * size); \
memset(_heap_->buffer, 0, sizeof(V) * capacity); \
\
_heap_->capacity = size; \
_heap_->capacity = capacity; \
_heap_->count = 0; \
_heap_->HO = HO; \
_heap_->cmp = compare; \
+6 -6
View File
@@ -80,7 +80,7 @@
\
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
FMOD SNAME *PFX##_new(size_t size); \
FMOD SNAME *PFX##_new(size_t capacity); \
FMOD void PFX##_clear(SNAME *_queue_); \
FMOD void PFX##_free(SNAME *_queue_); \
/* Collection Input and Output */ \
@@ -135,9 +135,9 @@
static SNAME##_iter PFX##_impl_it_start(SNAME *_queue_); \
static SNAME##_iter PFX##_impl_it_end(SNAME *_queue_); \
\
FMOD SNAME *PFX##_new(size_t size) \
FMOD SNAME *PFX##_new(size_t capacity) \
{ \
if (size < 1) \
if (capacity < 1) \
return NULL; \
\
SNAME *_queue_ = malloc(sizeof(SNAME)); \
@@ -145,7 +145,7 @@
if (!_queue_) \
return NULL; \
\
_queue_->buffer = malloc(sizeof(V) * size); \
_queue_->buffer = malloc(sizeof(V) * capacity); \
\
if (!_queue_->buffer) \
{ \
@@ -153,9 +153,9 @@
return NULL; \
} \
\
memset(_queue_->buffer, 0, sizeof(V) * size); \
memset(_queue_->buffer, 0, sizeof(V) * capacity); \
\
_queue_->capacity = size; \
_queue_->capacity = capacity; \
_queue_->count = 0; \
_queue_->front = 0; \
_queue_->rear = 0; \
+5 -5
View File
@@ -71,7 +71,7 @@
\
/* Collection Functions */ \
/* Collection Allocation and Deallocation */ \
FMOD SNAME *PFX##_new(size_t size); \
FMOD SNAME *PFX##_new(size_t capacity); \
FMOD void PFX##_clear(SNAME *_stack_); \
FMOD void PFX##_free(SNAME *_stack_); \
/* Collection Input and Output */ \
@@ -126,9 +126,9 @@
static SNAME##_iter PFX##_impl_it_start(SNAME *_stack_); \
static SNAME##_iter PFX##_impl_it_end(SNAME *_stack_); \
\
FMOD SNAME *PFX##_new(size_t size) \
FMOD SNAME *PFX##_new(size_t capacity) \
{ \
if (size < 1) \
if (capacity < 1) \
return NULL; \
\
SNAME *_stack_ = malloc(sizeof(SNAME)); \
@@ -136,7 +136,7 @@
if (!_stack_) \
return NULL; \
\
_stack_->buffer = malloc(sizeof(V) * size); \
_stack_->buffer = malloc(sizeof(V) * capacity); \
\
if (!_stack_->buffer) \
{ \
@@ -146,7 +146,7 @@
\
memset(_stack_->buffer, 0, sizeof(V) * size); \
\
_stack_->capacity = size; \
_stack_->capacity = capacity; \
_stack_->count = 0; \
\
_stack_->it_start = PFX##_impl_it_start; \