Commit Graph

74 Commits

Author SHA1 Message Date
Bailey Thompson
eff1e3e59a Optimize deque block allocations (#122)
Rather than allocating a new block every time it is needed, it will
check the other end of the outer array to see if blocks are available
but not in use. This way, if a deque is being used like a queue, the
block count will not arbitrarily grow.
2020-08-20 21:19:41 -04:00
Bailey Thompson
c77aa4d87b Add ordered retrieval (#120)
Add ordered retrieval functions to the tree-based containers.
2020-08-20 01:35:28 -04:00
Bailey Thompson
6af6778702 Create add_all functions (#118)
Create add_all functions for many containers, which adds all the elements
of an array to the container.
2020-08-19 15:13:11 -04:00
Bailey Thompson
b7cd535c6c Add "overflow" checking (#115)
Add checking and correction for unsigned integer wrapping.
2020-08-18 01:49:11 -04:00
Bailey Thompson
e3bc87298f Simplify return values (#114)
Introduce bk_err and bk_bool rather than using int for both of these.
This means that the function definition now specifies whether 0 means
no error, or whether it means false.
2020-08-17 16:55:29 -04:00
Bailey Thompson
a6225f9571 Add overflow checking to array (#111) 2020-08-17 02:49:10 -04:00
Bailey Thompson
eade6e4586 Bug bash (#105)
Valgrind previously did not fail the test suite when there were memory
leaks or invalid accesses. Due to this, a few bugs slipped in. These bugs
have been fixed, and now every container has more test cases.
Furthermore, the test suite has been updated to fail if Valgrind reports
any errors.
2020-08-16 19:17:59 -04:00
Bailey Thompson
5c4752c198 Reduce calls to malloc in multimap (#102)
Reduce the number of malloc calls in multimap. Improves efficiency by 40%.
2020-08-16 11:22:09 -04:00
Bailey Thompson
fd3d3fc8b8 Reduce calls to malloc in map (#101)
Reduce the number of malloc calls in map. Improves efficiency by 40%.
2020-08-15 02:44:41 -04:00
Bailey Thompson
ac725ef147 Reduce calls to malloc in multiset (#100)
Reduce the number of malloc calls in multiset. Improves efficiency by 30%.
2020-08-15 01:52:54 -04:00
Bailey Thompson
aab2a074d5 Reduce calls to malloc in set (#99)
Reduce the number of malloc calls in set. Improves efficiency by 40%.
2020-08-15 00:21:46 -04:00
Bailey Thompson
33023d09c4 Reduce calls to malloc in unordered_multimap (#97)
Reduce the number of malloc calls in unordered_multimap. Improves
efficiency by 60% (meaning it takes less than half the time that it used to).
2020-08-14 13:06:14 -04:00
Bailey Thompson
dea440d2a7 Reduce calls to malloc in unordered_map (#96)
Reduce the number of malloc calls in unordered_map. Improves
efficiency by 50% (meaning it takes half the time that it used to).
2020-08-14 11:43:25 -04:00
Bailey Thompson
8aa141785d Fix coverage (#95) 2020-08-14 01:53:35 -04:00
Bailey Thompson
115433497a Reduce calls to malloc in unordered_multiset (#93)
Reduce the number of malloc calls in
unordered_multiset. Improves efficiency by 40%.
2020-08-13 23:51:33 -04:00
Bailey Thompson
1e11cba319 Reduce malloc calls in unordered set (#92)
Reduce the number of malloc calls in
unordered_set. Improves efficiency by 40%.
2020-08-13 22:02:06 -04:00
Bailey Thompson
33fe92dade Use GitHub actions as test suite (#91)
Use GitHub actions as a test suite. Can get rid of CircleCI,
and now Valgrind is part of the test suite.
2020-08-12 19:06:49 -04:00
Bailey Thompson
2123ca2891 Use size_t for all sizes in priority_queue (#83) 2020-08-10 14:22:03 -04:00
Bailey Thompson
124d68fbf9 Reduce malloc calls in queue (#79) 2020-08-10 12:44:14 -04:00
Bailey Thompson
af869f2b46 Reduce malloc calls in stack (#78) 2020-08-10 12:30:51 -04:00
Bailey Thompson
c74b0c4caf Reduce calls to malloc in list (#77)
Reduce the number of malloc calls in list. Improves efficiency by 15%.
2020-08-10 03:00:48 -04:00
Bailey Thompson
c05d97e2c9 Reduce malloc calls (#75)
Reduce the number of malloc calls. Improves efficiency by 40%.
2020-08-10 00:25:33 -04:00
Bailey Thompson
00bf7d433e Change deque block size (#74)
The block size for deque now scales based on the element size.
This means that the byte count in each block remains the same,
but with bigger elements, fewer elements may be stored in each
block (but still the same number of bytes). There is an exception
for elements that are very large, and a minimum element count
exists for the block in that case.
2020-08-09 03:36:01 -04:00
Bailey Thompson
0c45fc80c6 Rewrite deque (#72)
The deque is now 40% faster and the code is much cleaner.
2020-08-08 21:28:48 -04:00
Bailey Thompson
fdde32d981 Refactor array (#71)
The array container is now 3% faster.
2020-08-08 19:05:44 -04:00
Bailey Thompson
48b0751b6c Stub malloc toggle (#69) 2020-08-07 16:57:41 -04:00
Bailey Thompson
e2587bc379 Add puzzle test case (#63) 2020-08-07 01:44:03 -04:00
Bailey Thompson
163fdb32ce Fix bug which occurred when removing the last node from a list (#64) 2020-08-07 01:40:05 -04:00
Bailey Thompson
eb4f8fb1ae Fix test warnings (#62) 2020-08-06 23:18:24 -04:00
Bailey Thompson
8d45509d68 Forward list optimization (#53)
Add a tail pointer which is either NULL or points to the back of the list. This improves the performance when adding to the back of the list many times in a row.
2019-06-09 00:30:30 -04:00
Bailey Thompson
411af131c2 Fix negative modulo for C89 (#45)
In C89, negative integer division and modulo is implementation-defined.

Case 1: division rounds to 0 (C89/90, C99, C11, C18)
-9 / 7 -> -1
-9 % 7 -> -2

Case 2: division rounds to negative infinity (C89/90)
-9 / 7 -> -2
-9 % 7 -> 5

This change fixes the deque data structure from having negative division and modulo to prevent this implementation-defined behavior.
2019-05-21 17:46:53 -04:00
Bailey Thompson
4332c05e0b Add compilation documentation (#36)
Add documentation for how to compile dynamic and static libraries.
2019-05-08 04:33:25 -04:00
Bailey Thompson
e2d596e4bd Refactor tests (#31)
Refactor tests in order for the component or logic that they are testing to be contained into individual sub-tests instead of all tests being contained in one big test for the whole data structure.

Add testing for out-of-memory (OOM) conditions. This makes the source code now 100% covered.

Bug fix! A bug has been identified and fixed in the list data structure in the list_add_last function. This bug would occur when adding an item to the back of the list because the pointers were not being updated properly.

Minor Bug fix! A bug has been identified and fixed in the unordered_set, unordered_map, unordered_multiset, and unordered_multimap data structures in their respective unordered_xxx_put functions. This bug would occur in an out-of-memory condition, which would cause the size of the collection to increase without actually adding the new element to it.
2019-05-04 17:59:20 -04:00
Bailey Thompson
10a11dc1aa Add zero length arrays (#28) 2019-05-02 20:03:31 -04:00
Bailey Thompson
24ca9d9d9b Make c89 compatible (#27) 2019-05-02 19:34:27 -04:00
Bailey Thompson
5fe6b40c3e Make c90 compatible (#26) 2019-05-02 14:49:36 -04:00
Bailey Thompson
20e8839143 Add more testing (#23)
Increase code coverage so that other than the out-of-memory conditions, the code is entirely covered.

Some areas of the code have been tweaked for performance optimizations.

Bug fix! A bug has been identified and fixed in the unordered_multiset data structure in the unordered_multiset_remove_all function.

This bug would occur when more than one entry exists in the bucket in which the element is occupying, and that element had a count of more than one.
2019-04-30 23:22:36 -04:00
Bailey Thompson
e2ee62af08 Fix bug reported in Issue #16
Before this bug was fixed, it would result in a segmentation fault due to an off-by-one error in the trim function in the deque file. This off by one error was due to the fact that the end index points to the index after the last allocated block. However, in the trim function, the end index was treated as the last allocated block. Thus, in the case that the last block was completely full, the trim function would function as if there were another block after that block with one item in it. Thus, this block would be copied from without the memory being allocated.
2018-07-15 12:29:54 -07:00
Bailey Thompson
dd9e099605 Add function used to obtain vector capacity 2018-01-25 19:48:27 -05:00
Bailey Thompson
00b849c42f Make queue trim by factors
Previously, queue would trim every 64 pops. However, this does not make sense for a queue with thousands of elements. Thus, now queue trims every time that the amount of trims times 1.5 is greater or equal to the size of the queue.
2018-01-24 21:28:13 -05:00
Bailey Thompson
ba17208b48 Add vector of vectors test case 2018-01-12 12:09:19 -05:00
Bailey Thompson
c51bdfefef Remove leading underscore from some identifiers
From the C standard, section 7.1.3:
 - All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
 - All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.

The internal struct which defines each container used to start with an underscore followed by a lower case letter. The leading underscore for those identifiers have been replaced in order to prevent undefined behaviour.
2018-01-11 20:01:08 -05:00
Bailey Thompson
37e935892d Clean up code for test cases 2018-01-03 01:02:07 -05:00
Bailey Thompson
c0fa8b66cd Clean up code for test cases 2018-01-03 01:00:25 -05:00
Bailey Thompson
bd73635e02 Improve variable names in test cases 2018-01-03 00:45:33 -05:00
Bailey Thompson
055e2875dd Convert stack and queue tests to test for bool 2018-01-01 19:03:49 -05:00
Bailey Thompson
7b18182e47 Add function to vector and array to get data
Add a function "get_data" to vector and array which lets the user access the data pointer which the vector and array operate on.
2018-01-01 18:42:30 -05:00
Bailey Thompson
bcfa6bb4ce Add priority_queue 2018-01-01 18:06:13 -05:00
Bailey Thompson
d5471f6f9f Add multimap 2017-12-31 22:35:57 -05:00
Bailey Thompson
0ff4917e92 Add map 2017-12-31 17:33:26 -05:00