|
4 | 4 | //
|
5 | 5 | // disk_extendible_hash_table.cpp
|
6 | 6 | //
|
7 |
| -// Identification: src/container/hash/extendible_hash_table.cpp |
| 7 | +// Identification: src/container/disk/hash/disk_extendible_hash_table.cpp |
8 | 8 | //
|
9 |
| -// Copyright (c) 2015-2021, Carnegie Mellon University Database Group |
| 9 | +// Copyright (c) 2015-2023, Carnegie Mellon University Database Group |
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
|
15 | 15 | #include <utility>
|
16 | 16 | #include <vector>
|
17 | 17 |
|
| 18 | +#include "common/config.h" |
18 | 19 | #include "common/exception.h"
|
19 | 20 | #include "common/logger.h"
|
| 21 | +#include "common/macros.h" |
20 | 22 | #include "common/rid.h"
|
| 23 | +#include "common/util/hash_util.h" |
21 | 24 | #include "container/disk/hash/disk_extendible_hash_table.h"
|
| 25 | +#include "storage/index/hash_comparator.h" |
| 26 | +#include "storage/page/extendible_htable_bucket_page.h" |
| 27 | +#include "storage/page/extendible_htable_directory_page.h" |
| 28 | +#include "storage/page/extendible_htable_header_page.h" |
| 29 | +#include "storage/page/page_guard.h" |
22 | 30 |
|
23 | 31 | namespace bustub {
|
24 | 32 |
|
25 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
26 |
| -HASH_TABLE_TYPE::DiskExtendibleHashTable(const std::string &name, BufferPoolManager *buffer_pool_manager, |
27 |
| - const KeyComparator &comparator, HashFunction<KeyType> hash_fn) |
28 |
| - : buffer_pool_manager_(buffer_pool_manager), comparator_(comparator), hash_fn_(std::move(hash_fn)) { |
29 |
| - // implement me! |
30 |
| -} |
31 |
| - |
32 |
| -/***************************************************************************** |
33 |
| - * HELPERS |
34 |
| - *****************************************************************************/ |
35 |
| -/** |
36 |
| - * Hash - simple helper to downcast MurmurHash's 64-bit hash to 32-bit |
37 |
| - * for extendible hashing. |
38 |
| - * |
39 |
| - * @param key the key to hash |
40 |
| - * @return the downcasted 32-bit hash |
41 |
| - */ |
42 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
43 |
| -auto HASH_TABLE_TYPE::Hash(KeyType key) -> uint32_t { |
44 |
| - return static_cast<uint32_t>(hash_fn_.GetHash(key)); |
45 |
| -} |
46 |
| - |
47 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
48 |
| -inline auto HASH_TABLE_TYPE::KeyToDirectoryIndex(KeyType key, HashTableDirectoryPage *dir_page) -> uint32_t { |
49 |
| - return 0; |
50 |
| -} |
51 |
| - |
52 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
53 |
| -inline auto HASH_TABLE_TYPE::KeyToPageId(KeyType key, HashTableDirectoryPage *dir_page) -> page_id_t { |
54 |
| - return 0; |
55 |
| -} |
56 |
| - |
57 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
58 |
| -auto HASH_TABLE_TYPE::FetchDirectoryPage() -> HashTableDirectoryPage * { |
59 |
| - return nullptr; |
60 |
| -} |
61 |
| - |
62 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
63 |
| -auto HASH_TABLE_TYPE::FetchBucketPage(page_id_t bucket_page_id) -> HASH_TABLE_BUCKET_TYPE * { |
64 |
| - return nullptr; |
| 33 | +template <typename K, typename V, typename KC> |
| 34 | +DiskExtendibleHashTable<K, V, KC>::DiskExtendibleHashTable(const std::string &name, BufferPoolManager *bpm, |
| 35 | + const KC &cmp, const HashFunction<K> &hash_fn, |
| 36 | + uint32_t header_max_depth, uint32_t directory_max_depth, |
| 37 | + uint32_t bucket_max_size) |
| 38 | + : bpm_(bpm), |
| 39 | + cmp_(cmp), |
| 40 | + hash_fn_(std::move(hash_fn)), |
| 41 | + header_max_depth_(header_max_depth), |
| 42 | + directory_max_depth_(directory_max_depth), |
| 43 | + bucket_max_size_(bucket_max_size) { |
| 44 | + throw NotImplementedException("DiskExtendibleHashTable is not implemented"); |
65 | 45 | }
|
66 | 46 |
|
67 | 47 | /*****************************************************************************
|
68 | 48 | * SEARCH
|
69 | 49 | *****************************************************************************/
|
70 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
71 |
| -auto HASH_TABLE_TYPE::GetValue(Transaction *transaction, const KeyType &key, std::vector<ValueType> *result) -> bool { |
| 50 | +template <typename K, typename V, typename KC> |
| 51 | +auto DiskExtendibleHashTable<K, V, KC>::GetValue(const K &key, std::vector<V> *result, Transaction *transaction) const |
| 52 | + -> bool { |
72 | 53 | return false;
|
73 | 54 | }
|
74 | 55 |
|
75 | 56 | /*****************************************************************************
|
76 | 57 | * INSERTION
|
77 | 58 | *****************************************************************************/
|
78 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
79 |
| -auto HASH_TABLE_TYPE::Insert(Transaction *transaction, const KeyType &key, const ValueType &value) -> bool { |
| 59 | + |
| 60 | +template <typename K, typename V, typename KC> |
| 61 | +auto DiskExtendibleHashTable<K, V, KC>::Insert(const K &key, const V &value, Transaction *transaction) -> bool { |
80 | 62 | return false;
|
81 | 63 | }
|
82 | 64 |
|
83 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
84 |
| -auto HASH_TABLE_TYPE::SplitInsert(Transaction *transaction, const KeyType &key, const ValueType &value) -> bool { |
| 65 | +template <typename K, typename V, typename KC> |
| 66 | +auto DiskExtendibleHashTable<K, V, KC>::InsertToNewDirectory(ExtendibleHTableHeaderPage *header, uint32_t directory_idx, |
| 67 | + uint32_t hash, const K &key, const V &value) -> bool { |
85 | 68 | return false;
|
86 | 69 | }
|
87 | 70 |
|
88 |
| -/***************************************************************************** |
89 |
| - * REMOVE |
90 |
| - *****************************************************************************/ |
91 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
92 |
| -auto HASH_TABLE_TYPE::Remove(Transaction *transaction, const KeyType &key, const ValueType &value) -> bool { |
| 71 | +template <typename K, typename V, typename KC> |
| 72 | +auto DiskExtendibleHashTable<K, V, KC>::InsertToNewBucket(ExtendibleHTableDirectoryPage *directory, uint32_t bucket_idx, |
| 73 | + const K &key, const V &value) -> bool { |
93 | 74 | return false;
|
94 | 75 | }
|
95 | 76 |
|
96 |
| -/***************************************************************************** |
97 |
| - * MERGE |
98 |
| - *****************************************************************************/ |
99 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
100 |
| -void HASH_TABLE_TYPE::Merge(Transaction *transaction, const KeyType &key, const ValueType &value) {} |
101 |
| - |
102 |
| -/***************************************************************************** |
103 |
| - * GETGLOBALDEPTH - DO NOT TOUCH |
104 |
| - *****************************************************************************/ |
105 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
106 |
| -auto HASH_TABLE_TYPE::GetGlobalDepth() -> uint32_t { |
107 |
| - table_latch_.RLock(); |
108 |
| - HashTableDirectoryPage *dir_page = FetchDirectoryPage(); |
109 |
| - uint32_t global_depth = dir_page->GetGlobalDepth(); |
110 |
| - assert(buffer_pool_manager_->UnpinPage(directory_page_id_, false)); |
111 |
| - table_latch_.RUnlock(); |
112 |
| - return global_depth; |
| 77 | +template <typename K, typename V, typename KC> |
| 78 | +void DiskExtendibleHashTable<K, V, KC>::UpdateDirectoryMapping(ExtendibleHTableDirectoryPage *directory, |
| 79 | + uint32_t new_bucket_idx, page_id_t new_bucket_page_id, |
| 80 | + uint32_t new_local_depth, uint32_t local_depth_mask) { |
| 81 | + throw NotImplementedException("DiskExtendibleHashTable is not implemented"); |
113 | 82 | }
|
114 | 83 |
|
115 | 84 | /*****************************************************************************
|
116 |
| - * VERIFY INTEGRITY - DO NOT TOUCH |
| 85 | + * REMOVE |
117 | 86 | *****************************************************************************/
|
118 |
| -template <typename KeyType, typename ValueType, typename KeyComparator> |
119 |
| -void HASH_TABLE_TYPE::VerifyIntegrity() { |
120 |
| - table_latch_.RLock(); |
121 |
| - HashTableDirectoryPage *dir_page = FetchDirectoryPage(); |
122 |
| - dir_page->VerifyIntegrity(); |
123 |
| - assert(buffer_pool_manager_->UnpinPage(directory_page_id_, false)); |
124 |
| - table_latch_.RUnlock(); |
| 87 | +template <typename K, typename V, typename KC> |
| 88 | +auto DiskExtendibleHashTable<K, V, KC>::Remove(const K &key, Transaction *transaction) -> bool { |
| 89 | + return false; |
125 | 90 | }
|
126 | 91 |
|
127 |
| -/***************************************************************************** |
128 |
| - * TEMPLATE DEFINITIONS - DO NOT TOUCH |
129 |
| - *****************************************************************************/ |
130 | 92 | template class DiskExtendibleHashTable<int, int, IntComparator>;
|
131 |
| - |
132 | 93 | template class DiskExtendibleHashTable<GenericKey<4>, RID, GenericComparator<4>>;
|
133 | 94 | template class DiskExtendibleHashTable<GenericKey<8>, RID, GenericComparator<8>>;
|
134 | 95 | template class DiskExtendibleHashTable<GenericKey<16>, RID, GenericComparator<16>>;
|
135 | 96 | template class DiskExtendibleHashTable<GenericKey<32>, RID, GenericComparator<32>>;
|
136 | 97 | template class DiskExtendibleHashTable<GenericKey<64>, RID, GenericComparator<64>>;
|
137 |
| - |
138 | 98 | } // namespace bustub
|
0 commit comments