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

p2 (Database Index : B+-Tree) #803

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/include/storage/index/index_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class IndexIterator {

auto operator++() -> IndexIterator &;

auto operator==(const IndexIterator &itr) const -> bool { throw std::runtime_error("unimplemented"); }
auto operator==(const IndexIterator &itr) const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }

auto operator!=(const IndexIterator &itr) const -> bool { throw std::runtime_error("unimplemented"); }
auto operator!=(const IndexIterator &itr) const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }

private:
// add your own private member variables here
Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/page/b_plus_tree_internal_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class BPlusTreeInternalPage : public BPlusTreePage {
// Array members for page data.
KeyType key_array_[INTERNAL_PAGE_SLOT_CNT];
ValueType page_id_array_[INTERNAL_PAGE_SLOT_CNT];
// (Fall 2024) Feel free to add more fields and helper functions below if needed
// (Spring 2025) Feel free to add more fields and helper functions below if needed
};

} // namespace bustub
2 changes: 1 addition & 1 deletion src/include/storage/page/b_plus_tree_leaf_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class BPlusTreeLeafPage : public BPlusTreePage {
// Array members for page data.
KeyType key_array_[LEAF_PAGE_SLOT_CNT];
ValueType rid_array_[LEAF_PAGE_SLOT_CNT];
// (Fall 2024) Feel free to add more fields and helper functions below if needed
// (Spring 2025) Feel free to add more fields and helper functions below if needed
};

} // namespace bustub
3 changes: 3 additions & 0 deletions src/include/storage/page/b_plus_tree_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BPlusTreePage {
void SetMaxSize(int max_size);
auto GetMinSize() const -> int;

/*
* TODO(P2): Remove __attribute__((__unused__)) if you intend to use the fields.
*/
private:
// Member variables, attributes that both internal and leaf page share
IndexPageType page_type_ __attribute__((__unused__));
Expand Down
27 changes: 15 additions & 12 deletions src/storage/index/b_plus_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BPLUSTREE_TYPE::BPlusTree(std::string name, page_id_t header_page_id, BufferPool
* @return Returns true if this B+ tree has no keys and values.
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::IsEmpty() const -> bool { return true; }
auto BPLUSTREE_TYPE::IsEmpty() const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/*****************************************************************************
* SEARCH
Expand All @@ -50,10 +50,9 @@ auto BPLUSTREE_TYPE::IsEmpty() const -> bool { return true; }
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::GetValue(const KeyType &key, std::vector<ValueType> *result) -> bool {
// Declaration of context instance.
UNIMPLEMENTED("TODO(P2): Add implementation.");
// Declaration of context instance. Using the Context is not necessary but advised.
Context ctx;
(void)ctx;
return false;
}

/*****************************************************************************
Expand All @@ -72,10 +71,9 @@ auto BPLUSTREE_TYPE::GetValue(const KeyType &key, std::vector<ValueType> *result
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::Insert(const KeyType &key, const ValueType &value) -> bool {
// Declaration of context instance.
UNIMPLEMENTED("TODO(P2): Add implementation.");
// Declaration of context instance. Using the Context is not necessary but advised.
Context ctx;
(void)ctx;
return false;
}

/*****************************************************************************
Expand All @@ -94,7 +92,7 @@ INDEX_TEMPLATE_ARGUMENTS
void BPLUSTREE_TYPE::Remove(const KeyType &key) {
// Declaration of context instance.
Context ctx;
(void)ctx;
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

/*****************************************************************************
Expand All @@ -103,32 +101,37 @@ void BPLUSTREE_TYPE::Remove(const KeyType &key) {
/**
* @brief Input parameter is void, find the leftmost leaf page first, then construct
* index iterator
*
* You may want to implement this while implementing Task #3.
*
* @return : index iterator
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::Begin() -> INDEXITERATOR_TYPE { return INDEXITERATOR_TYPE(); }
auto BPLUSTREE_TYPE::Begin() -> INDEXITERATOR_TYPE { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/**
* @brief Input parameter is low key, find the leaf page that contains the input key
* first, then construct index iterator
* @return : index iterator
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::Begin(const KeyType &key) -> INDEXITERATOR_TYPE { return INDEXITERATOR_TYPE(); }
auto BPLUSTREE_TYPE::Begin(const KeyType &key) -> INDEXITERATOR_TYPE { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/**
* @brief Input parameter is void, construct an index iterator representing the end
* of the key/value pair in the leaf node
* @return : index iterator
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::End() -> INDEXITERATOR_TYPE { return INDEXITERATOR_TYPE(); }
auto BPLUSTREE_TYPE::End() -> INDEXITERATOR_TYPE { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/**
* @return Page id of the root of this tree
*
* You may want to implement this while implementing Task #3.
*/
INDEX_TEMPLATE_ARGUMENTS
auto BPLUSTREE_TYPE::GetRootPageId() -> page_id_t { return 0; }
auto BPLUSTREE_TYPE::GetRootPageId() -> page_id_t { UNIMPLEMENTED("TODO(P2): Add implementation."); }

template class BPlusTree<GenericKey<4>, RID, GenericComparator<4>>;

Expand Down
6 changes: 3 additions & 3 deletions src/storage/index/index_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ INDEX_TEMPLATE_ARGUMENTS
INDEXITERATOR_TYPE::~IndexIterator() = default; // NOLINT

INDEX_TEMPLATE_ARGUMENTS
auto INDEXITERATOR_TYPE::IsEnd() -> bool { throw std::runtime_error("unimplemented"); }
auto INDEXITERATOR_TYPE::IsEnd() -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }

INDEX_TEMPLATE_ARGUMENTS
auto INDEXITERATOR_TYPE::operator*() -> std::pair<const KeyType &, const ValueType &> {
throw std::runtime_error("unimplemented");
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

INDEX_TEMPLATE_ARGUMENTS
auto INDEXITERATOR_TYPE::operator++() -> INDEXITERATOR_TYPE & { throw std::runtime_error("unimplemented"); }
auto INDEXITERATOR_TYPE::operator++() -> INDEXITERATOR_TYPE & { UNIMPLEMENTED("TODO(P2): Add implementation."); }

template class IndexIterator<GenericKey<4>, RID, GenericComparator<4>>;

Expand Down
14 changes: 10 additions & 4 deletions src/storage/page/b_plus_tree_internal_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace bustub {
* @param max_size Maximal size of the page
*/
INDEX_TEMPLATE_ARGUMENTS
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) {}
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/**
* @brief Helper method to get/set the key associated with input "index"(a.k.a
Expand All @@ -41,7 +41,9 @@ void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) {}
* @return Key at index
*/
INDEX_TEMPLATE_ARGUMENTS
auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType { return {}; }
auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType {
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

/**
* @brief Set key at the specified index.
Expand All @@ -50,7 +52,9 @@ auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType { return
* @param key The new value for key
*/
INDEX_TEMPLATE_ARGUMENTS
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {}
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

/**
* @brief Helper method to get the value associated with input "index"(a.k.a array
Expand All @@ -60,7 +64,9 @@ void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {}
* @return Value at index
*/
INDEX_TEMPLATE_ARGUMENTS
auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::ValueAt(int index) const -> ValueType { return 0; }
auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::ValueAt(int index) const -> ValueType {
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

// valuetype for internalNode should be page id_t
template class BPlusTreeInternalPage<GenericKey<4>, page_id_t, GenericComparator<4>>;
Expand Down
10 changes: 6 additions & 4 deletions src/storage/page/b_plus_tree_leaf_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,25 @@ namespace bustub {
* @param max_size Max size of the leaf node
*/
INDEX_TEMPLATE_ARGUMENTS
void B_PLUS_TREE_LEAF_PAGE_TYPE::Init(int max_size) {}
void B_PLUS_TREE_LEAF_PAGE_TYPE::Init(int max_size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/**
* Helper methods to set/get next page id
*/
INDEX_TEMPLATE_ARGUMENTS
auto B_PLUS_TREE_LEAF_PAGE_TYPE::GetNextPageId() const -> page_id_t { return INVALID_PAGE_ID; }
auto B_PLUS_TREE_LEAF_PAGE_TYPE::GetNextPageId() const -> page_id_t { UNIMPLEMENTED("TODO(P2): Add implementation."); }

INDEX_TEMPLATE_ARGUMENTS
void B_PLUS_TREE_LEAF_PAGE_TYPE::SetNextPageId(page_id_t next_page_id) {}
void B_PLUS_TREE_LEAF_PAGE_TYPE::SetNextPageId(page_id_t next_page_id) {
UNIMPLEMENTED("TODO(P2): Add implementation.");
}

/*
* Helper method to find and return the key associated with input "index" (a.k.a
* array offset)
*/
INDEX_TEMPLATE_ARGUMENTS
auto B_PLUS_TREE_LEAF_PAGE_TYPE::KeyAt(int index) const -> KeyType { return {}; }
auto B_PLUS_TREE_LEAF_PAGE_TYPE::KeyAt(int index) const -> KeyType { UNIMPLEMENTED("TODO(P2): Add implementation."); }

template class BPlusTreeLeafPage<GenericKey<4>, RID, GenericComparator<4>>;
template class BPlusTreeLeafPage<GenericKey<8>, RID, GenericComparator<8>>;
Expand Down
16 changes: 8 additions & 8 deletions src/storage/page/b_plus_tree_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ namespace bustub {
* Helper methods to get/set page type
* Page type enum class is defined in b_plus_tree_page.h
*/
auto BPlusTreePage::IsLeafPage() const -> bool { return false; }
void BPlusTreePage::SetPageType(IndexPageType page_type) {}
auto BPlusTreePage::IsLeafPage() const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }
void BPlusTreePage::SetPageType(IndexPageType page_type) { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/*
* Helper methods to get/set size (number of key/value pairs stored in that
* page)
*/
auto BPlusTreePage::GetSize() const -> int { return 0; }
void BPlusTreePage::SetSize(int size) {}
void BPlusTreePage::ChangeSizeBy(int amount) {}
auto BPlusTreePage::GetSize() const -> int { UNIMPLEMENTED("TODO(P2): Add implementation."); }
void BPlusTreePage::SetSize(int size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }
void BPlusTreePage::ChangeSizeBy(int amount) { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/*
* Helper methods to get/set max size (capacity) of the page
*/
auto BPlusTreePage::GetMaxSize() const -> int { return 0; }
void BPlusTreePage::SetMaxSize(int size) {}
auto BPlusTreePage::GetMaxSize() const -> int { UNIMPLEMENTED("TODO(P2): Add implementation."); }
void BPlusTreePage::SetMaxSize(int size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }

/*
* Helper method to get min page size
* Generally, min page size == max page size / 2
* But whether you will take ceil() or floor() depends on your implementation
*/
auto BPlusTreePage::GetMinSize() const -> int { return 0; }
auto BPlusTreePage::GetMinSize() const -> int { UNIMPLEMENTED("TODO(P2): Add implementation."); }

} // namespace bustub
Loading