-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* P0 Starter Code * Minor Change to fix in GCC * More changes to fix * Fixing format erros * Fixing Clang-tidy errors * Tidy fix 2 * Improving Grammar in comments
- Loading branch information
1 parent
89c7a5f
commit 0d4e3f8
Showing
7 changed files
with
517 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#pragma once | ||
|
||
#include <bitset> | ||
#include <functional> | ||
#include <memory> | ||
#include <mutex> // NOLINT | ||
#include <string> | ||
#include <vector> | ||
|
||
#define MAX_BITS 64 | ||
#define DEFAULT_CARDINALITY 0 | ||
|
||
namespace bustub { | ||
|
||
/** @brief Hash value type. */ | ||
using hash_t = uint64_t; | ||
|
||
/** @brief Constant for HLL. */ | ||
static const double CONSTANT = 0.79402; | ||
|
||
template <typename T> | ||
class HyperLogLog { | ||
public: | ||
HyperLogLog() = delete; | ||
|
||
explicit HyperLogLog(int16_t n_bits) : cardinality_(0) {} | ||
|
||
/** | ||
* @brief Getter value for cardinality. | ||
* | ||
* @returns cardinality value | ||
*/ | ||
auto GetCardinality() { return cardinality_; } | ||
|
||
/** | ||
* @brief Ddds a value into the HyperLogLog. | ||
* | ||
* @param[in] val - value that's added into hyperloglog | ||
*/ | ||
auto AddElem(T val) -> void; | ||
|
||
/** | ||
* @brief Function that computes cardinality. | ||
*/ | ||
auto ComputeCardinality() -> void; | ||
|
||
private: | ||
/** | ||
* @brief Calculates Hash of a given value. | ||
* | ||
* @param[in] val - value | ||
* @returns hash integer of given input value | ||
*/ | ||
inline auto CalculateHash(T val) -> hash_t; | ||
|
||
/** | ||
* @brief Function that computes binary. | ||
* | ||
* | ||
* @param[in] hash | ||
* @returns binary of a given hash | ||
*/ | ||
auto ComputeBinary(const hash_t &hash) const -> std::bitset<MAX_BITS>; | ||
|
||
/** | ||
* @brief Function that computes leading zeros. | ||
* | ||
* @param[in] bset - binary values of a given bitset | ||
* @returns leading zeros of given binary set | ||
*/ | ||
auto PositionOfLeftmostOne(const std::bitset<MAX_BITS> &bset) const -> uint64_t; | ||
|
||
/** @brief Cardinality value. */ | ||
size_t cardinality_; | ||
|
||
/** @todo (student) can add their data structures that support HyperLogLog */ | ||
}; | ||
|
||
} // namespace bustub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <bitset> | ||
#include <functional> | ||
#include <memory> | ||
#include <mutex> // NOLINT | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#define BUCKET_SIZE 4UL | ||
#define CONSTANT 0.79402 | ||
#define MAX_SIZE 7UL | ||
|
||
namespace bustub { | ||
|
||
template <typename T> | ||
class HyperLogLogPresto { | ||
/** | ||
* INSTRUCTIONS: Testing framework will use the GetDenseBucket and GetOverflow function, | ||
* hence SHOULD NOT be deleted. It's essential to use the dense_bucket_ | ||
* data structure. | ||
*/ | ||
|
||
/** @brief Hash type. */ | ||
using hash_t = uint64_t; | ||
|
||
public: | ||
/** @brief Disabling default constructor. */ | ||
HyperLogLogPresto() = delete; | ||
|
||
/** @brief Parameterized constructor. */ | ||
explicit HyperLogLogPresto(int16_t n_leading_bits) : cardinality_(0) {} | ||
|
||
/** @brief Returns the dense_bucket_ data structure. */ | ||
auto GetDenseBucket() const -> std::vector<std::bitset<BUCKET_SIZE>> { return dense_bucket_; } | ||
|
||
/** @brief Returns overflow bucket of a specific given index. */ | ||
auto GetOverflowBucketofIndex(uint16_t idx) { return overflow_bucket_[idx]; } | ||
|
||
/** @brief Retusn the cardinality of the set. */ | ||
auto GetCardinality() const -> uint64_t { return cardinality_; } | ||
|
||
/** @brief Element is added for HLL calculation. */ | ||
auto AddElem(T val) -> void; | ||
|
||
/** @brief Function to compute cardinality. */ | ||
auto ComputeCardinality() -> void; | ||
|
||
private: | ||
/** @brief Calculate Hash. | ||
* | ||
* @param[in] val | ||
* | ||
* @returns hash value | ||
*/ | ||
inline auto CalculateHash(T val) -> hash_t { return std::hash<T>{}(val); } | ||
|
||
/** @brief Structure holding dense buckets (or also known as registers). */ | ||
std::vector<std::bitset<BUCKET_SIZE>> dense_bucket_; | ||
|
||
/** @brief Structure holding overflow buckets. */ | ||
std::unordered_map<uint16_t, std::bitset<MAX_SIZE - BUCKET_SIZE>> overflow_bucket_; | ||
|
||
/** @brief Storing cardinality value */ | ||
uint64_t cardinality_; | ||
|
||
// TODO(student) - can add more data structures as required | ||
}; | ||
|
||
} // namespace bustub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
add_library( | ||
bustub_primer | ||
OBJECT | ||
hyperloglog.cpp | ||
hyperloglog_presto.cpp | ||
orset.cpp | ||
orset_driver.cpp | ||
trie.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "primer/hyperloglog.h" | ||
|
||
namespace bustub { | ||
|
||
template <typename T> | ||
auto inline HyperLogLog<T>::CalculateHash(T val) -> hash_t { | ||
/** @todo student - implement the function */ | ||
return 0; | ||
} | ||
|
||
template <typename T> | ||
auto HyperLogLog<T>::ComputeBinary(const hash_t &hash) const -> std::bitset<MAX_BITS> { | ||
/** @todo student - implement the function */ | ||
return {0}; | ||
} | ||
|
||
template <typename T> | ||
auto HyperLogLog<T>::PositionOfLeftmostOne(const std::bitset<MAX_BITS> &bset) const -> uint64_t { | ||
/** @todo student - implement the function*/ | ||
return 0; | ||
} | ||
|
||
template <typename T> | ||
auto HyperLogLog<T>::AddElem(T val) -> void { | ||
/** @todo implement the function */ | ||
} | ||
|
||
template <typename T> | ||
auto HyperLogLog<T>::ComputeCardinality() -> void { | ||
/** @todo - student implement the function */ | ||
} | ||
|
||
template class HyperLogLog<int64_t>; | ||
template class HyperLogLog<std::string>; | ||
|
||
} // namespace bustub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "primer/hyperloglog_presto.h" | ||
|
||
namespace bustub { | ||
|
||
template <typename T> | ||
auto HyperLogLogPresto<T>::AddElem(T val) -> void { | ||
/** @todo (student) has to fill the function */ | ||
} | ||
|
||
template <typename T> | ||
auto HyperLogLogPresto<T>::ComputeCardinality() -> void { | ||
// TODO(student) - implement the function | ||
} | ||
|
||
template class HyperLogLogPresto<int64_t>; | ||
template class HyperLogLogPresto<std::string>; | ||
} // namespace bustub |
Oops, something went wrong.