public Block ReadBlock(long offset)
        {
            stream.Position = offset;
            int count = reader.ReadInt16();

            byte[] blockData = reader.ReadBytes(count * (keySize + valueSize));
            Record[] records = new Record[count];

            for (int i = 0, recordOffset = 0; i < count; i++, recordOffset += keySize + valueSize)
            {
                ByteArrayRef key = new ByteArrayRef(blockData, recordOffset, keySize);
                ByteArrayRef value = new ByteArrayRef(blockData, recordOffset + keySize, valueSize);

                Record record = new Record(key, value);
                records[i] = record;
            }

            return new Block(records);
        }
 private int CompareKeys(ByteArrayRef keyA, ByteArrayRef keyB, int firstByte)
 {
     Contract.Assume(keyA.Length == keyB.Length, "Both keys should have the same size.");
     for (int i = firstByte; i < keyA.Length; i++)
     {
         int diff = keyA.GetByteAt(i) - keyB.GetByteAt(i);
         if (diff != 0)
         {
             return diff;
         }
     }
     return 0;
 }