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

using custom equal function in block_cache::cache_t #1264

Closed
wants to merge 1 commit into from

Conversation

aldenml
Copy link
Contributor

@aldenml aldenml commented Oct 27, 2016

I expect this to fix the issue #1225 (if not, well, need to keep looking).

The theory behind this is the following:

The custom hash is used to determine the internal bucket in the internal hash table. The libc++ implementation of the find, lookup the bucket and iterate all the elements (it could be one) and test for equality of the value (default is the ==). In this case, not providing a custom equals is a bug.

Why it hasn't happened before? Looking at the boost::unordered_set implementation, branch RC_1_1, in their find algorithm, they lookup the bucket and they "cleverly" returns if only one element is found. If the bucket contains more than one element (hash collision) then they iterate using the equality. In this case, not providing a custom equals is irrelevant, since by "definition", this is a set and hash values should not create a collision.

@aldenml
Copy link
Contributor Author

aldenml commented Oct 27, 2016

Crash happened again in internal tests, theory is wrong, I still think the PR is good

@codecov-io
Copy link

codecov-io commented Oct 28, 2016

Current coverage is 71.01% (diff: 100%)

Merging #1264 into master will decrease coverage by 0.11%

@@             master      #1264   diff @@
==========================================
  Files           391        391          
  Lines         58284      58283     -1   
  Methods        5756       5757     +1   
  Messages          0          0          
  Branches       8790       8790          
==========================================
- Hits          41458      41389    -69   
- Misses        12452      12516    +64   
- Partials       4374       4378     +4   

Powered by Codecov. Last update cb5d116...a7aba0d

@aldenml
Copy link
Contributor Author

aldenml commented Oct 28, 2016

I tracked all the locks on the mutex m_cache_mutex and now I think the problem of not having the "custom equals" was not in play since all the mutations are protected. What do you think about this PR?

, cached_piece_entry const& p2) const
{ return p1.storage.get() == p2.storage.get() && p1.piece == p2.piece; }
};
using cache_t = std::unordered_set<cached_piece_entry, hash_value, equal_value>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this is necessary. If it was, it would have been a compilation error. cached_piece_entry already has an operator== which does this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(line 197)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I looked for it...I guess I'm over thinking with the issue/crash

@aldenml aldenml closed this Oct 28, 2016
@aldenml aldenml deleted the block_cache-key-1.2 branch October 28, 2016 16:47
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.

3 participants