14 std::streampos *index;
17 nReads = 0; gap = nPos = 0;
21 ReadIndex(const char* readF) {
25 sprintf(indexF, "%s.ridx", readF);
26 fin.open(indexF, std::ios::binary);
27 if (!fin.is_open()) { fprintf(stderr, "Cannot open %s! It may not exist.\n", indexF); exit(-1); }
29 nReads = 0; gap = nPos = 0;
32 fin.read((char*)&nReads, sizeof(nReads));
33 fin.read((char*)&gap, sizeof(gap));
34 fin.read((char*)&nPos, sizeof(nPos));
35 index = new std::streampos[nPos];
36 for (int i = 0; i < nPos; i++) {
37 fin.read((char*)&index[i], sizeof(std::streampos));
43 nReads = 0; gap = nPos = 0;
44 if (index != NULL) delete[] index;
47 //rid 0-based , return crid : current seeked rid
48 long locate(long rid, std::ifstream& out) {
50 out.seekg(0, std::ios::beg);
53 assert(rid >= 0 && rid < nReads);
54 out.seekg(index[rid / gap]);
55 return (rid / gap) * gap;
59 #endif /* READINDEX_H_ */