1#ifndef SMOLLERGRAPH_NAME_INDEX_H_
2#define SMOLLERGRAPH_NAME_INDEX_H_
11#include "absl/status/status.h"
26 absl::Status
Open(
const std::string&
path);
35 std::optional<uint32_t>
Find(std::string_view name)
const;
37 void Insert(std::string_view name, uint32_t
id);
49 static constexpr size_t kHeaderSize = 16;
50 static constexpr uint32_t kEntries =
51 (
kPageSize - kHeaderSize) /
sizeof(Entry);
62 Entry entries[kEntries];
73 static std::string_view NameOf(
const Entry& entry);
76 static uint32_t Position(
const Node& node, std::string_view name);
78 static PageId Child(
const Node& node, std::string_view name);
82 std::optional<Entry> InsertUnder(
PageId id,
const Entry& entry);
85 std::optional<Entry> Add(
PageId id, Node& node, uint32_t at,
90 Node Load(
PageId id)
const;
91 void Store(
PageId id,
const Node& node);
94 static constexpr size_t kPoolPages = 4096;
97 mutable BufferPool pool_{pager_, kPoolPages};
void Flush()
Writes the changed pages back to the file, and keeps them.
An index from names to ids, kept in a file of pages as a B+ tree: leaves of names in order,...
absl::Status OpenTemporary()
Opens an index in a file with no name, which is deleted once it's closed.
absl::Status Open(const std::string &path)
Opens the index in the file at path, creating it when it isn't there.
std::vector< std::string > NamesStartingWith(std::string_view prefix, size_t limit) const
Returns up to limit names that start with prefix, in order.
uint64_t page_reads() const
void Insert(std::string_view name, uint32_t id)
Keeps id for name, which the index doesn't have yet.
uint64_t page_writes() const
static constexpr size_t kMaxName
The longest name it keeps, as long as a node's.
void Flush()
Writes the changed pages to the file.
std::optional< uint32_t > Find(std::string_view name) const
Returns the id kept for name, if there's one.
constexpr size_t kPageSize
What the database reads and writes at a time: 4 KiB, the size of a block on most file systems and dis...