Created
June 9, 2014 18:05
-
-
Save markpapadakis/075a8a0e1000bd665e89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int SSTable::VMResidentRows(Vector<token_t> *const out) const | |
| { | |
| uint8_t *const fileData = (uint8_t *)mmapReader->Data(); | |
| Vector<token_offset> tokens; | |
| tokens.EnsureCapacity(metadata.rowsCnt); | |
| if (offsetSize == 8) | |
| { | |
| for (const uint8_t *indexIt = fileData + indexChunkOffset, *const indexEnd = indexIt + indexChunkSize; indexIt != indexEnd; ) | |
| { | |
| auto *const out = tokens.PushEmpty(); | |
| out->token = *(token_t *)indexIt; indexIt += sizeof(token_t); | |
| indexIt+=(*indexIt) + sizeof(uint8_t); | |
| out->o = *(uint64_t *)indexIt; indexIt+=sizeof(uint64_t); | |
| } | |
| } | |
| else | |
| { | |
| IMPLEMENT_ME; | |
| } | |
| assert_impl(tokens.Size() == metadata.rowsCnt); | |
| const token_offset *const base = tokens.Values(); | |
| uint32_t it = 0; | |
| const uint32_t end = tokens.Size(); | |
| const uint8_t *const dChunk = fileData + dataChunkOffset; | |
| const uint8_t *const dChunkEnd = fileData + (encodingFmtId == ENCODING_VERSION_WINNIE ? indexChunkOffset : fileSize); | |
| if (it == end) | |
| return 0; | |
| tokens.Sort(token_offset::ByOffsetAsc); | |
| if (SwitchFS::EnumResidentVMAs((uint8_t *)fileData, fileSize, dChunk, dChunkEnd - dChunk, | |
| [&it, base, end, dChunk, out](const uint8_t *const chunk, const uint64_t size) | |
| { | |
| const uint64_t offset = unlikely(chunk < dChunk) ? 0 : chunk - dChunk; // Offset in the data chunk | |
| const auto range = range64_t(offset, size); | |
| while (it < end) // iterate tokens[] | |
| { | |
| auto indexValueOffset = base[it].o; | |
| if (range.Contains(indexValueOffset)) | |
| { | |
| out->Append(base[it].token); | |
| ++it; | |
| } | |
| else if (unlikely(offset < indexValueOffset)) | |
| { | |
| // Don't bother | |
| break; | |
| } | |
| else | |
| { | |
| // binary search advance, look for min(tokens[mid].o > offset) | |
| int32_t btm = it, top = end - 1; | |
| const auto next = offset; | |
| while (btm <= top) | |
| { | |
| const auto mid = (btm + top) / 2; | |
| const auto o = base[mid].o; | |
| if (next < o) | |
| { | |
| it = mid; | |
| top= mid - 1; | |
| } | |
| else | |
| { | |
| btm= mid + 1; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ) == -1) | |
| { | |
| IMPLERROUT("Unable to identify resident VMAs\n"); | |
| return -1; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment