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

Deprecate hash functions #757

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.3-wip

- Deprecate all `hash` functions. Use functions in `Object` instead.

## 3.2.2

- Fix a number of doc comment issues.
Expand Down
30 changes: 8 additions & 22 deletions lib/src/core/hash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,17 @@
// limitations under the License.

/// Generates a hash code for multiple [objects].
int hashObjects(Iterable objects) =>
_finish(objects.fold(0, (h, i) => _combine(h, i.hashCode)));
@Deprecated('Use Object.hashAll instead')
int hashObjects(Iterable objects) => Object.hashAll(objects);

/// Generates a hash code for two objects.
int hash2(a, b) => _finish(_combine(_combine(0, a.hashCode), b.hashCode));
@Deprecated('Use Object.hash instead')
int hash2(a, b) => Object.hash(a, b);

/// Generates a hash code for three objects.
int hash3(a, b, c) => _finish(
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode));
@Deprecated('Use Object.hash instead')
int hash3(a, b, c) => Object.hash(a, b, c);

/// Generates a hash code for four objects.
int hash4(a, b, c, d) => _finish(_combine(
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode),
d.hashCode));

// Jenkins hash functions

int _combine(int hash, int value) {
hash = 0x1fffffff & (hash + value);
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}

int _finish(int hash) {
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
@Deprecated('Use Object.hash instead')
int hash4(a, b, c, d) => Object.hash(a, b, c, d);
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >-
Quiver is a set of utility libraries for Dart that makes using many Dart
libraries easier and more convenient, or adds additional functionality.
repository: https://github.com/google/quiver-dart
version: 3.2.2
version: 3.2.3-wip

# When updating SDK lower bound, also update .github/workflows/dart.yml to test
# against the new lower bound.
Expand Down
2 changes: 2 additions & 0 deletions test/core/hash_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: deprecated_member_use_from_same_package

library quiver.core.hash_test;

import 'package:quiver/src/core/hash.dart';
Expand Down