Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelhatherly/contenthashes.jl
Julia package to hash any object by its content.
https://github.com/michaelhatherly/contenthashes.jl
hashing julia
Last synced: about 1 month ago
JSON representation
Julia package to hash any object by its content.
- Host: GitHub
- URL: https://github.com/michaelhatherly/contenthashes.jl
- Owner: MichaelHatherly
- License: mit
- Created: 2021-10-06T14:47:29.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-01T21:12:08.000Z (9 months ago)
- Last Synced: 2024-11-02T05:05:29.517Z (2 months ago)
- Topics: hashing, julia
- Language: Julia
- Homepage:
- Size: 26.4 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ContentHashes
A generic object hashing implementation that hashes the exact content of
objects in *all* cases rather than using the (much faster) `objectid`. This can
be useful when you want to know whether two distinct objects do in fact contain
the same content without having to implement custom `Base.hash` methods that do
the comparisons manually. You may also not actually "own" the types which you
would need to implement `Base.hash` for, which would be type-piracy.## Usage
Use the `ContentHashes.hash` function to hash any objects. This `hash` function
is not exported so that it won't conflict with the `Base.hash` function.```
julia> using ContentHashesjulia> struct T
x
endjulia> a = T([]);
julia> b = T([]);
julia> hash(a) === hash(b)
falsejulia> ContentHashes.hash(a) === ContentHashes.hash(b)
truejulia> f = x -> x + 1
#1 (generic function with 1 method)julia> g = x -> x + 1
#3 (generic function with 1 method)julia> hash(f) === hash(g)
falsejulia> ContentHashes.hash(f) === ContentHashes.hash(g)
true
```