-
Notifications
You must be signed in to change notification settings - Fork 874
Make hash by the value allocated, not by pointer #22129
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
Open
cpjulia
wants to merge
37
commits into
devel
Choose a base branch
from
bug-fix/aql-value-hash
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,678
−65
Open
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
446b3bb
Make hash by the value allocated, not by pointer
cpjulia 1977cd9
Removed duplicate
cpjulia e0dafb5
Fix hash function
cpjulia 4572970
Removed special treatment for SLICE_POINTER in hash
cpjulia b8ef3df
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 28eafae
Added missing brace
cpjulia ad56c03
Added comparison for different types
cpjulia f3aa424
Change comparison to use normalized equal instead of binaryEquals for…
cpjulia 0eb6df5
Remove unused variable
cpjulia 9c201b3
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 6f766d1
Fix hash comparison
cpjulia 36eccf0
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 12f1c17
Fix comment
cpjulia b44b774
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia fb50172
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 2650bd8
Simplified AqlValue equal_to, added new tests
cpjulia 4bce568
Added test to check if the new implementation makes more sense in the…
cpjulia 66e216b
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 8a33cdd
Fixed usage of velocypack helper in AqlValue equal_to and added tests
cpjulia 8d4f533
Added new tests
cpjulia 20708d0
Pass seed to avoid collisions and fix tests
cpjulia 3892a23
Added nullptr check to hash
cpjulia d2165d1
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia e6e3225
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia d631a69
Attempt to fix circle ci errors
cpjulia d4d92e3
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 9dcf5f1
Simplified logic in cloneDataAndMoveShadow
cpjulia 2e7a7ba
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 4c83b53
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 2f72dcc
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 51699d9
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 2455622
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 122e129
Simplified hash ccode, removed verbose comments
cpjulia 2f5a6ba
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia d2def76
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia 0fd411a
Merge branch 'devel' of github.com:arangodb/arangodb into bug-fix/aql…
cpjulia df15fb6
Added normalization of -0.0 to +0.0 as in an AqlValue constructor and…
cpjulia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -1371,59 +1371,60 @@ namespace std { | |
| using arangodb::aql::AqlValue; | ||
|
|
||
| size_t hash<AqlValue>::operator()(AqlValue const& x) const noexcept { | ||
| auto t = x.type(); | ||
| switch (t) { | ||
| case AqlValue::VPACK_INLINE: | ||
| return static_cast<size_t>( | ||
| VPackSlice(x._data.inlineSliceMeta.slice).volatileHash()); | ||
| case AqlValue::VPACK_INLINE_INT64: | ||
| case AqlValue::VPACK_INLINE_UINT64: | ||
| case AqlValue::VPACK_INLINE_DOUBLE: | ||
| return static_cast<size_t>( | ||
| VPackSlice(x._data.longNumberMeta.data.slice.slice).volatileHash()); | ||
| // TODO(MBkkt) these hashes have bad distribution | ||
| case AqlValue::VPACK_SLICE_POINTER: | ||
| return std::hash<void const*>()(x._data.slicePointerMeta.pointer); | ||
| case AqlValue::VPACK_MANAGED_SLICE: | ||
| return std::hash<void const*>()(x._data.managedSliceMeta.pointer); | ||
| case AqlValue::VPACK_MANAGED_STRING: | ||
| return std::hash<void const*>()(x._data.managedStringMeta.pointer); | ||
| case AqlValue::RANGE: | ||
| return std::hash<void const*>()(x._data.rangeMeta.range); | ||
| using T = AqlValue::AqlValueType; | ||
| auto aqlValueType = x.type(); | ||
| // as this is non owning, we hash by the pointer | ||
| if (aqlValueType == T::VPACK_SLICE_POINTER) { | ||
| return std::hash<void const*>()(x._data.slicePointerMeta.pointer); | ||
| } | ||
| return 0; | ||
| auto hash64 = x.hash(0); // make a normalized hash, for the semantics of the | ||
| // value regardless of the storae stype | ||
| size_t h = static_cast<size_t>(hash64); | ||
| if (h == 0) { // fallback to avoid collision with the marker that uses h == | ||
| // 0, very unlikely to happen | ||
| h = 1; | ||
| } | ||
|
||
| return h; | ||
| } | ||
|
|
||
| bool equal_to<AqlValue>::operator()(AqlValue const& a, | ||
| AqlValue const& b) const noexcept { | ||
| // TODO(MBkkt) can be just compare two uint64_t? | ||
| auto t = a.type(); | ||
| if (t != b.type()) { | ||
| using T = AqlValue::AqlValueType; | ||
| auto ta = a.type(); | ||
| auto tb = b.type(); | ||
|
|
||
| if (ta == tb) { | ||
| switch (ta) { | ||
| case T::VPACK_INLINE: | ||
| return VPackSlice(a._data.inlineSliceMeta.slice) | ||
| .binaryEquals(VPackSlice(b._data.inlineSliceMeta.slice)); | ||
| case T::VPACK_INLINE_INT64: | ||
| case T::VPACK_INLINE_UINT64: | ||
| case T::VPACK_INLINE_DOUBLE: | ||
| return a._data.longNumberMeta.data.intLittleEndian.val == | ||
| b._data.longNumberMeta.data.intLittleEndian.val; | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case T::VPACK_SLICE_POINTER: | ||
| return a._data.slicePointerMeta.pointer == | ||
| b._data.slicePointerMeta.pointer; | ||
|
||
| case T::RANGE: { | ||
| auto const* ra = a._data.rangeMeta.range; | ||
| auto const* rb = b._data.rangeMeta.range; | ||
| return ra->_low == rb->_low && ra->_high == rb->_high; | ||
| } | ||
| default: | ||
| return a.slice(ta).binaryEquals(b.slice(tb)); | ||
| } | ||
| } | ||
|
|
||
| if (ta == T::RANGE || tb == T::RANGE) { | ||
| return false; | ||
| } | ||
| switch (t) { | ||
| case AqlValue::VPACK_INLINE: | ||
| return VPackSlice(a._data.inlineSliceMeta.slice) | ||
| .binaryEquals(VPackSlice(b._data.inlineSliceMeta.slice)); | ||
| case AqlValue::VPACK_INLINE_INT64: | ||
| case AqlValue::VPACK_INLINE_UINT64: | ||
| case AqlValue::VPACK_INLINE_DOUBLE: | ||
| // equal is equal. sign/endianess does not matter | ||
| return a._data.longNumberMeta.data.intLittleEndian.val == | ||
| b._data.longNumberMeta.data.intLittleEndian.val; | ||
| case AqlValue::VPACK_SLICE_POINTER: | ||
| return a._data.slicePointerMeta.pointer == | ||
| b._data.slicePointerMeta.pointer; | ||
| case AqlValue::VPACK_MANAGED_SLICE: | ||
| return a._data.managedSliceMeta.pointer == | ||
| b._data.managedSliceMeta.pointer; | ||
| case AqlValue::VPACK_MANAGED_STRING: | ||
| return a._data.managedStringMeta.pointer == | ||
| b._data.managedStringMeta.pointer; | ||
| case AqlValue::RANGE: | ||
| return a._data.rangeMeta.range == b._data.rangeMeta.range; | ||
|
|
||
| if (ta == T::VPACK_SLICE_POINTER || tb == T::VPACK_SLICE_POINTER) { | ||
| return false; | ||
| } | ||
| return false; | ||
|
|
||
| return a.slice(ta).binaryEquals(b.slice(tb)); | ||
| } | ||
|
|
||
| } // namespace std | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does the owning make for a difference?
Hashing is a quick look of the content is equal.
In my opinion it should not take into account if the value is owned or not.