根据上面的树形图,最好的方法是简单的多维数组。
- 这允许重复的“键”
- 混合变量类型可以通过使用支持表来实现(参见下面的示例)
与其他方法相比:
- 地图不允许重复键
- 多地图。无法让它发挥作用。尝试了数周。
- 类继承。不将子分支链接到上面的分支。它只是一种公开变量和方法的方法,而无需重复您的工作。
- 还研究了多重集、向量等。
注意:对于大型多维数组,您将需要使用堆内存。
void conversationArray(LPWSTR line)
{
auto conversation = new int[5][10000][100][50]; // conversationID, lineID, objectID, tagid = tag/text
wstring conversationType[3];
auto lineType = new wstring[5][10000]; // conversationID, lineID = string
wstring text[50];
conversationType[0] = L"chat gui";
lineType[0][0] = L"chat";
conversation[0][0][14][12] = 25;
conversation[0][0][15][12] = 30;
lineType[0][1] = L"chat1";
conversation[0][1][15][12] = 500;
lineType[0][2] = L"chat2";
conversation[0][2][15][12] = 60;
conversationType[1] = L"chat gui1";
lineType[1][0] = L"chat-also";
conversation[1][0][15][12] = 33;
// if tag id = 0 then tag is text
conversation[0][0][14][0] = 0;
conversation[0][0][15][0] = 20;
text[0] = line;
text[20] = L"dog";
// print out
int records = 0;
for (int conversationID = 0; conversationID < 5; conversationID++)
{
//sendToReportWindow(L"conversationID: %d\n", conversationID);
for (int lineID = 0; lineID < 10000; lineID++)
{
//sendToReportWindow(L"lineID:%d\n", lineID);
for (int objectID = 0; objectID < 100; objectID++)
{
//sendToReportWindow(L"objectID:%d\n", objectID);
for (int tagID = 0; tagID < 50; tagID++)
{
if (conversation[conversationID][lineID][objectID][tagID] >= 0)
{
if (tagID > 0)
{
sendToReportWindow(L"conversationID:%d type:%s\n", conversationID, conversationType[conversationID].c_str());
sendToReportWindow(L"lineID:%d type:%s\n", lineID, lineType[conversationID][lineID].c_str());
sendToReportWindow(L"conversation[%d][%d][%d][%d]= %d\n", conversationID, lineID, objectID, tagID, conversation[conversationID][lineID][objectID][tagID]);
sendToReportWindow(L"\n");
}
else
{
sendToReportWindow(L"conversationID:%d type:%s\n", conversationID, conversationType[conversationID].c_str());
sendToReportWindow(L"lineID:%d type:%s\n", lineID, lineType[conversationID][lineID].c_str());
sendToReportWindow(L"conversation[%d][%d][%d][%d] text = %s\n", conversationID, lineID, objectID, tagID, text[conversation[conversationID][lineID][objectID][tagID]].c_str());
sendToReportWindow(L"\n");
}
records++;
}
}
}
}
}
sendToReportWindow(L"records:%d\n", records);
sendToReportWindow(L"\n");
// print all records on a specific branch. all lines for conversation 1, line 0
int conversationID = 1; int lineID = 0;
sendToReportWindow(L"Just print a subset of conversation:%d and Line:%d\n", conversationID, lineID);
for (int objectID = 0; objectID < 100; objectID++)
{
for (int tagID = 0; tagID < 50; tagID++)
{
if (conversation[1][0][objectID][tagID] >= 0)
{
if (tagID > 0)
{
sendToReportWindow(L"conversationID:%d type:%s\n", conversationID, conversationType[conversationID].c_str());
sendToReportWindow(L"lineID:%d type:%s\n", lineID, lineType[conversationID][lineID].c_str());
sendToReportWindow(L"conversation[%d][%d][%d][%d]= %d\n", conversationID, lineID, objectID, tagID, conversation[conversationID][lineID][objectID][tagID]);
sendToReportWindow(L"\n");
}
else
{
sendToReportWindow(L"conversationID:%d type:%s\n", conversationID, conversationType[conversationID].c_str());
sendToReportWindow(L"lineID:%d type:%s\n", lineID, lineType[conversationID][lineID].c_str());
sendToReportWindow(L"conversation[%d][%d][%d][%d] text = %s\n", conversationID, lineID, objectID, tagID, text[conversation[conversationID][lineID][objectID][tagID]].c_str());
sendToReportWindow(L"\n");
}
}
}
}
delete[] conversation; delete[] lineType;
}