Skip to content

Commit 4539192

Browse files
ChrisLaspiasChris Laspias
and
Chris Laspias
authored
p2 (Database Index : B+-Tree) (#803)
preparing p2 Co-authored-by: Chris Laspias <claspias@andrew.cmu.edu>
1 parent f9dfd14 commit 4539192

9 files changed

+49
-35
lines changed

src/include/storage/index/index_iterator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class IndexIterator {
3535

3636
auto operator++() -> IndexIterator &;
3737

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

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

4242
private:
4343
// add your own private member variables here

src/include/storage/page/b_plus_tree_internal_page.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class BPlusTreeInternalPage : public BPlusTreePage {
9494
// Array members for page data.
9595
KeyType key_array_[INTERNAL_PAGE_SLOT_CNT];
9696
ValueType page_id_array_[INTERNAL_PAGE_SLOT_CNT];
97-
// (Fall 2024) Feel free to add more fields and helper functions below if needed
97+
// (Spring 2025) Feel free to add more fields and helper functions below if needed
9898
};
9999

100100
} // namespace bustub

src/include/storage/page/b_plus_tree_leaf_page.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class BPlusTreeLeafPage : public BPlusTreePage {
9292
// Array members for page data.
9393
KeyType key_array_[LEAF_PAGE_SLOT_CNT];
9494
ValueType rid_array_[LEAF_PAGE_SLOT_CNT];
95-
// (Fall 2024) Feel free to add more fields and helper functions below if needed
95+
// (Spring 2025) Feel free to add more fields and helper functions below if needed
9696
};
9797

9898
} // namespace bustub

src/include/storage/page/b_plus_tree_page.h

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class BPlusTreePage {
5858
void SetMaxSize(int max_size);
5959
auto GetMinSize() const -> int;
6060

61+
/*
62+
* TODO(P2): Remove __attribute__((__unused__)) if you intend to use the fields.
63+
*/
6164
private:
6265
// Member variables, attributes that both internal and leaf page share
6366
IndexPageType page_type_ __attribute__((__unused__));

src/storage/index/b_plus_tree.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BPLUSTREE_TYPE::BPlusTree(std::string name, page_id_t header_page_id, BufferPool
3434
* @return Returns true if this B+ tree has no keys and values.
3535
*/
3636
INDEX_TEMPLATE_ARGUMENTS
37-
auto BPLUSTREE_TYPE::IsEmpty() const -> bool { return true; }
37+
auto BPLUSTREE_TYPE::IsEmpty() const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }
3838

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

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

8179
/*****************************************************************************
@@ -94,7 +92,7 @@ INDEX_TEMPLATE_ARGUMENTS
9492
void BPLUSTREE_TYPE::Remove(const KeyType &key) {
9593
// Declaration of context instance.
9694
Context ctx;
97-
(void)ctx;
95+
UNIMPLEMENTED("TODO(P2): Add implementation.");
9896
}
9997

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

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

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

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

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

src/storage/index/index_iterator.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ INDEX_TEMPLATE_ARGUMENTS
3030
INDEXITERATOR_TYPE::~IndexIterator() = default; // NOLINT
3131

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

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

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

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

src/storage/page/b_plus_tree_internal_page.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace bustub {
3131
* @param max_size Maximal size of the page
3232
*/
3333
INDEX_TEMPLATE_ARGUMENTS
34-
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) {}
34+
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }
3535

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

4648
/**
4749
* @brief Set key at the specified index.
@@ -50,7 +52,9 @@ auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType { return
5052
* @param key The new value for key
5153
*/
5254
INDEX_TEMPLATE_ARGUMENTS
53-
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {}
55+
void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {
56+
UNIMPLEMENTED("TODO(P2): Add implementation.");
57+
}
5458

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

6571
// valuetype for internalNode should be page id_t
6672
template class BPlusTreeInternalPage<GenericKey<4>, page_id_t, GenericComparator<4>>;

src/storage/page/b_plus_tree_leaf_page.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@ namespace bustub {
3232
* @param max_size Max size of the leaf node
3333
*/
3434
INDEX_TEMPLATE_ARGUMENTS
35-
void B_PLUS_TREE_LEAF_PAGE_TYPE::Init(int max_size) {}
35+
void B_PLUS_TREE_LEAF_PAGE_TYPE::Init(int max_size) { UNIMPLEMENTED("TODO(P2): Add implementation."); }
3636

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

4343
INDEX_TEMPLATE_ARGUMENTS
44-
void B_PLUS_TREE_LEAF_PAGE_TYPE::SetNextPageId(page_id_t next_page_id) {}
44+
void B_PLUS_TREE_LEAF_PAGE_TYPE::SetNextPageId(page_id_t next_page_id) {
45+
UNIMPLEMENTED("TODO(P2): Add implementation.");
46+
}
4547

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

5355
template class BPlusTreeLeafPage<GenericKey<4>, RID, GenericComparator<4>>;
5456
template class BPlusTreeLeafPage<GenericKey<8>, RID, GenericComparator<8>>;

src/storage/page/b_plus_tree_page.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ namespace bustub {
1818
* Helper methods to get/set page type
1919
* Page type enum class is defined in b_plus_tree_page.h
2020
*/
21-
auto BPlusTreePage::IsLeafPage() const -> bool { return false; }
22-
void BPlusTreePage::SetPageType(IndexPageType page_type) {}
21+
auto BPlusTreePage::IsLeafPage() const -> bool { UNIMPLEMENTED("TODO(P2): Add implementation."); }
22+
void BPlusTreePage::SetPageType(IndexPageType page_type) { UNIMPLEMENTED("TODO(P2): Add implementation."); }
2323

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

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

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

4545
} // namespace bustub

0 commit comments

Comments
 (0)