Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/FheapSet.h
Go to the documentation of this file.
00001 
00009 #ifndef FHEAPS_H
00010 #define FHEAPS_H
00011 
00012 #include "stdinc.h"
00013 #include "Adt.h"
00014 #include "Util.h"
00015 #include "List.h"
00016 #include "ClistSet.h"
00017 
00018 namespace grafalgo {
00019 
00020 typedef int keytyp;
00021 typedef int fheap;
00022 
00027 class FheapSet : public Adt {
00028 public:         FheapSet(int=26);
00029                 ~FheapSet();
00030 
00031         // common methods
00032         void    clear();
00033         void    resize(int);
00034         void    expand(int);
00035         void    copyFrom(const FheapSet&);
00036 
00037         keytyp  key(index) const;               
00038         void    setKey(index,keytyp);
00039         fheap   findmin(fheap) const;   
00040         fheap   meld(fheap,fheap);
00041         fheap   decreasekey(index,keytyp,fheap);
00042         fheap   deletemin(fheap);       
00043         fheap   insert(index,fheap);
00044         fheap   insert(index,fheap,keytyp);
00045         fheap   remove(index, fheap);   
00046 
00047         string& toString(string&) const;
00048         string& heap2string(fheap,string&) const;
00049 private:
00050         static const int MAXRANK = 32;
00051         struct Fnode {                  
00052         keytyp  kee;                    
00053         int     rank;                   
00054         bool    mark;                   
00055         fheap   p, c;                   
00056         };
00057         Fnode   *node;                  
00058         ClistSet *sibs;                 
00059         int     rvec[MAXRANK+1];        
00060         List    *tmpq;                  
00061 
00062         string& heap2string(fheap,bool,string&) const;
00063         void    makeSpace(int);
00064         void    freeSpace();
00065 };
00066 
00071 inline keytyp FheapSet::key(index i) const { return node[i].kee; }
00072 
00077 inline void FheapSet::setKey(index i, keytyp k) {
00078         assert(sibs->suc(i) == i && node[i].p == 0 && node[i].c == 0);
00079         node[i].kee = k;
00080 }
00081 
00086 inline fheap FheapSet::insert(index i, fheap h) { return meld(i,h); }
00087         
00092 inline fheap FheapSet::findmin(fheap h) const { return h; }
00093 
00094 } // ends namespace
00095 
00096 #endif
 All Classes Files Functions Variables Typedefs Friends