-
Notifications
You must be signed in to change notification settings - Fork 3
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
mappings #43
mappings #43
Conversation
WalkthroughThe update enhances the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 7
Configuration used: CodeRabbit UI
Files selected for processing (1)
- inc/mkn/kul/map.hpp (6 hunks)
Additional comments: 4
inc/mkn/kul/map.hpp (4)
160-160: The
getDeletedKey()
method is marked asconst
, which implies that it should not modify the object state. However, the summary mentions that the return type ofgetDeletedKey()
has been changed to non-const. This discrepancy needs to be resolved. If the intention is to allow modification, theconst
qualifier should be removed. Otherwise, the summary should be updated to reflect the actual change.202-202: The summary states that
getDeletedKey()
has been changed to non-const, but the code still shows it as const. If the intention is to allow modifications to the deleted key, the const qualifier should be removed. Otherwise, the summary should be updated to reflect the actual implementation.238-238: The
getDeletedKey()
method is marked asconst
, which implies that it should not modify the object state. However, the summary mentions that the return type ofgetDeletedKey()
has been changed to non-const. This discrepancy needs to be resolved. If the intention is to allow modification, theconst
qualifier should be removed. Otherwise, the summary should be updated to reflect the actual change.275-275: The summary states that
getDeletedKey()
has been changed to non-const, but the code still shows it as const. If the intention is to allow modifications to the deleted key, the const qualifier should be removed. Otherwise, the summary should be updated to reflect the actual implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 6
Configuration used: CodeRabbit UI
Files selected for processing (1)
- inc/mkn/kul/map.hpp (6 hunks)
Additional comments: 1
inc/mkn/kul/map.hpp (1)
- 91-94: The addition of the
empty()
function is a good enhancement for usability. It directly calls the underlying_map.empty()
which is the correct and efficient way to check if the container is empty.
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | ||
void clear() { Hash::clear(); } | ||
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | ||
T& operator[](key_type const& key) { return Hash::operator[](key); } | ||
|
||
size_type erase(key_type const& key) { return Hash::erase(key); } | ||
iterator begin() { return Hash::begin(); } | ||
iterator end() { return Hash::end(); } | ||
const_iterator begin() const { return Hash::begin(); } | ||
const_iterator end() const { return Hash::end(); } | ||
size_type size() const { return Hash::size(); } | ||
const key_type getDeletedKey() const { return Hash::deleted_key(); } | ||
auto empty() const { return size() == 0; } | ||
key_type getDeletedKey() const { return Hash::deleted_key(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty()
function should directly call Hash::empty()
instead of comparing size()
to zero for efficiency reasons. This change was correctly made in the Map
class but not in the Set
class.
- auto empty() const { return size() == 0; }
+ auto empty() const { return Hash::empty(); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | |
void clear() { Hash::clear(); } | |
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | |
T& operator[](key_type const& key) { return Hash::operator[](key); } | |
size_type erase(key_type const& key) { return Hash::erase(key); } | |
iterator begin() { return Hash::begin(); } | |
iterator end() { return Hash::end(); } | |
const_iterator begin() const { return Hash::begin(); } | |
const_iterator end() const { return Hash::end(); } | |
size_type size() const { return Hash::size(); } | |
const key_type getDeletedKey() const { return Hash::deleted_key(); } | |
auto empty() const { return size() == 0; } | |
key_type getDeletedKey() const { return Hash::deleted_key(); } | |
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | |
void clear() { Hash::clear(); } | |
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | |
size_type erase(key_type const& key) { return Hash::erase(key); } | |
iterator begin() { return Hash::begin(); } | |
iterator end() { return Hash::end(); } | |
const_iterator begin() const { return Hash::begin(); } | |
const_iterator end() const { return Hash::end(); } | |
size_type size() const { return Hash::size(); } | |
auto empty() const { return Hash::empty(); } | |
key_type getDeletedKey() const { return Hash::deleted_key(); } |
auto& at(key_type const& k) { return (*map::find(k)).second; } | ||
auto& at(key_type const& k) const { return (*map::find(k)).second; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous comment about the at()
function implementation is still valid. The current implementation will lead to undefined behavior if the key is not present. It should be corrected to use the at()
function provided by the underlying map.
- auto& at(key_type const& k) { return (*map::find(k)).second; }
- auto& at(key_type const& k) const { return (*map::find(k)).second; }
+ auto& at(key_type const& k) { return map::at(k); }
+ auto& at(key_type const& k) const { return map::at(k); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
auto& at(key_type const& k) { return (*map::find(k)).second; } | |
auto& at(key_type const& k) const { return (*map::find(k)).second; } | |
auto& at(key_type const& k) { return map::at(k); } | |
auto& at(key_type const& k) const { return map::at(k); } |
map::emplace(k, v); | ||
return *this; | ||
} | ||
|
||
void setDeletedKey(key_type const& key) { map::set_deleted_key(key); } | ||
void setEmptyKey(key_type const& key) { map::set_empty_key(key); } | ||
void clear() { map::clear(); } | ||
std::pair<iterator, bool> insert(std::pair<K, V> const& obj) { return map::insert(obj); } | ||
std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous comment about the insert
function taking two parameters const K k, V v
is still valid. The key should be taken by const reference to avoid unnecessary copying for non-primitive types.
- std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); }
+ std::pair<iterator, bool> insert(const K& k, const V& v) { return insert(std::pair<K, V>(k, v)); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); } | |
std::pair<iterator, bool> insert(const K& k, const V& v) { return insert(std::pair<K, V>(k, v)); } |
void clear() { Hash::clear(); } | ||
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | ||
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | ||
T& operator[](key_type const& key) { return Hash::operator[](key); } | ||
|
||
size_type erase(key_type const& key) { return Hash::erase(key); } | ||
iterator begin() { return Hash::begin(); } | ||
iterator end() { return Hash::end(); } | ||
const_iterator begin() const { return Hash::begin(); } | ||
const_iterator end() const { return Hash::end(); } | ||
size_type size() const { return Hash::size(); } | ||
const key_type getDeletedKey() const { return Hash::deleted_key(); } | ||
auto empty() const { return size() == 0; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty()
function in the Set
class within the dense::hash
namespace should also directly call Hash::empty()
instead of comparing size()
to zero for efficiency reasons, as previously mentioned for the Set
class in the hash
namespace.
- auto empty() const { return size() == 0; }
+ auto empty() const { return Hash::empty(); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
void clear() { Hash::clear(); } | |
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | |
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | |
T& operator[](key_type const& key) { return Hash::operator[](key); } | |
size_type erase(key_type const& key) { return Hash::erase(key); } | |
iterator begin() { return Hash::begin(); } | |
iterator end() { return Hash::end(); } | |
const_iterator begin() const { return Hash::begin(); } | |
const_iterator end() const { return Hash::end(); } | |
size_type size() const { return Hash::size(); } | |
const key_type getDeletedKey() const { return Hash::deleted_key(); } | |
auto empty() const { return size() == 0; } | |
void clear() { Hash::clear(); } | |
void setDeletedKey(key_type const& key) { Hash::set_deleted_key(key); } | |
std::pair<iterator, bool> insert(const T obj) { return Hash::insert(obj); } | |
size_type erase(key_type const& key) { return Hash::erase(key); } | |
iterator begin() { return Hash::begin(); } | |
iterator end() { return Hash::end(); } | |
const_iterator begin() const { return Hash::begin(); } | |
const_iterator end() const { return Hash::end(); } | |
size_type size() const { return Hash::size(); } | |
auto empty() const { return Hash::empty(); } |
auto& at(key_type const& k) { return (*map::find(k)).second; } | ||
auto& at(key_type const& k) const { return (*map::find(k)).second; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The at()
function implementation issue mentioned earlier for the Map
class in the hash
namespace also applies here in the dense::hash
namespace. It should be corrected to use the at()
function provided by the underlying map to prevent undefined behavior.
- auto& at(key_type const& k) { return (*map::find(k)).second; }
- auto& at(key_type const& k) const { return (*map::find(k)).second; }
+ auto& at(key_type const& k) { return map::at(k); }
+ auto& at(key_type const& k) const { return map::at(k); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
auto& at(key_type const& k) { return (*map::find(k)).second; } | |
auto& at(key_type const& k) const { return (*map::find(k)).second; } | |
auto& at(key_type const& k) { return map::at(k); } | |
auto& at(key_type const& k) const { return map::at(k); } |
@@ -240,21 +251,26 @@ class Map : public google::dense_hash_map<K, V, HashFcn, EqualKey> { | |||
typedef typename map::iterator iterator; | |||
typedef typename map::const_iterator const_iterator; | |||
|
|||
auto& at(key_type const& k) { return (*map::find(k)).second; } | |||
auto& at(key_type const& k) const { return (*map::find(k)).second; } | |||
|
|||
void setDeletedKey(key_type const& key) { map::set_deleted_key(key); } | |||
void setEmptyKey(key_type const& key) { map::set_empty_key(key); } | |||
void clear() { map::clear(); } | |||
std::pair<iterator, bool> insert(std::pair<K, V> const& obj) { return map::insert(obj); } | |||
std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous comment about the insert
function taking two parameters const K k, V v
is still valid here in the dense::hash
namespace. The key should be taken by const reference to avoid unnecessary copying for non-primitive types.
- std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); }
+ std::pair<iterator, bool> insert(const K& k, const V& v) { return insert(std::pair<K, V>(k, v)); }
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
std::pair<iterator, bool> insert(const K k, V v) { return insert(std::pair<K, V>(k, v)); } | |
std::pair<iterator, bool> insert(const K& k, const V& v) { return insert(std::pair<K, V>(k, v)); } |
Summary by CodeRabbit
New Features
empty
function to check if containers are empty.const
version ofoperator[]
for safer access.at
andemplace
functions for enhanced element access and insertion.Refactor
auto
for more flexible code.Bug Fixes
getDeletedKey()
to return a non-const value, fixing potential issues with key deletion handling.