/*! *Load bucket of specific disk address into memory. **/ nodePtr getNodeByMemAddr(uint32_t& memAddr, uint64_t diskAddr) { if (diskAddr%2==1) return nodePtr(); if (memAddr>=count_ && memAddr!=(uint32_t)-1&&count_!=0) return nodePtr(); if (memAddr!=(uint32_t)-1) { NodeType* t = nodes[memAddr].pNode_; if (t->getDiskAddr()==diskAddr) { return nodePtr(nodes[memAddr], memAddr); } } uint32_t i = findInCache(diskAddr); if (i != (uint32_t)-1) { memAddr = i; return nodePtr(nodes[i], memAddr); } if (count_<CACHE_SIZE) { NodeType* t = new NodeType(f_); t->load(diskAddr); nodes[count_] = _cache_node_(t); memAddr = count_; count_++; return nodePtr(nodes[memAddr], memAddr); } //cout<< "getNodeByMemAddr()\n"; memAddr = findSwitchOut(); //cout<<"\nswitch out-: "<<memAddr<<endl; kickOutNodes(memAddr); NodeType* t = new NodeType(f_); t->load(diskAddr); nodes[memAddr] = _cache_node_(t); return nodePtr(nodes[memAddr], memAddr); }
void load_(vector<uint32_t>& indexes) { uint32_t idx = indexes.front(); indexes.erase(indexes.begin()); NodeType* n = nodes[idx].pNode_ ; nodes[idx] = _cache_node_(n); for (uint32_t i=0; i<n->getSize(); i++) { if (n->getDiskAddr(i)==(uint64_t)-1) continue; if (n->getDiskAddr(i)%2==0) continue; NodeType* t = new NodeType(f_); t->load(n->getDiskAddr(i)); nodes[count_] = _cache_node_(t); indexes.push_back(count_); n->setMemAddr(i, count_); count_++; if (count_>=CACHE_SIZE) { indexes.clear(); return; } } }
/*! *Get a new node in cache which is stroed in position 'diskAddr'. **/ nodePtr newNode(uint64_t diskAddr) { if (count_<CACHE_SIZE) { NodeType* t = new NodeType(f_); t->load(diskAddr); nodes[count_] = _cache_node_(t); nodePtr p(nodes[count_]); count_++; return p; } uint32_t ret = findSwitchOut(); kickOutNodes(ret); NodeType* t = new NodeType(f_); t->load(diskAddr); nodes[ret] = _cache_node_(t); nodePtr p(nodes[ret]); return p; }
/** *Load data from disk. **/ uint32_t load() { vector<uint32_t> indexes; indexes.push_back(0); NodeType* t = new NodeType(f_); t->load(rootAddr_); nodes[count_] = _cache_node_(t); count_++; while (indexes.size()>0) { load_(indexes); } return count_; }