diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c1c647..6eeb416 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,19 +6,19 @@ set(CMAKE_C_STANDARD 90) set(CMAKE_C_FLAGS "-pedantic -ldl -g -O0 -Wall -fprofile-arcs -ftest-coverage") add_executable(Containers tst/test.c tst/test.h - src/array.c src/array.h tst/array.c - src/vector.c src/vector.h tst/vector.c - src/deque.c src/deque.h tst/deque.c - src/forward_list.c src/forward_list.h tst/forward_list.c - src/list.c src/list.h tst/list.c - src/set.c src/set.h tst/set.c - src/map.c src/map.h tst/map.c - src/multiset.c src/multiset.h tst/multiset.c - src/multimap.c src/multimap.h tst/multimap.c - src/unordered_set.c src/unordered_set.h tst/unordered_set.c - src/unordered_map.c src/unordered_map.h tst/unordered_map.c - src/unordered_multiset.c src/unordered_multiset.h tst/unordered_multiset.c - src/unordered_multimap.c src/unordered_multimap.h tst/unordered_multimap.c - src/stack.c src/stack.h tst/stack.c - src/queue.c src/queue.h tst/queue.c - src/priority_queue.c src/priority_queue.h tst/priority_queue.c) + src/array.c src/include/array.h tst/array.c + src/vector.c src/include/vector.h tst/vector.c + src/deque.c src/include/deque.h tst/deque.c + src/forward_list.c src/include/forward_list.h tst/forward_list.c + src/list.c src/include/list.h tst/list.c + src/set.c src/include/set.h tst/set.c + src/map.c src/include/map.h tst/map.c + src/multiset.c src/include/multiset.h tst/multiset.c + src/multimap.c src/include/multimap.h tst/multimap.c + src/unordered_set.c src/include/unordered_set.h tst/unordered_set.c + src/unordered_map.c src/include/unordered_map.h tst/unordered_map.c + src/unordered_multiset.c src/include/unordered_multiset.h tst/unordered_multiset.c + src/unordered_multimap.c src/include/unordered_multimap.h tst/unordered_multimap.c + src/stack.c src/include/stack.h tst/stack.c + src/queue.c src/include/queue.h tst/queue.c + src/priority_queue.c src/include/priority_queue.h tst/priority_queue.c) diff --git a/README.md b/README.md index 595e440..476f39a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,85 @@ This library provides various containers. Each container has utility functions t Inspired by the C++ standard library; however, implemented using C with different function interfaces as the C++ standard library but with the same container names. -## Sequence containers +## Setup +There are two types of library files which can be generated: dynamic and static. Both ways will be described below using clang. However, the steps are the same with gcc except `clang` is to be replaced with `gcc`. + +### Dynamic Library + +1. Navigate to your C working directory + +2. Run: +``` +git clone ssh://git@github.com/bkthomps/Containers.git +cd Containers/src +``` + +3. To create a dynamic library, run: +``` +clang -shared -o containers.so -fPIC *.c +``` + +4. Now, you can copy and paste the `include` directory and `containers.so` to any project that you would like to use the dynamic library with. + +5. Thus, for an example program, the directory would look like this: + * containers.so + * include/ + * array.h + * deque.h + * ... + * test.c + +6. The test.c file could then contain, for example: +``` +#include "include/vector.h" +``` + +7. And the project would be compiled with: +``` +clang test.c -o test containers.so -ldl +``` + +### Static Library + +1. Navigate to your C working directory + +2. Run: +``` +git clone ssh://git@github.com/bkthomps/Containers.git +cd Containers/src +``` + +3. To create a static library, run: +``` +gcc *.c -c -fpic +ar rcs containers.a *.o +rm *.o +``` + +4. Now, you can copy and paste the `include` directory and `containers.a` to any project that you would like to use the static library with. + +5. Thus, for an example program, the directory would look like this: + * containers.a + * include/ + * array.h + * deque.h + * ... + * test.c + +6. The test.c file could then contain, for example: +``` +#include "include/vector.h" +``` + +7. And the project would be compiled with: +``` +clang test.c -o test containers.a -ldl +``` + +## Container Types +The container types that this library contains are described below. + +### Sequence containers Data structures which can be accessed sequentially. * array - static contiguous array * vector - dynamic contiguous array @@ -19,21 +97,21 @@ Data structures which can be accessed sequentially. * forward_list - singly-linked list * list - doubly-linked list -## Associative containers +### Associative containers Data structures that can be quickly searched which use comparators. * set - collection of unique keys, sorted by keys * map - collection of key-value pairs, sorted by keys, keys are unique * multiset - collection of keys, sorted by keys * multimap - collection of key-value pairs, sorted by keys -## Unordered associative containers +### Unordered associative containers Data structures that can be quickly searched which use hashing. * unordered_set - collection of unique keys, hashed by keys * unordered_map - collection of key-value pairs, hashed by keys, keys are unique * unordered_multiset - collection of keys, hashed by keys * unordered_multimap - collection of key-value pairs, hashed by keys -## Container adaptors +### Container adaptors Data structures which adapt other containers to enhance functionality. * stack - adapts a container to provide stack (last-in first-out) * queue - adapts a container to provide queue (first-in first-out) diff --git a/src/array.c b/src/array.c index e56e811..3c75911 100644 --- a/src/array.c +++ b/src/array.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "array.h" +#include "include/array.h" struct internal_array { size_t bytes_per_item; diff --git a/src/deque.c b/src/deque.c index e3c9621..79bc6c6 100644 --- a/src/deque.c +++ b/src/deque.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "deque.h" +#include "include/deque.h" static const int BLOCK_SIZE = 8; static const double RESIZE_RATIO = 1.5; diff --git a/src/forward_list.c b/src/forward_list.c index 73b784d..13dd7d9 100644 --- a/src/forward_list.c +++ b/src/forward_list.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "forward_list.h" +#include "include/forward_list.h" struct internal_forward_list { size_t bytes_per_item; diff --git a/src/array.h b/src/include/array.h similarity index 98% rename from src/array.h rename to src/include/array.h index 2b89728..1c466cb 100644 --- a/src/array.h +++ b/src/include/array.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_ARRAY_H #define CONTAINERS_ARRAY_H +#include + /** * The array data structure, which is a static contiguous array. */ diff --git a/src/deque.h b/src/include/deque.h similarity index 99% rename from src/deque.h rename to src/include/deque.h index df2bc8a..4f89dee 100644 --- a/src/deque.h +++ b/src/include/deque.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_DEQUE_H #define CONTAINERS_DEQUE_H +#include + /** * The deque data structure, which is a doubly-ended queue. */ diff --git a/src/forward_list.h b/src/include/forward_list.h similarity index 99% rename from src/forward_list.h rename to src/include/forward_list.h index 071717c..b0bc349 100644 --- a/src/forward_list.h +++ b/src/include/forward_list.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_FORWARD_LIST_H #define CONTAINERS_FORWARD_LIST_H +#include + /** * The forward_list data structure, which is a singly-linked list. */ diff --git a/src/list.h b/src/include/list.h similarity index 99% rename from src/list.h rename to src/include/list.h index ff4566c..d67d072 100644 --- a/src/list.h +++ b/src/include/list.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_LIST_H #define CONTAINERS_LIST_H +#include + /** * The list data structure, which is a doubly-linked list. */ diff --git a/src/map.h b/src/include/map.h similarity index 98% rename from src/map.h rename to src/include/map.h index 7f6c2db..83bb5dd 100644 --- a/src/map.h +++ b/src/include/map.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_MAP_H #define CONTAINERS_MAP_H +#include + /** * The map data structure, which is a collection of key-value pairs, sorted by * keys, keys are unique. diff --git a/src/multimap.h b/src/include/multimap.h similarity index 99% rename from src/multimap.h rename to src/include/multimap.h index d5be70b..842d14a 100644 --- a/src/multimap.h +++ b/src/include/multimap.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_MULTIMAP_H #define CONTAINERS_MULTIMAP_H +#include + /** * The multimap data structure, which is a collection of key-value pairs, sorted * by keys. diff --git a/src/multiset.h b/src/include/multiset.h similarity index 98% rename from src/multiset.h rename to src/include/multiset.h index 673cefe..54ea67d 100644 --- a/src/multiset.h +++ b/src/include/multiset.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_MULTISET_H #define CONTAINERS_MULTISET_H +#include + /** * The multiset data structure, which is a collection of key-value pairs, sorted * by keys, keys are unique diff --git a/src/priority_queue.h b/src/include/priority_queue.h similarity index 99% rename from src/priority_queue.h rename to src/include/priority_queue.h index 54133e6..52bfe56 100644 --- a/src/priority_queue.h +++ b/src/include/priority_queue.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_PRIORITY_QUEUE_H #define CONTAINERS_PRIORITY_QUEUE_H +#include + /** * The priority_queue data structure, which adapts a container to provide a * priority queue. Adapts the vector container. diff --git a/src/queue.h b/src/include/queue.h similarity index 98% rename from src/queue.h rename to src/include/queue.h index a09e60d..04c59a0 100644 --- a/src/queue.h +++ b/src/include/queue.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_QUEUE_H #define CONTAINERS_QUEUE_H +#include + /** * The queue data structure, which adapts a container to provide a queue * (first-in first-out). Adapts the deque container. diff --git a/src/set.h b/src/include/set.h similarity index 98% rename from src/set.h rename to src/include/set.h index df16624..dc3773b 100644 --- a/src/set.h +++ b/src/include/set.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_SET_H #define CONTAINERS_SET_H +#include + /** * The set data structure, which is a collection of unique keys, sorted by keys. */ diff --git a/src/stack.h b/src/include/stack.h similarity index 98% rename from src/stack.h rename to src/include/stack.h index 1855220..337f88a 100644 --- a/src/stack.h +++ b/src/include/stack.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_STACK_H #define CONTAINERS_STACK_H +#include + /** * The stack data structure, which adapts a container to provide a stack * (last-in first-out). Adapts the deque container. diff --git a/src/unordered_map.h b/src/include/unordered_map.h similarity index 99% rename from src/unordered_map.h rename to src/include/unordered_map.h index f7c68ba..c99d737 100644 --- a/src/unordered_map.h +++ b/src/include/unordered_map.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_UNORDERED_MAP_H #define CONTAINERS_UNORDERED_MAP_H +#include + /** * The unordered_map data structure, which is a collection of key-value pairs, * hashed by keys, keys are unique diff --git a/src/unordered_multimap.h b/src/include/unordered_multimap.h similarity index 99% rename from src/unordered_multimap.h rename to src/include/unordered_multimap.h index 417d172..56d8a3c 100644 --- a/src/unordered_multimap.h +++ b/src/include/unordered_multimap.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_UNORDERED_MULTIMAP_H #define CONTAINERS_UNORDERED_MULTIMAP_H +#include + /** * The unordered_multimap data structure, which is a collection of key-value * pairs, hashed by keys. diff --git a/src/unordered_multiset.h b/src/include/unordered_multiset.h similarity index 99% rename from src/unordered_multiset.h rename to src/include/unordered_multiset.h index 703d14a..8ed737d 100644 --- a/src/unordered_multiset.h +++ b/src/include/unordered_multiset.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_UNORDERED_MULTISET_H #define CONTAINERS_UNORDERED_MULTISET_H +#include + /** * The unordered_multiset data structure, which is a collection of keys, hashed * by keys. diff --git a/src/unordered_set.h b/src/include/unordered_set.h similarity index 99% rename from src/unordered_set.h rename to src/include/unordered_set.h index 7eff180..fb2f9db 100644 --- a/src/unordered_set.h +++ b/src/include/unordered_set.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_UNORDERED_SET_H #define CONTAINERS_UNORDERED_SET_H +#include + /** * The unordered_set data structure, which is a collection of unique keys, * hashed by keys. diff --git a/src/vector.h b/src/include/vector.h similarity index 99% rename from src/vector.h rename to src/include/vector.h index 6012334..89b4cd2 100644 --- a/src/vector.h +++ b/src/include/vector.h @@ -23,6 +23,8 @@ #ifndef CONTAINERS_VECTOR_H #define CONTAINERS_VECTOR_H +#include + /** * The vector data structure, which is a dynamic contiguous array. */ diff --git a/src/list.c b/src/list.c index 12c1db1..95096de 100644 --- a/src/list.c +++ b/src/list.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "list.h" +#include "include/list.h" struct internal_list { size_t bytes_per_item; diff --git a/src/map.c b/src/map.c index 2863b1f..6b28c08 100644 --- a/src/map.c +++ b/src/map.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "map.h" +#include "include/map.h" struct internal_map { size_t key_size; diff --git a/src/multimap.c b/src/multimap.c index 2204858..09e9c13 100644 --- a/src/multimap.c +++ b/src/multimap.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "multimap.h" +#include "include/multimap.h" struct internal_multimap { size_t key_size; diff --git a/src/multiset.c b/src/multiset.c index a2a2c85..4f231c7 100644 --- a/src/multiset.c +++ b/src/multiset.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "multiset.h" +#include "include/multiset.h" struct internal_multiset { size_t key_size; diff --git a/src/priority_queue.c b/src/priority_queue.c index 46fc351..71fb1ca 100644 --- a/src/priority_queue.c +++ b/src/priority_queue.c @@ -20,11 +20,10 @@ * SOFTWARE. */ -#include #include #include -#include "vector.h" -#include "priority_queue.h" +#include "include/vector.h" +#include "include/priority_queue.h" struct internal_priority_queue { vector data; diff --git a/src/queue.c b/src/queue.c index b806050..5095f26 100644 --- a/src/queue.c +++ b/src/queue.c @@ -20,9 +20,8 @@ * SOFTWARE. */ -#include -#include "deque.h" -#include "queue.h" +#include "include/deque.h" +#include "include/queue.h" static const double TRIM_RATIO = 1.5; diff --git a/src/set.c b/src/set.c index 5258dca..0581991 100644 --- a/src/set.c +++ b/src/set.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "set.h" +#include "include/set.h" struct internal_set { size_t key_size; diff --git a/src/stack.c b/src/stack.c index 6e9d35b..b0f612a 100644 --- a/src/stack.c +++ b/src/stack.c @@ -20,9 +20,8 @@ * SOFTWARE. */ -#include -#include "deque.h" -#include "stack.h" +#include "include/deque.h" +#include "include/stack.h" struct internal_stack { deque deque_data; diff --git a/src/unordered_map.c b/src/unordered_map.c index 19a6fb0..e105a3a 100644 --- a/src/unordered_map.c +++ b/src/unordered_map.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "unordered_map.h" +#include "include/unordered_map.h" static const int STARTING_BUCKETS = 8; static const double RESIZE_AT = 0.75; diff --git a/src/unordered_multimap.c b/src/unordered_multimap.c index a958aab..367943d 100644 --- a/src/unordered_multimap.c +++ b/src/unordered_multimap.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "unordered_multimap.h" +#include "include/unordered_multimap.h" static const int STARTING_BUCKETS = 8; static const double RESIZE_AT = 0.75; diff --git a/src/unordered_multiset.c b/src/unordered_multiset.c index 70a7a13..dece4c8 100644 --- a/src/unordered_multiset.c +++ b/src/unordered_multiset.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "unordered_multiset.h" +#include "include/unordered_multiset.h" static const int STARTING_BUCKETS = 8; static const double RESIZE_AT = 0.75; diff --git a/src/unordered_set.c b/src/unordered_set.c index 8456cf0..3565d72 100644 --- a/src/unordered_set.c +++ b/src/unordered_set.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "unordered_set.h" +#include "include/unordered_set.h" static const int STARTING_BUCKETS = 8; static const double RESIZE_AT = 0.75; diff --git a/src/vector.c b/src/vector.c index 290dd69..fcee19f 100644 --- a/src/vector.c +++ b/src/vector.c @@ -20,10 +20,9 @@ * SOFTWARE. */ -#include #include #include -#include "vector.h" +#include "include/vector.h" static const int START_SPACE = 8; static const double RESIZE_RATIO = 1.5; diff --git a/tst/array.c b/tst/array.c index 911b254..fc2e2dd 100644 --- a/tst/array.c +++ b/tst/array.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/array.h" +#include "../src/include/array.h" static void test_invalid_init(void) { diff --git a/tst/deque.c b/tst/deque.c index 7fe63e2..5d75d5d 100644 --- a/tst/deque.c +++ b/tst/deque.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/deque.h" +#include "../src/include/deque.h" static void test_invalid_init(void) { diff --git a/tst/forward_list.c b/tst/forward_list.c index 436b4f5..bada179 100644 --- a/tst/forward_list.c +++ b/tst/forward_list.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/forward_list.h" +#include "../src/include/forward_list.h" static void test_invalid_init(void) { diff --git a/tst/list.c b/tst/list.c index 3706488..3730a93 100644 --- a/tst/list.c +++ b/tst/list.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/list.h" +#include "../src/include/list.h" static void test_invalid_init(void) { diff --git a/tst/map.c b/tst/map.c index 5e880bf..6d36366 100644 --- a/tst/map.c +++ b/tst/map.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/map.h" +#include "../src/include/map.h" /* * Include this struct to verify the tree. diff --git a/tst/multimap.c b/tst/multimap.c index 3ee06f1..f6b9cf7 100644 --- a/tst/multimap.c +++ b/tst/multimap.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/multimap.h" +#include "../src/include/multimap.h" /* * Include this struct to verify the tree. diff --git a/tst/multiset.c b/tst/multiset.c index 9254010..68fe26d 100644 --- a/tst/multiset.c +++ b/tst/multiset.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/multiset.h" +#include "../src/include/multiset.h" /* * Include this struct to verify the tree. diff --git a/tst/priority_queue.c b/tst/priority_queue.c index 346412c..7c57d54 100644 --- a/tst/priority_queue.c +++ b/tst/priority_queue.c @@ -1,6 +1,6 @@ #include "test.h" -#include "../src/vector.h" -#include "../src/priority_queue.h" +#include "../src/include/vector.h" +#include "../src/include/priority_queue.h" /* * Include this for the stubs. diff --git a/tst/queue.c b/tst/queue.c index 7171abe..c3c900d 100644 --- a/tst/queue.c +++ b/tst/queue.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/queue.h" +#include "../src/include/queue.h" static void test_invalid_init(void) { diff --git a/tst/set.c b/tst/set.c index 21fc568..46159e4 100644 --- a/tst/set.c +++ b/tst/set.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/set.h" +#include "../src/include/set.h" /* * Include this struct to verify the tree. diff --git a/tst/stack.c b/tst/stack.c index 1416ddb..6134d60 100644 --- a/tst/stack.c +++ b/tst/stack.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/stack.h" +#include "../src/include/stack.h" static void test_invalid_init(void) { diff --git a/tst/unordered_map.c b/tst/unordered_map.c index a82f420..1abc79e 100644 --- a/tst/unordered_map.c +++ b/tst/unordered_map.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/unordered_map.h" +#include "../src/include/unordered_map.h" static int compare_int(const void *const one, const void *const two) { diff --git a/tst/unordered_multimap.c b/tst/unordered_multimap.c index 99128f4..2d40a58 100644 --- a/tst/unordered_multimap.c +++ b/tst/unordered_multimap.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/unordered_multimap.h" +#include "../src/include/unordered_multimap.h" static int compare_int(const void *const one, const void *const two) { diff --git a/tst/unordered_multiset.c b/tst/unordered_multiset.c index 1da920c..2538fdb 100644 --- a/tst/unordered_multiset.c +++ b/tst/unordered_multiset.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/unordered_multiset.h" +#include "../src/include/unordered_multiset.h" static int compare_int(const void *const one, const void *const two) { diff --git a/tst/unordered_set.c b/tst/unordered_set.c index 914856a..ff4d2e6 100644 --- a/tst/unordered_set.c +++ b/tst/unordered_set.c @@ -1,5 +1,5 @@ #include "test.h" -#include "../src/unordered_set.h" +#include "../src/include/unordered_set.h" static int compare_int(const void *const one, const void *const two) { diff --git a/tst/vector.c b/tst/vector.c index bc9ce79..5e71528 100644 --- a/tst/vector.c +++ b/tst/vector.c @@ -1,6 +1,6 @@ #include #include "test.h" -#include "../src/vector.h" +#include "../src/include/vector.h" static void test_invalid_init(void) {