void IterateDict(ulong dictId, IFieldHandler keyHandler, IFieldHandler valueHandler) { if (_visitor != null && !_visitor.StartDictionary()) { return; } var o = ObjectDB.AllDictionariesPrefix.Length; var prefix = new byte[o + PackUnpack.LengthVUInt(dictId)]; Array.Copy(ObjectDB.AllDictionariesPrefix, prefix, o); PackUnpack.PackVUInt(prefix, ref o, dictId); _trkv.SetKeyPrefix(prefix); var protector = _tr.TransactionProtector; long prevProtectionCounter = 0; long pos = 0; while (true) { protector.Start(); if (pos == 0) { _trkv.SetKeyPrefix(prefix); if (!_trkv.FindFirstKey()) { break; } } else { if (protector.WasInterupted(prevProtectionCounter)) { _trkv.SetKeyPrefix(prefix); if (!_trkv.SetKeyIndex(pos)) { break; } } else { if (!_trkv.FindNextKey()) { break; } } } _fastVisitor.MarkCurrentKeyAsUsed(_trkv); prevProtectionCounter = protector.ProtectionCounter; if (_visitor == null || _visitor.StartDictKey()) { var keyReader = new KeyValueDBKeyReader(_trkv); IterateHandler(keyReader, keyHandler, false, null); _visitor?.EndDictKey(); } if (protector.WasInterupted(prevProtectionCounter)) { _trkv.SetKeyPrefix(prefix); if (!_trkv.SetKeyIndex(pos)) { break; } } if (_visitor == null || _visitor.StartDictValue()) { var valueReader = new KeyValueDBValueReader(_trkv); IterateHandler(valueReader, valueHandler, false, null); _visitor?.EndDictValue(); } pos++; } _visitor?.EndDictionary(); }
void IterateDict(ulong dictId, IFieldHandler keyHandler, IFieldHandler valueHandler) { if (_visitor != null && !_visitor.StartDictionary()) { return; } var o = ObjectDB.AllDictionariesPrefix.Length; var prefix = new byte[o + PackUnpack.LengthVUInt(dictId)]; Array.Copy(ObjectDB.AllDictionariesPrefix, prefix, o); PackUnpack.PackVUInt(prefix, ref o, dictId); long prevProtectionCounter = 0; long pos = 0; Span <byte> keyBuffer = stackalloc byte[512]; while (true) { if (pos == 0) { if (!_trkv.FindFirstKey(prefix)) { break; } } else { if (_trkv.CursorMovedCounter != prevProtectionCounter) { if (!_trkv.SetKeyIndex(prefix, pos)) { break; } } else { if (!_trkv.FindNextKey(prefix)) { break; } } } _fastVisitor.MarkCurrentKeyAsUsed(_trkv); prevProtectionCounter = _trkv.CursorMovedCounter; if (_visitor == null || _visitor.StartDictKey()) { var keyReader = new SpanReader(_trkv.GetKey(ref MemoryMarshal.GetReference(keyBuffer), keyBuffer.Length).Slice(prefix.Length)); IterateHandler(ref keyReader, keyHandler, false, null); _visitor?.EndDictKey(); } if (_trkv.CursorMovedCounter != prevProtectionCounter) { if (!_trkv.SetKeyIndex(prefix, pos)) { break; } } if (_visitor == null || _visitor.StartDictValue()) { var valueReader = new SpanReader(_trkv.GetValue()); IterateHandler(ref valueReader, valueHandler, false, null); _visitor?.EndDictValue(); } pos++; } _visitor?.EndDictionary(); }