Exemple #1
0
FibonacciHeapNode<Key, Data> * FibonacciHeap<Key, Data>::Delete(FibonacciHeapNode<Key, Data> * node)
{
	FibonacciHeapNode<Key, Data> * parent = node->m_pParent;
	if (parent != NULL) {
		Cut(node, parent);
		CascadingCut(parent);
	}
	m_pMin = node;
	return ExtractMin();
}
Exemple #2
0
 void fibonacci_heap::CascadingCut(Node* y) {
   Node* z = y->parent;
   if (z != nullptr) {
     if (y->marked == false) {
       y->marked = true;
     } else {
       Cut(y,z);
       CascadingCut(z);
     }
   }
 }
Exemple #3
0
static void * ReplaceKeyData(PQueue *h, PQueueElement *x, intptr_t key, void *data)
{
    void *odata;
    int okey;
    PQueueElement *y;
    int r;

    odata = x->Data;
    okey = x->Key;

    /*
     * we can increase a key by deleting and reinserting, that
     * requires O(lgn) time.
     */
    if ((r = comparedata(h, key, data, x)) > 0) {

        /* XXX - bad code! */
        abort();
        DeleteElement(h, x);

        if (data) memcpy(x->Data , data,h->ElementSize);
        x->Key = key;

        insertel(h, x);

        return odata;
    }

    if (data) memcpy(x->Data , data, h->ElementSize);
    x->Key = key;

    /* because they are equal, we don't have to do anything */
    if (r == 0)
        return odata;

    y = x->Parent;

    if (okey == key)
        return odata;

    if (y != NULL && compare(h, x, y) <= 0) {
        Cut(h, x, y);
        CascadingCut(h, y);
    }

    /*
     * the = is so that the call from delete will delete the proper
     * element.
     */
    if (compare(h, x, h->Minimum) <= 0)
        h->Minimum = x;

    return odata;
}
Exemple #4
0
void FibonacciHeap<Key, Data>::CascadingCut(FibonacciHeapNode<Key, Data> * node)
{
	FibonacciHeapNode<Key, Data> * parent = node->m_pParent;
	if (parent != NULL) {
		if (!node->m_bMarked)
			node->m_bMarked = true;
		else {
			Cut(node, parent);
			CascadingCut(parent);
		}
	}
}
Exemple #5
0
FibonacciHeapNode<Key, Data> * FibonacciHeap<Key, Data>::DecreaseKey(FibonacciHeapNode<Key, Data> * node, const Key & newKey)
{
	if (newKey < node->m_Key) {
		node->m_Key = newKey;
		FibonacciHeapNode<Key, Data> * parent = node->m_pParent;
		if (parent != NULL && node->m_Key < parent->m_Key) {
			Cut(node, parent);
			CascadingCut(parent);
		}
		if (node->m_Key < m_pMin->m_Key) m_pMin = node;
	}
	return node;
}
void DecreaseKey(heap **H,heap *x,int k)
{
    heap *y,*back;
    y=x->parent;
    x->time=k;
    if(y!=NULL && k<y->time)
    {
        cut(*H,x,y);
        CascadingCut(*H,y);
    }
    if(k<(*H)->time)
        (*H)=x;
}
void CascadingCut(heap *H,heap *y)
{
    heap *z;
    z=y->parent;
    if(z!=NULL)
    {
        if(y->mark==0)
            y->mark=1;
        else
        {
            cut(H,y,z);
            CascadingCut(H,z);
        }
    }
}
Exemple #8
0
  void fibonacci_heap::DecreaseKey(Node* x, ii key) {

    if (key > x->key)
      return; // error: new key is greater than current key

    x->key = key;
    Node* y = x->parent;

    if (y != nullptr && x->key < y->key) {
      Cut(x,y);
      CascadingCut(y);
    }

    if (x->key < min->key)
      min = x;
  }