private Tuple <PropertyId, BinaryData> EncodeDataRecord( PropertyTag propertyTag, PropertyValue propertyValue, IHeapOnNodeGenerator heapOnNodeGenerator, InternalNIDAllocator nidAllocator, List <Tuple <NID, BID> > propertiesAllocatedOnSubnodes) { if (propertyTag.Type.IsFixedLength()) { var size = propertyTag.Type.GetFixedLengthTypeSize(); if (size <= 4) { return(Tuple.Create(propertyTag.Id, propertyValue.Value)); } return(AllocatePropertyOnTheHN(propertyTag, propertyValue, heapOnNodeGenerator)); } if (propertyTag.Type.IsMultiValueFixedLength() || propertyTag.Type.IsVariableLength() || propertyTag.Type.IsMultiValueVariableLength()) { if (propertyValue.Value.Length <= MaximumHeapOnNodeAllocation) { return(AllocatePropertyOnTheHN(propertyTag, propertyValue, heapOnNodeGenerator)); } } return(AllocatePropertyOnSubnode(propertyTag, propertyValue, nidAllocator, propertiesAllocatedOnSubnodes)); }
private Tuple <PropertyId, BinaryData> AllocatePropertyOnTheHN( PropertyTag propertyTag, PropertyValue propertyValue, IHeapOnNodeGenerator hnGenerator) { var propertyValueInHN = BinaryDataGenerator .New() .Append((short)propertyTag.Type.Value) .Append(propertyValue.Value) .GetData(); var hid = hnGenerator.AllocateItem(propertyValueInHN); var hnid = new HNID(hid); return(Tuple.Create(propertyTag.Id, hnidEncoder.Encode(hnid))); }
private HID Generate(int keySize, Tuple <TKey, HID>[] blockItems, IHeapOnNodeGenerator hnGenerator) { var indexBlocks = blockItems.Slice(keySize + 4, MaximumIndexOrLeafBlockSize); if (indexBlocks.Length == 1) { var encodedBlock = EncodeIndexBlock(indexBlocks[0]); return(hnGenerator.AllocateItem(encodedBlock, isUserRoot: true)); } var hidForIndexBlocks = new List <Tuple <TKey, HID> >(); foreach (var slice in indexBlocks) { var encodedIndexBlock = EncodeIndexBlock(slice); var indexBlockId = hnGenerator.AllocateItem(encodedIndexBlock); hidForIndexBlocks.Add(Tuple.Create <TKey, HID>(slice[0].Item1, indexBlockId)); } return(Generate(keySize, hidForIndexBlocks.ToArray(), hnGenerator)); }
public void Generate(int keySize, int valueSize, Tuple <TKey, TValue>[] dataRecords, IHeapOnNodeGenerator hnGenerator) { var orderedDataRecords = dataRecords.OrderBy(t => t.Item1).ToArray(); var leafBlocks = orderedDataRecords.Slice(keySize + valueSize, MaximumIndexOrLeafBlockSize); if (leafBlocks.Length == 1) { var encodedBlock = EncodeLeafBlock(leafBlocks[0]); hnGenerator.AllocateItem(encodedBlock, isUserRoot: true); return; } var hidForLeafBlocks = new List <Tuple <TKey, HID> >(); foreach (var slice in leafBlocks) { var encodedLeafBlock = EncodeLeafBlock(slice); var leafBlockId = hnGenerator.AllocateItem(encodedLeafBlock); hidForLeafBlocks.Add(Tuple.Create(slice[0].Item1, leafBlockId)); } Generate(keySize, hidForLeafBlocks.ToArray(), hnGenerator); }