CIndexTreeNodeFile* CIndexTreeBlockFile::GetIndexNode(void* pvKey, int iKeySize) { CIndexTreeNodeFile* pcCurrent; CIndexTreeChildNode* pcChild; if ((iKeySize == 0) || (pvKey == NULL)) { return NULL; } pcCurrent = mpcRoot; for (int i = 0; i < iKeySize; i++) { char c = ((char*)pvKey)[i]; pcChild = pcCurrent->Get(c); if (pcChild->IsMemory()) { pcCurrent = pcChild->u.mpcMemory; } else if (pcChild->IsFile()) { // Load that shit! } else { return NULL; } } return pcCurrent; }
void TestIndexTreeNodeFileRootMemory(void) { CIndexTreeNodeFile* pcNode; CIndexTreeBlockFile cIndex; CIndexTreeNodeFile cChildNode; CIndexTreeChildNode* pcResult; cIndex.FakeInit(); pcNode = (CIndexTreeNodeFile*)malloc(sizeof(CIndexTreeNodeFile) + sizeof(CIndexTreeChildNode)); //Node. No object. One child. pcNode->Init(&cIndex, NULL); AssertTrue(pcNode->IsEmpty()); AssertFalse(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); AssertTrue(pcNode->ValidateNodesEmpty()); pcNode->Contain(33); AssertFalse(pcNode->IsEmpty()); AssertTrue(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); gcLogger.SetBreakOnError(FALSE); AssertFalse(pcNode->ValidateNodesEmpty()); gcLogger.SetBreakOnError(TRUE); AssertInt(33, pcNode->GetFirstIndex()); AssertInt(33, pcNode->GetLastIndex()); pcNode->Set(33, &cChildNode); AssertFalse(pcNode->IsEmpty()); AssertTrue(pcNode->HasNodes()); AssertFalse(pcNode->HasObject()); AssertInt(1, pcNode->NumInitialisedIndexes()); AssertTrue(pcNode->ValidateNodesEmpty()); pcResult = pcNode->Get(33); AssertTrue(pcResult->IsMemory()); AssertPointer(&cChildNode, pcResult->u.mpcMemory); AssertFalse(pcNode->ContainsIndex(32)); AssertTrue(pcNode->ContainsIndex(33)); AssertFalse(pcNode->ContainsIndex(34)); free(pcNode); }