Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jed-Z opened this issue Apr 22, 2021 · 0 comments
Open

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

Jed-Z opened this issue Apr 22, 2021 · 0 comments

Comments

@Jed-Z
Copy link

Jed-Z commented Apr 22, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant