Skip to content

Commit

Permalink
Fast forward changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoVen committed Jan 30, 2020
1 parent cbf24ab commit b2bef4e
Show file tree
Hide file tree
Showing 25 changed files with 648 additions and 255 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is useful to format all the source files and header in this library using clang-format

.PHONY
main:
clang-format --style=file -i ./src/cmc/*.h
5 changes: 3 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ TODO

[/] Tests
[/] Documentation
[/] Add Function Tables that contains data type functions
(compare, copy, display, free, hash, priority)
[/] Add error codes that can be accessed from the collection's struct

#!! Medium Priority --------------------------------------------------------------------------------

[/] Callback utility
[ ] Add interface that contains data type functions
(compare, copy, display, free, hash, priority)
[ ] Add to iterators struct
[ ] get_value
[ ] get_index
Expand Down
347 changes: 257 additions & 90 deletions src/cmc/bidimap.h

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src/cmc/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
23 changes: 19 additions & 4 deletions src/cmc/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
23 changes: 19 additions & 4 deletions src/cmc/hashset.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
23 changes: 19 additions & 4 deletions src/cmc/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
23 changes: 19 additions & 4 deletions src/cmc/intervalheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
23 changes: 19 additions & 4 deletions src/cmc/linkedlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down
45 changes: 21 additions & 24 deletions src/cmc/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down Expand Up @@ -175,7 +190,6 @@ struct cmc_callbacks_list
struct SNAME *PFX##_new_custom(size_t capacity, \
struct cmc_alloc_node *alloc, \
struct cmc_callbacks_list *callbacks); \
struct SNAME *PFX##_new_from(V *elements, size_t size); \
void PFX##_clear(struct SNAME *_list_, void (*deallocator)(V)); \
void PFX##_free(struct SNAME *_list_, void (*deallocator)(V)); \
/* Customization of Allocation and Callbacks */ \
Expand Down Expand Up @@ -316,23 +330,6 @@ struct cmc_callbacks_list
return _list_; \
} \
\
struct SNAME *PFX##_new_from(V *elements, size_t size) \
{ \
if (size == 0) \
return NULL; \
\
struct SNAME *_list_ = PFX##_new(size + size / 2); \
\
if (!_list_) \
return NULL; \
\
memcpy(_list_->buffer, elements, size * sizeof(V)); \
\
_list_->count = size; \
\
return _list_; \
} \
\
void PFX##_clear(struct SNAME *_list_, void (*deallocator)(V)) \
{ \
if (deallocator) \
Expand Down Expand Up @@ -428,7 +425,7 @@ struct cmc_callbacks_list
return false; \
\
memmove(_list_->buffer, _list_->buffer + 1, \
_list_->count * sizeof(V)); \
(_list_->count - 1) * sizeof(V)); \
\
_list_->buffer[--_list_->count] = (V){ 0 }; \
\
Expand All @@ -441,7 +438,7 @@ struct cmc_callbacks_list
return false; \
\
memmove(_list_->buffer + index, _list_->buffer + index + 1, \
(_list_->count - index) * sizeof(V)); \
(_list_->count - index - 1) * sizeof(V)); \
\
_list_->buffer[--_list_->count] = (V){ 0 }; \
\
Expand Down
23 changes: 19 additions & 4 deletions src/cmc/multimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,31 @@ static const size_t cmc_string_len = 400;
* Custom allocation node. Allows collections to use custom allocation
* functions.
*/
struct cmc_alloc_node
static struct cmc_alloc_node
{
void *(*malloc)(size_t);
void *(*calloc)(size_t, size_t);
void *(*realloc)(void *, size_t);
void (*free)(void *);
};
} cmc_alloc_node_default = { malloc, calloc, realloc, free };

static struct cmc_alloc_node cmc_alloc_node_default = { malloc, calloc, realloc,
free };
/**
* enum cmc_flags
*
* Defines common error codes used by all collections. These are flags that
* indicate if something went wrong in the last operation by the collection.
*/
static struct
{
int OK; // Everything went as expected
int ALLOC; // Allocation failed
int EMPTY; // The collection is empty and the operation could not proceed
int NOT_FOUND; // Key or value not found
int INVALID; // Something is invalid
int OUT_OF_RANGE; // Index out of array range
int DUPLICATE; // Duplicate key or value
int ERROR; // Generic error, usually caused by unexpected behaviour
} cmc_flags = { 0, 1, 2, 3, 4, 5, 6, 7 };

#endif /* CMC_CORE_H */

Expand Down

0 comments on commit b2bef4e

Please sign in to comment.