Remove hashnode as a dependency and localize its functionality to the package.

Maintenance was done long time ago hence no need to wait for the update
pull/87/head
Miller Adulu 4 years ago
parent e9c5a2238e
commit be56739a53
  1. 5
      lib/models/documents/attribute.dart
  2. 6
      lib/models/documents/style.dart
  3. 10
      lib/models/quill_delta.dart
  4. 31
      lib/utils/hashcode.dart
  5. 7
      pubspec.lock
  6. 1
      pubspec.yaml

@ -1,4 +1,5 @@
import 'package:quiver_hashcode/hashcode.dart';
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
enum AttributeScope {
INLINE, // refer to https://quilljs.com/docs/formats/#inline
@ -181,7 +182,7 @@ class Attribute<T> {
}
@override
int get hashCode => hash3(key, scope, value);
int get hashCode => hashcode.hash3(key, scope, value);
@override
String toString() {

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

@ -7,7 +7,7 @@ library quill_delta;
import 'dart:math' as math;
import 'package:collection/collection.dart';
import 'package:quiver_hashcode/hashcode.dart';
import 'package:flutter_quill/utils/hashcode.dart' as hashcode;
const _attributeEquality = DeepCollectionEquality();
const _valueEquality = DeepCollectionEquality();
@ -155,10 +155,10 @@ class Operation {
int get hashCode {
if (_attributes != null && _attributes!.isNotEmpty) {
final attrsHash =
hashObjects(_attributes!.entries.map((e) => hash2(e.key, e.value)));
return hash3(key, value, attrsHash);
hashcode.hashObjects(_attributes!.entries.map((e) => hashcode.hash2(e.key, e.value)));
return hashcode.hash3(key, value, attrsHash);
}
return hash2(key, value);
return hashcode.hash2(key, value);
}
@override
@ -301,7 +301,7 @@ class Delta {
}
@override
int get hashCode => hashObjects(_operations);
int get hashCode => hashcode.hashObjects(_operations);
/// Retain [count] of characters from current position.
void retain(int count, [Map<String, dynamic>? attributes]) {

@ -0,0 +1,31 @@
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));
}

@ -212,13 +212,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
quiver_hashcode:
dependency: "direct main"
description:
name: quiver_hashcode
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
sky_engine:
dependency: transitive
description: flutter

@ -12,7 +12,6 @@ environment:
dependencies:
flutter:
sdk: flutter
quiver_hashcode: ^2.0.0
collection: ^1.15.0
tuple: ^2.0.0
url_launcher: ^6.0.2

Loading…
Cancel
Save