do {
LinkedList<?> currentList = (LinkedList<?>)calendar.elementAt(index);
//dumpList("dequeueNextEvent top of loop", currentList);
if ( (currentList.size() > 0) &&
((Event) currentList.getFirst()).getNextTime() < buckettop) {
Event curr = (Event) currentList.removeFirst();
lastbucket = index;
lastprio = curr.getNextTime();
qsize--;
if (qsize < bot_threshold) {
calendarResize(nbuckets / 2);
}
//System.out.println("Dequeued-A event time " + curr.getNextTime());
return curr;
} else {
++index;
if (index == nbuckets) {
index = 0; // modulo
}
//System.out.println("Dequeued prepare to check next bucket " + index);
buckettop += width;
}
} while (index != lastbucket);
// perform direct search for minimum priority event
// find it by examing the first event in each bucket
//System.out.println("Dequeued go to a direct search");
int lowIndex = -1;
double minTime = 0.0;
for (int j = 0; j < nbuckets; j++) {
LinkedList<?> currentList = (LinkedList<?>)calendar.elementAt(j);
if (currentList.size() > 0) {
Event curr = (Event)currentList.getFirst();
double currTime = curr.getNextTime();
if ( (currTime < minTime) || (lowIndex == -1)) {
lowIndex = j;
minTime = currTime;
}
}
}
Event curr = (Event) ( (LinkedList<?>) calendar.elementAt(lowIndex)).removeFirst();
lastbucket = lowIndex;
lastprio = minTime;
buckettop = ( (int) (lastprio / width) + 1) * width + (0.5 * width);
qsize--;
if (qsize < bot_threshold) {