Example #1
0
        public byte[] GetLeafValue(BTreeLeaf leaf, Key key)
        {
            var reader = new LeafReader(this, leaf);

            var unpacked = DataConverter.Unpack("^i", reader.Read(4), 0);

            var numKeys = (int)unpacked[0];

            int discarded;

            for (int i = 0; i < numKeys; i++)
            {
                byte[] curKey = reader.Read(KeySize);

                int length = (int)VLQ.ReadVLQ(reader, out discarded);

                byte[] value = reader.Read(length);

                if (curKey.SequenceEqual(key.TheKey))
                {
                    return(value);
                }
            }

            return(null);
        }
Example #2
0
        public static ulong ReadVLQ(LeafReader leafReader, out int length)
        {
            ulong value = 0L;

            length = 0;

            while (true)
            {
                byte tmp = leafReader.Read(1)[0];

                value = (value << 7) | (ulong)(tmp & 0x7f);

                length++;

                if ((tmp & 0x80) == 0)
                {
                    break;
                }
            }

            return(value);
        }