00001 //File: $Id$ 00002 // Author: John Wu <John.Wu at ACM.org> 00003 // Copyright 2000-2012 the Regents of the University of California 00004 #ifndef IBIS_ROSTER_H 00005 #define IBIS_ROSTER_H 00006 #include "array_t.h" 00007 #include "util.h" 00010 00019 class ibis::roster { 00020 public: 00021 ~roster() {clear();}; 00022 roster(const ibis::column* c, const char* dir = 0); 00023 roster(const ibis::column* c, ibis::fileManager::storage* st, 00024 uint32_t offset = 8); 00025 00026 const char* name() const {return "roster list";} 00027 const ibis::column* getColumn() const {return col;} 00028 uint32_t size() const; 00029 00030 int read(const char* idxfile); 00031 int read(ibis::fileManager::storage* st); 00032 00034 void print(std::ostream& out) const; 00036 int write(const char* dt) const; 00038 int writeSorted(const char* dt) const; 00039 00040 const array_t<uint32_t>& array() const {return ind;} 00041 inline uint32_t operator[](uint32_t i) const; 00042 00048 template <typename T> 00049 int locate(const ibis::array_t<T>& vals, 00050 ibis::bitvector& positions) const; 00053 template <typename T> 00054 int locate(const ibis::array_t<T>& vals, 00055 std::vector<uint32_t>& positions) const; 00056 00062 template <typename T> 00063 int locate(const std::vector<T>& vals, 00064 ibis::bitvector& positions) const; 00067 template <typename T> 00068 int locate(const std::vector<T>& vals, 00069 std::vector<uint32_t>& positions) const; 00070 00073 template <class T> 00074 static long mergeBlock2(const char *dsrc, const char *dout, 00075 const uint32_t segment, array_t<T>& buf1, 00076 array_t<T>& buf2, array_t<T>& buf3); 00077 00078 // /// A templated multi-way merge sort algorithm for a data file with 00079 // /// values of the same type. Return the number of passes if 00080 // /// successful, other return a negative number to indicate error. 00081 // template <class Type, uint32_t mway=64, uint32_t block=8192> 00082 // static int diskSort(const char *datafile, const char *scratchfile); 00083 00084 protected: 00085 // /// This function performs the initial sort of blocks. Entries in each 00086 // /// (@c mway * @c block)-segment is sorted and written back to the same 00087 // /// data file. 00088 // template <class Type, uint32_t mway, uint32_t block> 00089 // static int diskSortInit(const char *datafile); 00090 // /// Merge blocks. The variable @c segment contains the number of 00091 // /// consecutive entries (a segement) that are already sorted. To 00092 // /// consecutive such segments will be merged. 00093 // template <class Type, uint32_t mway, uint32_t block> 00094 // static int diskSortMerge(const char *from, const char *to, 00095 // uint32_t segment); 00096 00097 uint32_t locate(const double& val) const; 00098 00099 template <typename T> int 00100 icSearch(const std::vector<T>& vals, std::vector<uint32_t>& pos) const; 00101 template <typename T> int 00102 oocSearch(const std::vector<T>& vals, std::vector<uint32_t>& pos) const; 00103 template <typename inT, typename myT> int 00104 locate2(const std::vector<inT>&, std::vector<uint32_t>&) const; 00105 template <typename T> int 00106 icSearch(const ibis::array_t<T>& vals, std::vector<uint32_t>& pos) const; 00107 template <typename T> int 00108 oocSearch(const ibis::array_t<T>& vals, std::vector<uint32_t>& pos) const; 00109 template <typename inT, typename myT> int 00110 locate2(const ibis::array_t<inT>&, std::vector<uint32_t>&) const; 00111 00112 private: 00113 // private member variables 00114 const ibis::column* col; 00115 array_t<uint32_t> ind; 00116 mutable int inddes; 00117 00118 // private member functions 00119 void clear() {ind.clear(); if (inddes>=0) UnixClose(inddes);}; 00120 int write(FILE* fptr) const; 00121 00123 void icSort(const char* f = 0); 00125 void oocSort(const char* f = 0); 00126 template <class T> 00127 long oocSortBlocks(const char *src, const char *dest, 00128 const char *ind, const uint32_t mblock, 00129 array_t<T>& dbuf1, array_t<T>& dbuf2, 00130 array_t<uint32_t>& ibuf) const; 00131 template <class T> 00132 long oocMergeBlocks(const char *dsrc, const char *dout, 00133 const char *isrc, const char *iout, 00134 const uint32_t mblock, const uint32_t stride, 00135 array_t<T>& dbuf1, array_t<T>& dbuf2, 00136 array_t<uint32_t>& ibuf1, 00137 array_t<uint32_t>& ibuf2) const; 00138 00139 roster(); // not implemented 00140 roster(const roster&); // not implemented 00141 const roster& operator=(const roster&); // not implemented 00142 }; // ibis::roster 00143 00144 namespace ibis { 00145 template <> int 00146 roster::locate(const std::vector<double>&, ibis::bitvector&) const; 00147 template <> int 00148 roster::locate(const ibis::array_t<double>&, ibis::bitvector&) const; 00149 } 00150 00152 inline uint32_t ibis::roster::operator[](uint32_t i) const { 00153 uint32_t tmp = UINT_MAX; 00154 if (i < ind.size()) { 00155 tmp = ind[i]; 00156 } 00157 else if (inddes >= 0) { 00158 if (static_cast<off_t>(i*sizeof(uint32_t)) != 00159 UnixSeek(inddes, i*sizeof(uint32_t), SEEK_SET)) 00160 return tmp; 00161 if (sizeof(uint32_t) != UnixRead(inddes, &tmp, sizeof(uint32_t))) 00162 return UINT_MAX; 00163 } 00164 else { 00165 LOGGER(ibis::gVerbose > 0) 00166 << "Warning -- roster(ind[" << ind.size() << "], inddes=" 00167 << inddes << ")::operator[]: index i (" << i 00168 << ") is out of range"; 00169 } 00170 return tmp; 00171 } // ibis::roster::operator[] 00172 #endif // IBIS_ROSTER_H 00173
![]() |