Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new class
 /// </summary>
 /// <param name="level"></param>
 /// <param name="blockSize"></param>
 /// <param name="stream"></param>
 /// <param name="lookupKey"></param>
 public GenericEncodedNodeScanner(PairEncodingBase <TKey, TValue> encoding, byte level, int blockSize, BinaryStreamPointerBase stream, Func <TKey, byte, uint> lookupKey)
     : base(level, blockSize, stream, lookupKey)
 {
     m_encoding   = encoding;
     m_nextOffset = 0;
     m_prevKey    = new TKey();
     m_prevValue  = new TValue();
     m_prevKey.Clear();
     m_prevValue.Clear();
     m_tmpKey   = new TKey();
     m_tmpValue = new TValue();
 }
Ejemplo n.º 2
0
        public GenericEncodedNode(PairEncodingBase <TKey, TValue> encoding, byte level)
            : base(level)
        {
            if (level != 0)
            {
                throw new ArgumentException("Level for this type is only supported on the leaf level.");
            }
            m_currentKey   = new TKey();
            m_currentValue = new TValue();
            m_prevKey      = new TKey();
            m_prevValue    = new TValue();
            m_nullKey      = new TKey();
            m_nullValue    = new TValue();
            m_nullKey.Clear();
            m_nullValue.Clear();

            NodeIndexChanged += OnNodeIndexChanged;
            ClearNodeCache();

            m_encoding = encoding;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new class
 /// </summary>
 /// <param name="level">the level of this node.</param>
 public FixedSizeNode(byte level)
     : base(level)
 {
     m_encoding = Library.Encodings.GetEncodingMethod <TKey, TValue>(EncodingDefinition.FixedSizeCombinedEncoding);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new <see cref="StreamEncodingGeneric{TKey,TValue}"/> based on the supplied <see cref="encodingMethod"/>
 /// </summary>
 /// <param name="encodingMethod">the encoding method to use for the streaming</param>
 public StreamEncodingGeneric(EncodingDefinition encodingMethod)
 {
     m_encoding  = Library.Encodings.GetEncodingMethod <TKey, TValue>(encodingMethod);
     m_prevKey   = new TKey();
     m_prevValue = new TValue();
 }
Ejemplo n.º 5
0
        public static void Create(EncodingDefinition encodingMethod, BinaryStreamPointerBase stream, int blockSize, byte level, uint startingNodeIndex, Func <uint> getNextNewNodeIndex, SparseIndexWriter <TKey> sparseIndex, TreeStream <TKey, TValue> treeStream)
        {
            NodeHeader <TKey> header = new NodeHeader <TKey>(level, blockSize);
            PairEncodingBase <TKey, TValue> encoding = Library.Encodings.GetEncodingMethod <TKey, TValue>(encodingMethod);

            SparseIndexWriter <TKey> sparseIndex1 = sparseIndex;
            Func <uint> getNextNewNodeIndex1      = getNextNewNodeIndex;
            int         maximumStorageSize        = encoding.MaxCompressionSize;

            byte[] buffer1 = new byte[maximumStorageSize];
            if ((header.BlockSize - header.HeaderSize) / maximumStorageSize < 4)
            {
                throw new Exception("Tree must have at least 4 records per node. Increase the block size or decrease the size of the records.");
            }

            //InsideNodeBoundary = m_BoundsFalse;
            header.NodeIndex             = startingNodeIndex;
            header.RecordCount           = 0;
            header.ValidBytes            = (ushort)header.HeaderSize;
            header.LeftSiblingNodeIndex  = uint.MaxValue;
            header.RightSiblingNodeIndex = uint.MaxValue;
            header.LowerKey.SetMin();
            header.UpperKey.SetMax();

            byte *writePointer = stream.GetWritePointer(blockSize * header.NodeIndex, blockSize);

            fixed(byte *buffer = buffer1)
            {
                TKey   key1   = new TKey();
                TKey   key2   = new TKey();
                TValue value1 = new TValue();
                TValue value2 = new TValue();

                key1.Clear();
                key2.Clear();
                value1.Clear();
                value2.Clear();

Read1:
                //Read part 1.
                if (treeStream.Read(key1, value1))
                {
                    if (header.RemainingBytes < maximumStorageSize)
                    {
                        if (header.RemainingBytes < encoding.Encode(buffer, key2, value2, key1, value1))
                        {
                            NewNodeThenInsert(header, sparseIndex1, getNextNewNodeIndex1(), writePointer, key1);
                            key2.Clear();
                            value2.Clear();
                            writePointer = stream.GetWritePointer(blockSize * header.NodeIndex, blockSize);
                        }
                    }

                    byte *stream1 = writePointer + header.ValidBytes;
                    header.ValidBytes += (ushort)encoding.Encode(stream1, key2, value2, key1, value1);
                    header.RecordCount++;

                    //Read part 2.
                    if (treeStream.Read(key2, value2))
                    {
                        if (header.RemainingBytes < maximumStorageSize)
                        {
                            if (header.RemainingBytes < encoding.Encode(buffer, key1, value1, key2, value2))
                            {
                                NewNodeThenInsert(header, sparseIndex1, getNextNewNodeIndex1(), writePointer, key2);
                                key1.Clear();
                                value1.Clear();
                                writePointer = stream.GetWritePointer(blockSize * header.NodeIndex, blockSize);
                            }
                        }
                        byte *stream2 = writePointer + header.ValidBytes;
                        header.ValidBytes += (ushort)encoding.Encode(stream2, key1, value1, key2, value2);
                        header.RecordCount++;

                        goto Read1;
                    }
                }
            }

            header.Save(writePointer);
        }