예제 #1
0
 public LeafReader(SBBF03 sb, BTreeLeaf leaf)
 {
     File    = sb;
     Leaf    = leaf;
     Offset  = 0;
     Visited = new List <int>(new[] { leaf.Index });
 }
예제 #2
0
파일: BTreeDb4.cs 프로젝트: SharpStar/Star
        public override void Read(SBBF03 sbb, int blockIndex)
        {
            base.Read(sbb, blockIndex);

            if (!(sbb is BTreeDb4))
            {
                throw new Exception("Expected BTreeDb4!");
            }

            Keys   = new List <Key>();
            Values = new List <int>();

            BTreeDb4 db = (BTreeDb4)sbb;

            var unpacked = DataConverter.Unpack("^Cii", db.Reader.ReadBytes(9), 0);

            Level     = (byte)(char)unpacked[0];
            NumKeys   = (int)unpacked[1];
            LeftBlock = (int)unpacked[2];

            Values.Add(LeftBlock);

            for (int i = 0; i < NumKeys; i++)
            {
                Key key = sbb.Reader.ReadBytes(db.KeySize);

                var unpacked2 = DataConverter.Unpack("^i", db.Reader.ReadBytes(4), 0);

                int block = (int)unpacked2[0];

                Keys.Add(key);
                Values.Add(block);
            }
        }
예제 #3
0
파일: Block.cs 프로젝트: SharpStar/Star
        public static byte[] GetBlockSignature(SBBF03 sbb)
        {
            byte[] signature = new byte[2];

            sbb.Reader.Read(signature, 0, signature.Length);

            sbb.Reader.BaseStream.Seek(-signature.Length, SeekOrigin.Current);

            return(signature);
        }
예제 #4
0
파일: BTreeDb4.cs 프로젝트: SharpStar/Star
        public override void Read(SBBF03 sb, int blockIndex)
        {
            byte[] data = FreeBlock.RawData.Take(FreeBlock.RawData.Length - 4).ToArray();

            var unpacked = DataConverter.Unpack("^i", data.Skip(data.Length - 4).ToArray(), 0);

            int value = (int)unpacked[0];

            NextBlock = value != -1 ? (int?)value : null;
        }
예제 #5
0
파일: Block.cs 프로젝트: SharpStar/Star
        public override void Read(SBBF03 sb, int blockIndex)
        {
            base.Read(sb, blockIndex);

            RawData = sb.Reader.ReadBytes(sb.BlockSize - 2);

            var unpacked = DataConverter.Unpack("^i", RawData.Take(4).ToArray(), 0);

            Value         = (int)unpacked[0];
            NextFreeBlock = Value != -1 ? Value : 0;
        }
예제 #6
0
파일: BTreeDb4.cs 프로젝트: SharpStar/Star
        public override void Read(SBBF03 sb, int blockIndex)
        {
            base.Read(sb, blockIndex);

            Data = sb.Reader.ReadBytes(sb.BlockSize - 6);

            var unpacked = DataConverter.Unpack("^i", sb.Reader.ReadBytes(4), 0);

            int value = (int)unpacked[0];

            NextBlock = value != -1 ? value : 0;
        }
예제 #7
0
파일: Block.cs 프로젝트: SharpStar/Star
        public virtual void Read(SBBF03 sbb, int blockIndex)
        {
            byte[] signature = GetBlockSignature(sbb);

            sbb.Reader.BaseStream.Seek(signature.Length, SeekOrigin.Current);

            if (signature[0] == '\x00' && signature[1] == '\x00')
            {
                throw new Exception();
            }

            if (!Signature.SequenceEqual(signature))
            {
                throw new Exception("Signatures don't match!");
            }

            Index = blockIndex;
        }