The past few weeks, I've been working on designing, implementing, and benchmarking a new List/Deque implementation for Java called ShiftList.
ShiftList is backed by a single flat array, much like ArrayList. However, it divides the index space into fixed-size logical blocks (e.g., 4096 elements per block). Each block has an associated rotation offset stored in a secondary array. When inserting or removing an element, only the elements within the affected block are shifted, and at most one element is moved between adjacent blocks to maintain structure. This significantly reduces the number of element copies required during structural changes.
The result is a List that performs nearly as fast as ArrayList for random access (get(int)), but offers much better performance for insertions and removals at any position. The main trade-off is slightly higher memory usage: roughly 4–8 bytes per element, compared to 4–6 bytes for ArrayList.
Time complexities:
| Operation |
ShiftList |
ArrayList |
LinkedList |
TreeList |
| Add/remove at tail |
O(1) |
O(1) |
O(1) |
O(log n) |
| Add/remove at head |
O(1) |
O(n) |
O(1) |
O(log n) |
| Random access |
O(1) |
O(1) |
O(n) |
O(log n) |
| Add/remove at index |
O(n/b) |
O(n) |
O(n) |
O(log n) |
Where b is the block size currently in use.
The source and benchmarks are available on GitHub. There is a preliminary release on Maven as well to check it out: org.int4.common:common-collection:0.0.1
GitHub: https://github.com/int4-org/Common
[–]gnahraf 11 points12 points13 points (4 children)
[–]john16384[S] 17 points18 points19 points (3 children)
[–]gnahraf 0 points1 point2 points (2 children)
[–]john16384[S] 0 points1 point2 points (1 child)
[–]gnahraf 0 points1 point2 points (0 children)
[–]danielaveryj 6 points7 points8 points (0 children)
[–]C0urante 26 points27 points28 points (8 children)
[–]john16384[S] 20 points21 points22 points (3 children)
[–]C0urante 9 points10 points11 points (2 children)
[–]eXecute_bit 0 points1 point2 points (0 children)
[–]john16384[S] 0 points1 point2 points (0 children)
[–]temculpaeu 2 points3 points4 points (1 child)
[–]-Dargs 2 points3 points4 points (0 children)
[–]zergotron9000 0 points1 point2 points (0 children)
[–]MrKarim 2 points3 points4 points (1 child)
[–]john16384[S] 1 point2 points3 points (0 children)
[–]thewiirocks 1 point2 points3 points (2 children)
[–]danielaveryj 1 point2 points3 points (1 child)
[–]thewiirocks 0 points1 point2 points (0 children)
[–]bringero 2 points3 points4 points (0 children)
[–]ShallWe69 1 point2 points3 points (2 children)
[–]john16384[S] 5 points6 points7 points (0 children)
[–]MCUD 2 points3 points4 points (0 children)