/* * Constructs a new skip list optimized for the given * expected upper bound for the number of nodes. */

public SkipList(long maxNodes) { // probability set to 0.25 and maximum level // of list is depending on expected number of nodes // (see paper for mathematical background)this(OPT_PROB,(int)Math.ceil(Math.log(maxNodes)/Math.log(1/OPT_PROB))-1);}

/* * Generates with help of randomizer the level of a new element. * The higher a level, the less probable it is (see paper). * Levels begin at 0 (not at 1 like in the paper). */ private int generateRandomLevel() { int newLevel = 0; while (newLevel<myMaxLevel &&Math.random()<myProbability ) { newLevel++; } return newLevel; }

/* * Inserts a new node into the list. * If the key already exists, its node is updated to the new value. */ public void insert(int searchKey, int value) { // update pointers to next elements on each level and // levels run from 0 up to myMaxLevel. SkipListElement[] update = new SkipListElement[myMaxLevel+1];