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

mappings #43

Merged
merged 1 commit into from
Nov 19, 2023
Merged

mappings #43

merged 1 commit into from
Nov 19, 2023

Conversation

PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Nov 19, 2023

Summary by CodeRabbit

  • New Features

    • Introduced empty function to check if containers are empty.
    • Added const version of operator[] for safer access.
    • New at and emplace functions for enhanced element access and insertion.
  • Refactor

    • Updated return types to auto for more flexible code.
  • Bug Fixes

    • Adjusted getDeletedKey() to return a non-const value, fixing potential issues with key deletion handling.

Copy link

coderabbitai bot commented Nov 19, 2023

Walkthrough

The update enhances the Map and Set classes by introducing empty() functions, adding const accessors, and expanding functionality with at() and emplace() methods. It also adjusts return types for better utility and consistency.

Changes

File(s) Summary
.../kul/map.hpp Added empty() to Map and Set; const version of operator[]; added at() and emplace() to Map; changed return types to auto; modified getDeletedKey() to non-const.

🐇🍂 "In the heart of fall, we hop and tweak,
Code now flows without a creak.
With empty checks and at so sleek,
Our Map and Set are at their peak!" 🍁🌟


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4b8d0ee and 65c63d2.
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 as const, which implies that it should not modify the object state. However, the summary mentions that the return type of getDeletedKey() has been changed to non-const. This discrepancy needs to be resolved. If the intention is to allow modification, the const 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 as const, which implies that it should not modify the object state. However, the summary mentions that the return type of getDeletedKey() has been changed to non-const. This discrepancy needs to be resolved. If the intention is to allow modification, the const 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.

inc/mkn/kul/map.hpp Outdated Show resolved Hide resolved
inc/mkn/kul/map.hpp Outdated Show resolved Hide resolved
inc/mkn/kul/map.hpp Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4b8d0ee and 557fa6a.
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.

Comment on lines 147 to +158
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(); }
Copy link

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.

Suggested change
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(); }

Comment on lines +176 to +177
auto& at(key_type const& k) { return (*map::find(k)).second; }
auto& at(key_type const& k) const { return (*map::find(k)).second; }
Copy link

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.

Suggested change
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)); }
Copy link

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.

Suggested change
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)); }

Comment on lines 225 to +235
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; }
Copy link

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.

Suggested change
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(); }

Comment on lines +254 to +255
auto& at(key_type const& k) { return (*map::find(k)).second; }
auto& at(key_type const& k) const { return (*map::find(k)).second; }
Copy link

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.

Suggested change
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)); }
Copy link

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.

Suggested change
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)); }

@PhilipDeegan PhilipDeegan merged commit bcc8540 into master Nov 19, 2023
3 checks passed
@PhilipDeegan PhilipDeegan deleted the mapped branch November 19, 2023 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant