Ejemplo n.º 1
0
        public void Heap_Gives_Correct_User_Root()
        {
            var block = Block.Create(_heapData);
            var heap = new Heap(block);

            Assert.AreEqual(0x20, heap.UserRoot);
        }
Ejemplo n.º 2
0
        public void Heap_Gives_Correct_Freed_Count()
        {
            var block = Block.Create(_heapData);
            var heap = new Heap(block);

            Assert.AreEqual(0, heap.FreedCount);
        }
Ejemplo n.º 3
0
        public void Heap_Gives_Correct_Client_Signature()
        {
            var block = Block.Create(_heapData);
            var heap = new Heap(block);

            Assert.AreEqual(0xbc, heap.ClientSignature);
        }
Ejemplo n.º 4
0
 private void Initialize()
 {
     var block = _node.GetDataBlock();
     _heap = new Heap(block);
     _bTree = new BTree<Property, ushort>(
         _heap,
         b => BitConverter.ToUInt16(b.Array, b.Offset),
         CreateProperty);
 }
Ejemplo n.º 5
0
        private void Initialize()
        {
            var block = _reader.FindBlock(_node.DataBid);
            _heap = new Heap(block);
            var tableHeader = _heap[_heap.UserRoot];
            _numColumns = tableHeader[1];
            _columnOffsets = new TcColumnOffsets(
                BitConverter.ToInt16(tableHeader.Array, tableHeader.Offset + 2),
                BitConverter.ToInt16(tableHeader.Array, tableHeader.Offset + 4),
                BitConverter.ToInt16(tableHeader.Array, tableHeader.Offset + 6),
                BitConverter.ToInt16(tableHeader.Array, tableHeader.Offset + 8));

            var rowIndexHid = BitConverter.ToUInt32(tableHeader.Array, tableHeader.Offset + 10);
            _rowIndex = new BTree<uint, uint>(
                _heap,
                rowIndexHid,
                s => BitConverter.ToUInt32(s.Array, s.Offset),
                s => BitConverter.ToUInt32(s.Array, s.Offset + 4));

            var rowDataHnid = BitConverter.ToUInt32(tableHeader.Array, tableHeader.Offset + 14);
            if ((rowDataHnid & 0x1f) == 0)
            {
                _rowData = _heap[rowDataHnid];
            }
            else
            {
                var subnode = _node.FindSubnode(rowDataHnid);
                var dataBlock = _reader.FindBlock(subnode.DataBid);
                _rowData = dataBlock.Data;
            }

            _columnDefs = new TcColumnDef[_numColumns];
            for (int i = 0; i < _numColumns; i++)
            {
                var offset = tableHeader.Offset + 22 + (i * 8);
                var tagType = BitConverter.ToUInt16(tableHeader.Array, offset);
                var tagKey = BitConverter.ToUInt16(tableHeader.Array, offset + 2);
                var dataOffset = BitConverter.ToUInt16(tableHeader.Array, offset + 4);
                var dataLength = tableHeader.Array[offset + 6];
                var cebIndex = tableHeader.Array[offset + 7];
                var def = new TcColumnDef
                {
                    Tag = new ColumnTag
                    {
                        Type = (PropertyType)tagType,
                        Key = (PropertyKey)tagKey
                    },
                    Offset = dataOffset,
                    Size = dataLength,
                    CebIndex = cebIndex
                };
                _columnDefs[i] = def;
            }
        }
Ejemplo n.º 6
0
        public void Find_Nonexistent_Element_Returns_Null()
        {
            var block = Block.Create(_heapData);
            var heap = new Heap(block);
            var btree = new BTree<byte[], ushort>(
                heap,
                b => BitConverter.ToUInt16(b.Array, b.Offset),
                b => b.ToArray());

            var result = btree.Find(1234);
            Assert.IsNull(result);
        }
Ejemplo n.º 7
0
 internal TcRow(
     int rowIndex,
     TcColumnOffsets offsets,
     TcColumnDef[] columnDefs,
     Segment<byte> rowData,
     Heap heap,
     Node node,
     IPstReader reader)
 {
     _rowIndex = rowIndex;
     _offsets = offsets;
     _columnDefs = columnDefs;
     _rowData = rowData;
     _heap = heap;
     _node = node;
     _reader = reader;
 }
Ejemplo n.º 8
0
        public void Finds_Element()
        {
            var expectedBytes = new byte[]
            {
                0xe5, 0x35, 0x02, 0x01,
                0x60, 0x01, 0x00, 0x00
            };

            var block = Block.Create(_heapData);
            var heap = new Heap(block);
            var btree = new BTree<byte[], ushort>(
                heap,
                b => BitConverter.ToUInt16(b.Array, b.Offset),
                b => b.ToArray());

            var result = btree.Find(0x35e5);
            Assert.IsNotNull(result);
            CollectionAssert.AreEqual(expectedBytes, result);
        }
Ejemplo n.º 9
0
        public void Gets_All_Elements()
        {
            var block = Block.Create(_heapData);
            var heap = new Heap(block);
            var btree = new BTree<byte[], ushort>(
                heap,
                b => BitConverter.ToUInt16(b.Array, b.Offset),
                b => b.ToArray());

            var items = btree.GetAll();

            Assert.AreEqual(17, items.Count());
            var item1 = items.ElementAt(0);
            Assert.AreEqual(0xe34, item1.Key);
            CollectionAssert.AreEqual(
                new byte[] { 0x34, 0x0e, 0x02, 0x01, 0xa0, 0x00, 0x00, 0x00 },
                item1.Value);
            var item6 = items.ElementAt(5);
            Assert.AreEqual(0x35df, item6.Key);
            CollectionAssert.AreEqual(
                new byte[] { 0xdf, 0x35, 0x03, 0x00, 0xff, 0x00, 0x00, 0x00 },
                item6.Value);
        }
Ejemplo n.º 10
0
 public void Validates_Header()
 {
     var block = Block.Create(_heapData);
     var heap = new Heap(block);
     new BTree<ulong, ushort>(heap, null, null);
 }
Ejemplo n.º 11
0
        public void Heap_Retrieves_Item()
        {
            var expectedBytes = new byte[]
            {
                0xb5, 0x02, 0x06, 0x00,
                0x40, 0x00, 0x00, 0x00
            };
            var block = Block.Create(_heapData);
            var heap = new Heap(block);

            var item = heap[0x20];

            CollectionAssert.AreEqual(expectedBytes, item.ToArray());
        }