You do not need to know the maximum skipist level before creating it, if you are ready to dynamically change the size of the head, the size of which is exactly equal to maxlevel
. Since maxlevel
approximately log N
, changing the size of the head is rare, and when it does, it requires very little work. If you really wanted to avoid this, you could create a head with enough power for the entire available storage, although it would be a waste of space if most of your skipists were several hundred elements.
This all works because the search procedure for a skipist never rises to the level; just down. Therefore, the insertion of a new node with a higher level than any existing node does not require modification of any existing node, except for the chapter, which must be changed to point to the new node at its highest level. (Otherwise, a new level will be useless.)
As a curious implementation detail, there is no need to store the size of the node; the fact that a node is specified at level i
is sufficient to demonstrate that node has at least i
levels, so you never need to compare i
with the size of the node. You need to know only the size of the head.
source share