Exemple #1
0
Heap KMV::getkmv(set<int>& data)
{
    Heap kmv;
    set<int>::iterator is;
    for(is=data.begin(); is!=data.end(); is++)
    {
        double h = hash(*is + 1);
        if(kmv.size() < size)
            kmv.push(HeapEntry(h, *is));
        else
        {
            if(h < kmv.top())
            {
                kmv.pop();
                kmv.push(HeapEntry(h, *is));
            }
        }
    }
    return kmv;
}
void PriorityQueue<ValueType>::enqueue(ValueType value, double priority) {
    if (count == heap.size()) heap.add(HeapEntry());
    int index = count++;
    heap[index].value = value;
    heap[index].priority = priority;
    heap[index].sequence = enqueueCount++;
    while (index > 0) {
        int parent = (index - 1) / 2;
        if (takesPriority(parent, index)) break;
        swapHeapEntries(parent, index);
        index = parent;
    }
}