
/*
**  This file forms part of the GOBLIN C++ Class Library.
**
**  Written by Christian Fremuth-Paeger, May 2000.
**  
**  Copying, compiling, distribution and modification
**  of this source code is permitted only in accordance
**  with the GOBLIN general licence information.
*/             


#if !defined(_FIBHEAP_H_)

#define _FIBHEAP_H_

#include <queue.h>


template <class TItem,class TKey>
class fibonacciHeap : public goblinQueue<TItem,TKey>
{
private:

    TItem*          pred;
    TItem*          first;
    TItem*          next;
    TItem*          previous;
    TItem*          rank;
    char*           status;
    TItem*          bucket;
    TItem*          nextLink;
    TKey*           key;

    TItem           card;
    TItem           n;
    TItem           k;
    TItem           minimal;
    TItem           firstLink;
	TItem 			UNDEFINED;

public:

    fibonacciHeap(TItem nn,goblinController &thisContext) throw();
    ~fibonacciHeap() throw();
    
    unsigned long   Size() throw();
    unsigned long   Allocated() throw();

    void            Init() throw();
    void            Display(TItem i) throw(ERRange);
    char*           Display() throw();

private:

    void            Link(TItem v,TItem w) throw(ERRange,ERRejected);
    void            Push(TItem w) throw(ERRejected);
    void            Restore() throw();
    void            Cut(TItem w) throw(ERRange,ERRejected);
    
public:

    void            Insert(TItem w,TKey alpha) throw(ERRange,ERRejected);
    TItem           Delete() throw(ERRejected);
    void            Delete(TItem w) throw(ERRange);
    TKey            Key(TItem w) throw(ERRange);
    void            ChangeKey(TItem w,TKey alpha) throw(ERRange);
    TItem           Peek() throw(ERRejected);
    bool            Empty() throw() {return (card==0);};
    TItem           Cardinality() throw() {return card;};

};


#endif
