• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

DistRUSHp.h

Go to the documentation of this file.
00001 /* 
00002  * File:   DistRUSHp.h
00003  * Author: ywkang
00004  *
00005  * Created on February 25, 2010, 4:44 PM
00006  */
00007 
00008 #ifndef _DISTRUSHP_H
00009 #define _DISTRUSHP_H
00010 #include "Distributor.h"
00011 #include <set>
00012 #include <map>
00013 #include <list>
00014 #include <iostream>
00015 
00016 using namespace std;
00017 
00018 namespace VDRIVE {
00019 
00020     
00021     
00022     class DistRUSHp : public Distributor {
00023     public:
00024         DistRUSHp(int argc, char **argv) ;
00025         DistRUSHp(const DistRUSHp& orig);
00026         DistRUSHp(xercesc::DOMElement* data);
00027         virtual ~DistRUSHp();
00028         double hash(int64_t key1, int64_t key2, int64_t key3) const;
00029 
00030         virtual std::list<Disk*>* placeExtent(int64_t virtualVolumeId, int64_t position) ;
00031         virtual void setClusters(std::list<std::list<Disk*>*>* clusters, std::list<uint32_t>* weights);
00032         virtual void setConfiguration(std::list<Disk*>* disks, int64_t extentsize, int32_t copies);
00033         virtual void setDisks(std::list<Disk*>* disks);
00034         virtual std::list<Disk*>* getDisks() const;
00035         virtual int64_t getExtentsize() const;
00036         virtual int32_t getCopies() const;
00037         virtual xercesc::DOMElement* toXML(xercesc::DOMDocument* doc) const;
00038         static std::string getXMLRootType() {
00039             return std::string("Rushp");
00040         }
00041         Disk* RUSHp(int64_t x, int64_t r, int32_t j) const;
00042     private:
00043         int32_t copies;
00044         int32_t j;   // cluster id
00045         map<int64_t, list<Disk*>* > clusters;
00046 
00047         //map<int32_t, int32_t > weights;
00048         vector<int64_t> weights;
00049         vector<Disk*> alldisks;
00050 
00051         virtual void debug();
00052 
00053         Disk* getDisk(int32_t c, int64_t offset) const {
00054             map<int64_t, list<Disk*>* >::const_iterator ci = clusters.find(c);
00055             list<Disk*>* disks = ci->second;
00056 
00057             list<Disk*>::const_iterator it = (*disks).begin();
00058             for (int i = 0; i < offset; i++, ++it);
00059 
00060             return *it;
00061         }
00062 
00063 
00064         int64_t getMj(int32_t c) const {
00065             if (c < 0) {
00066                 cout << "error" << endl;
00067             }
00068             map<int64_t, list<Disk*>* >::const_iterator ci = clusters.find(c);
00069             //cout << "cluster " << c  << ", mj = " << ci->second->size() << endl;
00070             return ci->second->size();
00071         }
00072 /*
00073         int64_t getNj(int32_t c) const {
00074             int64_t sum = 0;
00075             for (int i =0 ;i <= c; i++) {
00076                 sum += getMj(i);
00077             }
00078             if (sum < 0) {
00079                 cout << "error " << endl;
00080             }
00081             cout << "nj = " << sum << endl;
00082             return sum;
00083         }
00084 */
00085         int64_t getWj(int32_t c) const {
00086             return weights[c];
00087         }
00088 
00089         // return the total amount of weight in cluster j
00090         int64_t getMPrimej(int32_t c) const {
00091             int64_t numdisks = getMj(c);
00092 
00093             //cout << "m'j = " << numdisks * getWj(c) << endl;
00094             return numdisks * getWj(c);
00095         }
00096 
00097         // return the total amount of weight in cluster 0 ~ j-1
00098         int64_t getNPrimej(int32_t c) const {
00099             int64_t sum = 0;
00100             //cout << "cluster " << c << endl;
00101             for (int i =0 ;i < c; i++) {
00102                 sum += getMPrimej(i);
00103               //  cout << "subset sum =  " << sum << endl;
00104             }
00105             //cout <<  ", n'j = " << sum << endl;
00106             return sum;
00107         }
00108         
00109  
00110         //Robert Jenkins's hash function
00111     };
00112 
00113     
00114 
00115 }
00116 
00117 #endif  /* _DISTRUSHP_H */
00118 

Generated on Mon Oct 11 2010 13:09:26 for CppDistributors by  doxygen 1.7.2