Commit Graph

55 Commits

Author SHA1 Message Date
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
Bailey Thompson
3daf2deb09 Add multiset 2017-12-31 16:15:01 -05:00
Bailey Thompson
dcdb8c9c95 Make set iteratively clear
Previously, the set AVL tree would recursively clear. Now, it iteratively clears.
2017-12-31 02:46:23 -05:00
Bailey Thompson
4d665a7e4d Remove debugging from set 2017-12-29 11:58:05 -05:00
Bailey Thompson
e5c15efe41 Add invariant checking in set test 2017-12-29 11:45:05 -05:00
Bailey Thompson
27c04c204a Make set an AVL tree
Instead of using an ordinary binary search tree, an AVL tree is now used.
2017-12-29 00:03:55 -05:00
Bailey Thompson
22f2fb501f Add parent to each node 2017-12-17 17:50:37 -05:00
Bailey Thompson
671504d45b Add test case for vector
Add test case for vector which uses strings allocated dynamically.
2017-12-16 19:05:30 -05:00
Bailey Thompson
613e73bbcc Add unordered_multimap 2017-12-12 23:50:43 -05:00
Bailey Thompson
76966ca188 Add unordered_multiset 2017-12-12 19:49:31 -05:00
Bailey Thompson
dfa195e89d Add unordered_map 2017-12-12 00:24:25 -05:00
Bailey Thompson
3e6033ef7d Add unordered_set 2017-12-10 15:57:38 -05:00
Bailey Thompson
3b043fb4f8 Add unordered_set - still in development 2017-12-10 02:39:55 -05:00
Bailey Thompson
a7d0040615 Add array 2017-12-01 23:03:53 -05:00
Bailey Thompson
1124b2ef6a Add more set tests 2017-11-27 23:55:30 -05:00
Bailey Thompson
0dbf0b1b08 Add set 2017-11-27 22:27:21 -05:00
Bailey Thompson
7bd241f741 Improve formatting
Follow K&R convention.
2017-11-25 23:14:23 -05:00
Bailey Thompson
6188b5a22a Add queue 2017-10-29 21:34:32 -04:00
Bailey Thompson
394cd4ac15 Add stack 2017-10-29 19:44:48 -04:00
Bailey Thompson
35b405a74b Add deque 2017-10-29 13:45:51 -04:00