The other day I needed a linked list for the umpteenth time, and instead of going with the old (data, next) pairs, I decided I wanted something a bit more efficient, like an [unrolled linked list][http://en.wikipedia.org/wiki/Unrolled_linked_list “Wikipedia”). This also provided a good opportunity to use the CuTest unit testing framework and do some test-first development.
The result is rather nice, testing actually found a small bug, despite the fact that I was sure can do linked lists in my sleep, and I was so pleased with the performance characteristics (better cache efficiency and far fewer allocations) that I replaced all the lists in Eressea with it.
Code Sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
The code is on github for you to use as you please.