Пример #1
0
        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));
        }
Пример #2
0
        public DataTreeWithPossibleSubnodes Generate(Tuple <PropertyTag, PropertyValue>[] properties)
        {
            var dataRecords = new List <Tuple <PropertyId, BinaryData> >();

            var propertiesAllocatedOnSubnodes = new List <Tuple <NID, BID> >();

            var nidAllocator = new InternalNIDAllocator();

            var hnGenerator = heapOnNodeGeneratorFactory.Create();

            foreach (var property in properties)
            {
                dataRecords.Add(
                    EncodeDataRecord(
                        property.Item1,
                        property.Item2,
                        hnGenerator,
                        nidAllocator,
                        propertiesAllocatedOnSubnodes));
            }

            bthGenerator.Generate(2, 6, dataRecords.ToArray(), hnGenerator);

            var dataTreeRootBlockId = hnGenerator.Commit(Constants.bTypePC);

            return(new DataTreeWithPossibleSubnodes(dataTreeRootBlockId, propertiesAllocatedOnSubnodes.ToArray()));
        }
Пример #3
0
        private Tuple <PropertyId, BinaryData> AllocatePropertyOnSubnode(
            PropertyTag propertyTag,
            PropertyValue propertyValue,
            InternalNIDAllocator nidAllocator,
            List <Tuple <NID, BID> > propertiesAllocatedOnSubnodes)
        {
            var dataTreeRootBlockId = dataTreeAllocator.Allocate(new[] { propertyValue.Value });

            var nid = nidAllocator.New();

            var hnid = new HNID(nid);

            propertiesAllocatedOnSubnodes.Add(Tuple.Create(nid, dataTreeRootBlockId));

            return(Tuple.Create(propertyTag.Id, hnidEncoder.Encode(hnid)));
        }