hash package:rebase
Like
hashWithSalt, but no salt is used. The default
implementation uses
hashWithSalt with some default salt.
Instances might want to implement this method to provide a more
efficient implementation than the default implementation.
Compute a hash value for the content of this
ByteArray#,
beginning at the specified offset, using specified number of bytes.
Compute a hash value for the content of this
ByteArray#, using
an initial salt.
This function can for example be used to hash non-contiguous segments
of memory as if they were one contiguous segment, by using the output
of one hash as the salt for the next.
Compute a hash value for the content of this pointer.
Compute a hash value for the content of this pointer, using an initial
salt.
This function can for example be used to hash non-contiguous segments
of memory as if they were one contiguous segment, by using the output
of one hash as the salt for the next.
Convert a
StableName to an
Int. The
Int returned
is not necessarily unique; several
StableNames may map to the
same
Int (in practice however, the chances of this are small,
so the result of
hashStableName makes a good hash key).
Hashes a
Unique into an
Int. Two
Uniques may hash
to the same value, although in practice this is unlikely. The
Int returned makes a good hash key.
Transform a value into a
Hashable value, then hash the
transformed value using the given salt.
This is a useful shorthand in cases where a type can easily be mapped
to another type that is already an instance of
Hashable.
Example:
data Foo = Foo | Bar
deriving (Enum)
instance Hashable Foo where
hashWithSalt = hashUsing fromEnum
Return a hash value for the argument, using the given salt.
The general contract of
hashWithSalt is:
- If two values are equal according to the == method, then
applying the hashWithSalt method on each of the two values
must produce the same integer result if the same salt is used
in each case.
- It is not required that if two values are unequal according
to the == method, then applying the hashWithSalt method
on each of the two values must produce distinct integer results.
However, the programmer should be aware that producing distinct
integer results for unequal values may improve the performance of
hashing-based data structures.
- This method can be used to compute different hash values for the
same input by providing a different salt in each application of the
method. This implies that any instance that defines
hashWithSalt must make use of the salt in its
implementation.
- hashWithSalt may return negative Int values.
Wrap a hashable value, caching the
hash function result.
A map from keys to values. A map cannot contain duplicate keys; each
key can map to at most one value.
A set of values. A set cannot contain duplicate values.
The class of types that can be converted to a hash value.
Minimal implementation:
hashWithSalt.
Hashable is intended exclusively for use in in-memory data
structures. .
Hashable does
not have a fixed standard.
This allows it to improve over time. . Because it does not have a
fixed standard, different computers or computers on different versions
of the code will observe different hash values. As such,
Hashable is not recommended for use other than in-memory
datastructures. Specifically,
Hashable is not intended for
network use or in applications which persist hashed values. For stable
hashing use named hashes: sha256, crc32, xxhash etc.
If you are looking for
Hashable instance in
time
package, check
time-compat
A hashable value along with the result of the
hash function.
Since we support a generic implementation of
hashWithSalt we
cannot also provide a default implementation for that method for the
non-generic instance use case. Instead we provide
defaultHashWith.