00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _DOCINFOLIST_HPP
00014 #define _DOCINFOLIST_HPP
00015
00016 #include "IndexTypes.hpp"
00017 #include <iterator>
00018
00019
00021
00030 class DocInfo {
00031 public:
00032 DocInfo() {}
00033 DocInfo(DOCID_T docID, COUNT_T termCount) :
00034 did(docID), tcount(termCount) {}
00035
00036 virtual ~DocInfo() {}
00037
00039 virtual DOCID_T docID() const {return did;}
00040
00042 virtual void docID(DOCID_T id) {did = id;}
00043
00045 virtual COUNT_T termCount() const {return tcount;}
00046
00048 virtual void termCount(COUNT_T c) {tcount = c;}
00049
00052 virtual const LOC_T* positions() const { return NULL; }
00053
00056 virtual void positions(const LOC_T* pos) {}
00057
00058
00059 protected:
00060 DOCID_T did;
00061 COUNT_T tcount;
00062 };
00063
00064
00065
00067
00075 class DocInfoList {
00076 public:
00077 DocInfoList() {}
00078 virtual ~DocInfoList() {}
00079
00080 protected:
00081
00083
00085
00088
00090
00092
00094
00095
00096 public:
00097
00099
00101
00103
00104
00105
00107
00108 public:
00109 iterator() : list(NULL), position(NULL), current(NULL) {}
00110 iterator(const iterator& other) {
00111 list = other.list;
00112 position = other.position;
00113 if ((list) && (other.current) ) {
00114 current = list->newElement();
00115 list->assignElement(current, other.current);
00116 } else {
00117 current = NULL;
00118 }
00119 }
00120 iterator(const DocInfoList* dil, POS_T pos) : list(dil), position(pos) {
00121 if (list) {
00122 if (position != list->endPosition()) {
00123 current = list->newElement();
00124 current = list->getElement(current, position);
00125 } else {
00126 current=NULL;
00127 }
00128 }
00129 }
00130
00131
00132 ~iterator() {
00133 delete(current);
00134 }
00135
00136 DocInfo& operator*() { return *current; }
00137 DocInfo* operator->() { return current; }
00138 iterator& operator++() {
00139 position = list->nextPosition(position);
00140 if (position != list->endPosition())
00141 current = list->getElement(current, position);
00142 return *this;
00143 }
00144
00145 iterator& operator++(int) {
00146 return operator++();
00147 }
00148 bool operator==(const iterator& other) const {
00149 return (list == other.list) && (position == other.position);
00150 }
00151 bool operator!=(const iterator& other) const {
00152 return (list != other.list) || (position != other.position);
00153 }
00154 iterator& operator=(const iterator& other) {
00155 list = other.list;
00156 position = other.position;
00157 if ((list) && (other.current)) {
00158 if (!current)
00159 current = list->newElement();
00160 list->assignElement(current, other.current);
00161 } else {
00162 delete(current);
00163 current = NULL;
00164 }
00165 return *this;
00166 }
00169 void seek(POS_T pos) {
00170 position = pos;
00171 if (position != list->endPosition()) {
00172 if (!current)
00173 current = list->newElement();
00174 current = list->getElement(current, position);
00175 } else {
00176 delete(current);
00177 current = NULL;
00178 }
00179 }
00180
00181 protected:
00182 const DocInfoList* list;
00183 POS_T position;
00184 DocInfo* current;
00185 };
00186
00187 iterator& begin() const {
00188 iterator it(this, beginPosition());
00189 itbegin = it;
00190 return itbegin;
00191 }
00192 iterator& end() const {
00193 iterator it(this, endPosition());
00194 itend = it;
00195 return itend;
00196 }
00197
00198 protected:
00199 mutable DocInfoList::iterator itbegin;
00200 mutable DocInfoList::iterator itend;
00201 friend class iterator;
00202 };
00203
00204
00205 #endif