Use sorted lists when there are just few entries

We now use a sorted list instead of a dict until the number of elements
on the respective level exceeds a certain threshold of `MAX_LIST_SIZE`,
which is a constant that for now is set to the value `8`.