Remove custom util implementation in favor of quiver

pull/87/head
Miller Adulu 4 years ago
parent e68215b913
commit 888f4f5045
  1. 3
      lib/models/documents/attribute.dart
  2. 5
      lib/models/documents/style.dart
  3. 9
      lib/models/quill_delta.dart
  4. 31
      lib/utils/hashcode.dart

@ -1,4 +1,3 @@
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
import 'package:quiver/core.dart';
enum AttributeScope {
@ -185,7 +184,7 @@ class Attribute<T> {
}
@override
int get hashCode => hashcode.hash3(key, scope, value);
int get hashCode => hash3(key, scope, value);
@override
String toString() {

@ -1,6 +1,5 @@
import 'package:collection/collection.dart';
import 'package:flutter_quill/models/documents/attribute.dart';
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
import 'package:quiver/core.dart';
/* Collection of style attributes */
@ -102,8 +101,8 @@ class Style {
@override
int get hashCode {
final hashes = _attributes.entries
.map((entry) => hashcode.hash2(entry.key, entry.value));
return hashcode.hashObjects(hashes);
.map((entry) => hash2(entry.key, entry.value));
return hashObjects(hashes);
}
@override

@ -7,7 +7,6 @@ library quill_delta;
import 'dart:math' as math;
import 'package:collection/collection.dart';
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
import 'package:quiver/core.dart';
const _attributeEquality = DeepCollectionEquality();
@ -155,11 +154,11 @@ class Operation {
@override
int get hashCode {
if (_attributes != null && _attributes!.isNotEmpty) {
final attrsHash = hashcode.hashObjects(
_attributes!.entries.map((e) => hashcode.hash2(e.key, e.value)));
return hashcode.hash3(key, value, attrsHash);
final attrsHash = hashObjects(
_attributes!.entries.map((e) => hash2(e.key, e.value)));
return hash3(key, value, attrsHash);
}
return hashcode.hash2(key, value);
return hash2(key, value);
}
@override

@ -1,31 +0,0 @@
library quiver.hashcode;
/// Generates a hash code for multiple [objects].
int hashObjects(Iterable objects) =>
_finish(objects.fold(0, (h, i) => _combine(h, i.hashCode)));
/// Generates a hash code for two objects.
int hash2(a, b) => _finish(_combine(_combine(0, a.hashCode), b.hashCode));
/// Generates a hash code for three objects.
int hash3(a, b, c) => _finish(
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode));
/// 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));
}
Loading…
Cancel
Save