-
Notifications
You must be signed in to change notification settings - Fork 143
IGNITE-28081 Added hashing functions for C++ client #7750
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f17a2a1
IGNITE-28081 added hashing functions for C++ client
Erixonich 6340d58
IGNITE-28081 robot review fixes
Erixonich de79b55
IGNITE-28081 robot review fixes
Erixonich 41489a2
IGNITE-28081 added error desc
Erixonich 9c3cd99
IGNITE-28081 review fixes
Erixonich 2b7b90f
IGNITE-28081 review fixes
Erixonich 94dfaf4
IGNITE-28081 review fixes round 4
Erixonich 994d400
IGNITE-28081 review fixes
Erixonich 7f13c31
IGNITE-28081 todo optimization added
Erixonich 9d25cbb
IGNITE-28081 smol fix
Erixonich 4678675
IGNITE-28081 smol fix 2
Erixonich 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
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
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
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
77 changes: 77 additions & 0 deletions
77
modules/platforms/cpp/ignite/common/detail/hash_calculator.cpp
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| // | ||
|
|
||
| #include "hash_calculator.h" | ||
|
|
||
| #include "hash_utils.h" | ||
|
|
||
| namespace ignite::detail { | ||
|
|
||
| std::int32_t hash_calculator::calc_hash(const primitive& val, std::int32_t scale, std::int32_t precision) { | ||
| auto type = val.get_type(); | ||
|
|
||
| switch (type) { | ||
| case ignite_type::BOOLEAN: | ||
| return hash(val.get<bool>()); | ||
| case ignite_type::NIL: | ||
| return hash(static_cast<std::int8_t>(0)); | ||
| case ignite_type::INT8: | ||
| return hash(val.get<std::int8_t>()); | ||
| case ignite_type::INT16: | ||
| return hash(val.get<std::int16_t>()); | ||
| case ignite_type::INT32: | ||
| return hash(val.get<std::int32_t>()); | ||
| case ignite_type::INT64: | ||
| return hash(val.get<std::int64_t>()); | ||
| case ignite_type::FLOAT: | ||
| return hash(val.get<float>()); | ||
| case ignite_type::DOUBLE: | ||
| return hash(val.get<double>()); | ||
| case ignite_type::DECIMAL: | ||
| return hash(val.get<big_decimal>(), scale); | ||
| case ignite_type::DATE: | ||
| return hash(val.get<ignite_date>()); | ||
| case ignite_type::TIME: | ||
| return hash(val.get<ignite_time>(), precision); | ||
| case ignite_type::DATETIME: | ||
| return hash(val.get<ignite_date_time>(), precision); | ||
| case ignite_type::TIMESTAMP: | ||
| return hash(val.get<ignite_timestamp>(), precision); | ||
| case ignite_type::UUID: | ||
| return hash(val.get<uuid>()); | ||
| case ignite_type::STRING: | ||
| return hash(val.get<std::string>()); | ||
| case ignite_type::BYTE_ARRAY: | ||
| return hash(val.get<std::vector<std::byte>>()); | ||
| case ignite_type::PERIOD: | ||
| case ignite_type::DURATION: | ||
| case ignite_type::UNDEFINED: | ||
| default: | ||
| throw ignite_error( | ||
| error::code::INTERNAL, | ||
| "Can't calculate hash value for type = " + std::to_string(static_cast<int>(type)) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| void hash_calculator::append(const primitive &val, std::int32_t scale, std::int32_t precision) { | ||
| auto h = calc_hash(val, scale, precision); | ||
|
|
||
| m_state = hash32(m_state, h); | ||
| } | ||
| } // namespace ignite::detail | ||
60 changes: 60 additions & 0 deletions
60
modules/platforms/cpp/ignite/common/detail/hash_calculator.h
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "primitive.h" | ||
|
|
||
| namespace ignite::detail { | ||
|
|
||
| /** | ||
| * Calculator of hashes for all basic types. | ||
| */ | ||
| class hash_calculator { | ||
|
isapego marked this conversation as resolved.
|
||
| public: | ||
| /** | ||
| * Calculates hash. | ||
| * @param val Value of basic type. | ||
| * @param scale Scale applies to some types (e.g. big_decimal), value ignored by other types. | ||
| * @param precision Precision applies to some type (e.g. ignite_time) value ignored by other types. | ||
| * @return Hash value. | ||
| */ | ||
| static std::int32_t calc_hash(const primitive& val, std::int32_t scale, std::int32_t precision); | ||
|
isapego marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Appends hash of provided value into internal state. | ||
| * @param val Value of basic type. | ||
| * @param scale Scale applies to some types (e.g. big_decimal), value ignored by other types. | ||
| * @param precision Precision applies to some type (e.g. ignite_time) value ignored by other types. | ||
| */ | ||
| void append(const primitive& val, std::int32_t scale, std::int32_t precision); | ||
|
isapego marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Retrieves accumulated hash from internal state. | ||
| * @return hash from internal state. | ||
| */ | ||
| [[nodiscard]] std::int32_t result_hash() const { | ||
| return m_state; | ||
| } | ||
|
|
||
| private: | ||
| /** Internal state. */ | ||
| std::int32_t m_state{0}; | ||
| }; | ||
|
|
||
| } // namespace ignite::detail | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.