Commit fede5e0c authored by Mark Nordine's avatar Mark Nordine

Merge branch 'hash-code' into 'master'

Hash code

See merge request !4
parents 8f7ecbbb 5e7ce8a9
Pipeline #34589921 passed with stages
in 2 minutes and 8 seconds
......@@ -94,6 +94,27 @@ class ByteArray
return true;
}
@override
int get hashCode
{
final tempOffset = offset;
const p = 16777619;
var hash = 2166136261;
for (var i = 0; i < length; i++)
hash = (hash ^ this[i]) * p;
offset = tempOffset;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/// Copies bytes from [bytes] to [this]
void writeBytes(ByteArray bytes, [int offset = 0, int byteCount = 0])
{
......
......@@ -337,6 +337,7 @@ void main() {
..offset = 0;
expect(bytes, equals(bytes2));
expect(bytes.hashCode, equals(bytes2.hashCode));
});
test('byte stream', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment