leveldb-handbook icon indicating copy to clipboard operation
leveldb-handbook copied to clipboard

勘误:sstable 中“data block 结构”例子错误

Open Jed-Z opened this issue 3 years ago • 0 comments

sstable 一章中介绍“data block 结构”的例子中,第二个 restart point 的值应为 17 而不是 16。错误的图片如下:

验证代码:

#include <cctype>
#include <iostream>
#include "leveldb/options.h"
#include "table/block_builder.h"

int main() {
  leveldb::Options options;
  options.block_restart_interval = 2;
  leveldb::BlockBuilder builder(&options);
  builder.Add("deck", "v1");
  builder.Add("dock", "v2");
  builder.Add("duck", "v3");

  std::cout << "-------------" << std::endl;
  leveldb::Slice result = builder.Finish();
  for (char c : result.ToString()) {
    if (isalnum(c))
      std::cout << c << ' ';
    else
      std::cout << "\\0x" << int(c) << ' ';
  }
  std::cout << std::endl;
  std::cout << "-------------" << std::endl;

  return 0;
}

输出结果:

\0x0 \0x4 \0x2 d e c k v 1 \0x1 \0x3 \0x2 o c k v 2 \0x0 \0x4 \0x2 d u c k v 3 \0x0 \0x0 \0x0 \0x0 \0x17 \0x0 \0x0 \0x0 \0x2 \0x0 \0x0 \0x0

Jed-Z avatar Apr 22 '21 02:04 Jed-Z