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


#if !defined(_BINHEAP_H_)

#define _BINHEAP_H_

#include <queue.h>


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

    TItem*          v;
    TItem*          index;
    TKey*           key;         

    TItem           maxIndex;
    TItem           n;
	TItem 			UNDEFINED;

public:

    binaryHeap(TItem nn,goblinController &thisContext) throw();
    ~binaryHeap() throw();
    
    void            Init() throw();
    unsigned long   Size() throw();
    unsigned long   Allocated() throw();

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

    void            UpHeap(TItem w) throw(ERRange);
    void            DownHeap(TItem w) throw(ERRange);
    
    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 (maxIndex==0);};
    TItem           Cardinality() throw() {return maxIndex;};

};


#endif
