Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Add Unrolled List Implementation #23

Open Kalkwst opened 1 year ago

Kalkwst commented 1 year ago

An unrolled linked list is a variation of the traditional linked list data structure where each node contains a small array of elements instead of a single element. This allows for more efficient memory usage and faster access to elements that are stored close to each other in the list. The size of the array, or the block size, is usually chosen based on the characteristics of the data and the expected usage of the list.

From a more technical perspective, an unrolled linked list is a linked list with the difference that instead of each node containing a single element, it contains an array of elements, called a block. These blocks reduce the number of pointers required, thus decreasing the cache miss rate and improving performance. Each node also contains a pointer to the next node in the list and the number of elements stored in the current node. The size of the block is chosen based on the expected usage of the list, and it can be adjusted based on the performance characteristics. The search and insertion operations are done by traversing the list and looking for the correct position in the current block. The deletion operation is done by copying the elements from the following block to the current block and removing the next one. The time complexity of the search, insertion and deletion operations is usually O(n/b) where b is the block size, which is faster than the O(n) time complexity of a typical singly linked list.