T dequeue()

in drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/datastructures/BinaryHeapQueue.java [136:163]


    T dequeue(final int index) {
        if ( index < 1 || index > this.size ) {
            return null;
        }

        final T result = this.elements.get(index);

        setElement( index,
                this.elements.get(this.size) );
        this.elements.set(this.size, null);
        this.size--;
        if ( this.size != 0 && index <= this.size ) {
            int compareToParent = 0;
            if ( index > 1 ) {
                compareToParent = compare( this.elements.get(index),
                        this.elements.get(index / 2) );
            }
            if ( index > 1 && compareToParent > 0 ) {
                percolateUpMaxHeap( index );
            } else {
                percolateDownMaxHeap( index );
            }
        }

        result.setQueueIndex(-1);

        return result;
    }