public void Insert(IEnumerable <KeyValuePair <BsonValue, PageAddress> > items, int order, BufferSlice buffer) { var query = order == Query.Ascending ? items.OrderBy(x => x.Key, _collation) : items.OrderByDescending(x => x.Key, _collation); var offset = 0; foreach (var item in query) { buffer.WriteIndexKey(item.Key, offset); var keyLength = IndexNode.GetKeyLength(item.Key, false); if (keyLength > MAX_INDEX_KEY_LENGTH) { throw LiteException.InvalidIndexKey($"Sort key must be less than {MAX_INDEX_KEY_LENGTH} bytes."); } offset += keyLength; buffer.Write(item.Value, offset); offset += PageAddress.SIZE; _remaining++; } _count = _remaining; }
/// <summary> /// Create new index node and persist into page segment /// </summary> public IndexNode(IndexPage page, byte index, BufferSlice segment, byte slot, byte level, BsonValue key, PageAddress dataBlock) { _page = page; _segment = segment; this.Position = new PageAddress(page.PageID, index); this.Slot = slot; this.Level = level; this.Key = key; this.DataBlock = dataBlock; this.NextNode = PageAddress.Empty; this.Next = new PageAddress[level]; this.Prev = new PageAddress[level]; for (var i = 0; i < level; i++) { this.SetPrev((byte)i, PageAddress.Empty); this.SetNext((byte)i, PageAddress.Empty); } // persist in buffer read only data segment[P_SLOT] = slot; segment[P_LEVEL] = level; segment.Write(dataBlock, P_DATA_BLOCK); segment.WriteIndexKey(key, P_KEY); // prevNode/nextNode must be defined as Empty segment.Write(this.NextNode, P_NEXT_NODE); page.IsDirty = true; }
public void Insert(IEnumerable <KeyValuePair <BsonValue, PageAddress> > items, int order, BufferSlice buffer) { var query = order == Query.Ascending ? items.OrderBy(x => x.Key) : items.OrderByDescending(x => x.Key); var offset = 0; foreach (var item in query) { buffer.WriteIndexKey(item.Key, offset); offset += GetKeyLength(item.Key); buffer.Write(item.Value, offset); offset += PageAddress.SIZE; _remaining++; } _count = _remaining; }