while (true)
{
ReadStatus status = btreeGet(txn ref key ref data DbFileReadFlagsNone);
switch (status)
{
case ReadStatusSuccess:
dataStreamPosition = ;
dataStreamSetLength(dataSize);
put = (IPut)formatterDeserialize(dataStream);
return true;
case ReadStatusBufferSmall: //扩容
if (keyBufferLength < keySize)
{
keyStreamSetLength(keySize);
key = DbEntryOut(keyStreamGetBuffer());
}
if (dataBufferLength < dataSize)
{
dataStreamSetLength(dataSize);
data = DbEntryOut(dataStreamGetBuffer());
}
continue;
case ReadStatusNotFound:
case ReadStatusKeyEmpty:
default:
return false;
}
}
}
五遍历
public List<IPut> Find()
{
List<IPut> custList = new List<IPut>();
using (DbBTreeCursor cursor = btreeOpenCursor(txn DbFileCursorCreateFlagsNone))
{
IPut cust = null;
while (GetNextRecord(cursor ref cust))
custListAdd(cust);
}
return custList;
}
private bool GetNextRecord(DbBTreeCursor cursor ref IPut cust)
{
ReadStatus status;
keyStreamSetLength(keyStreamCapacity);
dataStreamSetLength(dataStreamCapacity);
DbEntry key = DbEntryOut(keyStreamGetBuffer());
DbEntry data = DbEntryOut(dataStreamGetBuffer());
do
{
status = cursorGet(ref key ref data DbFileCursorGetModeNext DbFileCursorReadFlagsNone);
switch (status)
{
case ReadStatusNotFound: return false;
case ReadStatusKeyEmpty: continue; // skip deleted records
case ReadStatusBufferSmall:
if (keyBufferLength < keySize)
{
keyStreamSetLength(keySize);
key = DbEntryOut(keyStreamGetBuffer());
[] [] [] [] [] [] []