Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/DkBstSet.h
Go to the documentation of this file.
00001 
00009 #ifndef DKBSTSET_H
00010 #define DKBSTSET_H
00011 
00012 #include "SaBstSet.h"
00013 
00014 namespace grafalgo {
00015 
00020 class DkBstSet : public SaBstSet {
00021 public:         DkBstSet(int);
00022                 ~DkBstSet();
00023         static  const int MAX2 = Util::BIGINT32-1;  
00024 
00025         // common methods
00026         void    clear();
00027         void    resize(int);
00028         void    expand(int);
00029         void    copyFrom(const DkBstSet&);
00030 
00031         // access methods
00032         keytyp  key1(index);               
00033         keytyp  key2(index);              
00034         index   first(bst) const;        
00035         index   next(index) const;      
00036         index   access(keytyp,bst);
00037         keytyp  min2(bst);              
00038 
00039         // modifiers
00040         void    setkey(index,keytyp,keytyp); 
00041         void    change2(keytyp,bst); 
00042         bst     insert(index,bst);
00043         bst     remove(index,bst);        
00044         bst     join(bst,index,bst);     
00045         BstPair split(index,bst);       
00046 
00047 private:
00048         keytyp  *dmin;                  // delta min value for key 2
00049         keytyp  *dkey;                  // delta key value for key 2
00050         void    virtual rotate(index);
00051 
00052         virtual string& node2string(index, string&) const;
00053 
00054         void    makeSpace(int);
00055         void    freeSpace();
00056 };
00057 
00061 void inline DkBstSet::setkey(index i, keytyp k1, keytyp k2) {
00062         assert(0 <= i && i <= n() && k2 <= MAX2);
00063         assert(node[i].p == 0 && node[i].left == 0 && node[i].right == 0);
00064         node[i].kee = k1; dmin[i] = k2; dkey[i] = 0;
00065 }
00066 
00071 keytyp inline DkBstSet::key1(index i) {
00072         assert(1 <= i && i <= n());
00073         return node[i].kee;
00074 }
00075 
00080 keytyp inline DkBstSet::min2(bst s) {
00081         assert(1 <= s && s <= n());
00082         return dmin[s];
00083 }
00084 
00090 void inline DkBstSet::change2(keytyp diff, bst s) {
00091         assert(1 <= s && s <= n());
00092         dmin[s] += diff;
00093 }
00094 
00095 } // ends namespace
00096 
00097 #endif
 All Classes Files Functions Variables Typedefs Friends