# \#hash

**URL:** https://discourse.julialang.org/tag/hash/520.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Create a set with custom hash and isequal](https://discourse.julialang.org/t/create-a-set-with-custom-hash-and-isequal/127862)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 7\
**Last updated:** [April 9, 2025, 7:31pm UTC](https://discourse.julialang.org/t/create-a-set-with-custom-hash-and-isequal/127862 "2025-04-09T19:31:09Z")

</div>

Is it possible to create a Set{MyType} that uses a custom hash and isequal functions s.t. it is essentially a set of equivalence classes w.r.t the equivalence relation defined by my hash and isequal? I want to do this wi…

---

## [About the low quality of Base.hash()](https://discourse.julialang.org/t/about-the-low-quality-of-base-hash/127707)

<div class="topic-metadata">

**Author:** [@noteas](https://discourse.julialang.org/u/noteas)\
**Replies:** 8\
**Last updated:** [April 4, 2025, 10:04pm UTC](https://discourse.julialang.org/t/about-the-low-quality-of-base-hash/127707 "2025-04-04T22:04:49Z")

</div>

I was implementing a 1d noise function where hashes of Ints were needed, when I found Base.hash() is of surprisingly low quality. I wonder whether this should be an issue or not. Consider the following example: using P…

---

## [Dict with integer keys and fastest insertion?](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 8\
**Last updated:** [January 25, 2025, 1:28pm UTC](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171 "2025-01-25T13:28:35Z")

</div>

What are the best options for a dict/map with integer keys and the fastest insert/update? For background, I wish to aggregate those position-weight pairs (p,w) where the position is the same, I’m tinkering with the idea …

---

## [Why must the second argument of \`hash\` come from another hash function?](https://discourse.julialang.org/t/why-must-the-second-argument-of-hash-come-from-another-hash-function/124783)

<div class="topic-metadata">

**Author:** [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Replies:** 5\
**Last updated:** [January 15, 2025, 9:34pm UTC](https://discourse.julialang.org/t/why-must-the-second-argument-of-hash-come-from-another-hash-function/124783 "2025-01-15T21:34:35Z")

</div>

The documentation for hash contains an example that has the following comment: # only use the output of another hash function as the second argument What happens if I just provide any UInt64 value as the second argumen…

---

## [In Set, what's decompose?](https://discourse.julialang.org/t/in-set-whats-decompose/124031)

<div class="topic-metadata">

**Author:** [@phma](https://discourse.julialang.org/u/phma)\
**Replies:** 4\
**Last updated:** [December 22, 2024, 6:26am UTC](https://discourse.julialang.org/t/in-set-whats-decompose/124031 "2024-12-22T06:26:38Z")

</div>

I wrote a function which computes something using a SortedSet of a type I defined, which is a fixed-size SVector with no variable-size fields. I thought that maybe using a Set would make it faster, so I changed SortedSet …

---

## [How to achieve collision-free "hash codes" in one single Julia session?](https://discourse.julialang.org/t/how-to-achieve-collision-free-hash-codes-in-one-single-julia-session/123428)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 2\
**Last updated:** [December 3, 2024, 11:08pm UTC](https://discourse.julialang.org/t/how-to-achieve-collision-free-hash-codes-in-one-single-julia-session/123428 "2024-12-03T23:08:19Z")

</div>

I have many mixed composite-type instances that I need to compare their equality (by ===) when I don’t necessarily (want to) have access to them directly. I do not want to directly store a reference (like Ref or a struc…

---

## [In what case \`x===y\` and \`objectid(x) == objectid(y)\` are not interchangable?](https://discourse.julialang.org/t/in-what-case-x-y-and-objectid-x-objectid-y-are-not-interchangable/123265)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 3\
**Last updated:** [November 29, 2024, 11:42pm UTC](https://discourse.julialang.org/t/in-what-case-x-y-and-objectid-x-objectid-y-are-not-interchangable/123265 "2024-11-29T23:42:25Z")

</div>

I was reading the official documentation and found the following statement about objectid: If x === y then objectid(x) == objectid(y) , and usually when x !== y , objectid(x) != objectid(y) . It seems that there are …

---

## [S3 Multipart Upload failed with SignatureDoesNotMatch error](https://discourse.julialang.org/t/s3-multipart-upload-failed-with-signaturedoesnotmatch-error/113363)

<div class="topic-metadata">

**Author:** [@Chamika\_Kasun](https://discourse.julialang.org/u/Chamika_Kasun)\
**Replies:** 0\
**Last updated:** [April 22, 2024, 11:14pm UTC](https://discourse.julialang.org/t/s3-multipart-upload-failed-with-signaturedoesnotmatch-error/113363 "2024-04-22T23:14:24Z")

</div>

I tried to do the multipart upload with the S3 methods as follows using AWS.ji library, but every time it gives me the following error, appreciate if someone can point out the mistake that I’ve made. \<Error\>\<Code\>Signat…

---

## [Why do hash functions use xor to combine multiple values?](https://discourse.julialang.org/t/why-do-hash-functions-use-xor-to-combine-multiple-values/109967)

<div class="topic-metadata">

**Author:** [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Replies:** 11\
**Last updated:** [February 9, 2024, 5:15pm UTC](https://discourse.julialang.org/t/why-do-hash-functions-use-xor-to-combine-multiple-values/109967 "2024-02-09T17:15:24Z")

</div>

Continuing the discussion from Dictionary lookup errors when the struct contains empty vectors: Usually in these hash function one sees xor being used to combine the results of multiple values. I myself usually also us…

---

## [Should custom hash functions distinguish types?](https://discourse.julialang.org/t/should-custom-hash-functions-distinguish-types/106984)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 2\
**Last updated:** [December 1, 2023, 11:16am UTC](https://discourse.julialang.org/t/should-custom-hash-functions-distinguish-types/106984 "2023-12-01T11:16:17Z")

</div>

Suppose my package define two struct types A and B, each containing just a single field called data. Then I overload Base.hash as follows: import Base: hash hash(a::A, i) = hash(a.data, i) hash(b::B, i) = hash(b.data,…

---

## [Trouble defining hash/isequal for an interval type](https://discourse.julialang.org/t/trouble-defining-hash-isequal-for-an-interval-type/106629)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 7\
**Last updated:** [November 26, 2023, 2:58pm UTC](https://discourse.julialang.org/t/trouble-defining-hash-isequal-for-an-interval-type/106629 "2023-11-26T14:58:46Z")

</div>

I tried to practice on this topic, but evidently I still lack a lot of knowledge to be profitable. I would like to be able to merge the two dictionaries so that, for example, merge(da,db) ==db That is, having da and db…

---

## [Dictionary with custom hash function](https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168)

<div class="topic-metadata">

**Author:** [@tisztamo](https://discourse.julialang.org/u/tisztamo)\
**Replies:** 6\
**Last updated:** [December 30, 2021, 7:45am UTC](https://discourse.julialang.org/t/dictionary-with-custom-hash-function/49168 "2021-12-30T07:45:22Z")

</div>

In a tight loop (50-100ns/cycle) I am using a dict filled with randomly generated UInt64 keys. I think that they could be used directly in a hashmap, without hashing, so I am looking for a hashmap with a custom (here th…

---

## [Why is objectid not foldable for type arguments?](https://discourse.julialang.org/t/why-is-objectid-not-foldable-for-type-arguments/101928)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 3\
**Last updated:** [July 22, 2023, 6:06pm UTC](https://discourse.julialang.org/t/why-is-objectid-not-foldable-for-type-arguments/101928 "2023-07-22T18:06:31Z")

</div>

For some types, objectid now folds in Julia 1.10-alpha1: julia\> f() = objectid(1); @code\_typed f() CodeInfo( 1 ─ return 0x5bca7c69b0d0ebca ) =\> UInt64 However, it doesn’t fold with a type as argument: julia\> f() =…

---

## [Can I index a DataFrame using a String key?](https://discourse.julialang.org/t/can-i-index-a-dataframe-using-a-string-key/90251)

<div class="topic-metadata">

**Author:** [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Replies:** 7\
**Last updated:** [November 15, 2022, 10:39am UTC](https://discourse.julialang.org/t/can-i-index-a-dataframe-using-a-string-key/90251 "2022-11-15T10:39:59Z")

</div>

Hi all! So I’m writing some code where I need to access some properties of some machine register. I want to store both the value the register it’s initializated to and its binary weight. Using a DataFrame and the count\_…

---

## [Edge case in Sets with Floats](https://discourse.julialang.org/t/edge-case-in-sets-with-floats/78787)

<div class="topic-metadata">

**Author:** [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Replies:** 6\
**Last updated:** [March 31, 2022, 12:25pm UTC](https://discourse.julialang.org/t/edge-case-in-sets-with-floats/78787 "2022-03-31T12:25:00Z")

</div>

Hi Julia Community, recently I was approached by a colleague who just got started with Julia and ran into a problem that took him ages to debug. We then seat down together and could come up with the following MWE: juli…

---

## [\`unique(Vector{CustomStruct})\` requires method for hash | Bug or misleading documentation?](https://discourse.julialang.org/t/unique-vector-customstruct-requires-method-for-hash-bug-or-misleading-documentation/77974)

<div class="topic-metadata">

**Author:** [@aaronpeikert](https://discourse.julialang.org/u/aaronpeikert)\
**Replies:** 6\
**Last updated:** [March 16, 2022, 5:02pm UTC](https://discourse.julialang.org/t/unique-vector-customstruct-requires-method-for-hash-bug-or-misleading-documentation/77974 "2022-03-16T17:02:02Z")

</div>

I was surprised to see that it is not enough to implement isequal to get unique for free, though the documentation seems to suggest it: https://docs.julialang.org/en/v1/base/collections/#Base.unique Return an array co…

---

## [Create a user-type set](https://discourse.julialang.org/t/create-a-user-type-set/75420)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 2\
**Last updated:** [January 29, 2022, 6:31pm UTC](https://discourse.julialang.org/t/create-a-user-type-set/75420 "2022-01-29T18:31:41Z")

</div>

hellow, how to create a user type set? # i do mutable struct UserType id::Int end Base.:(==)(a::UserType, b::UserType) = a.id == b.id set = Set((UserType(1), UserType(2),)) UserType(1) == UserType(1) # -\> true # bu…

---

## [Hash function for immutable struct containing mutable vectors](https://discourse.julialang.org/t/hash-function-for-immutable-struct-containing-mutable-vectors/68326)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 2\
**Last updated:** [September 17, 2021, 6:24pm UTC](https://discourse.julialang.org/t/hash-function-for-immutable-struct-containing-mutable-vectors/68326 "2021-09-17T18:24:45Z")

</div>

Suppose I have an immutable struct A containing immutable fields as well as a (mutable) vector of immutable objects (such as Int64 objects), struct A x::Int y::Vector{Int} end Does Julia automatically define se…

---

## [Fast hash for custom type](https://discourse.julialang.org/t/fast-hash-for-custom-type/68135)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 10\
**Last updated:** [September 17, 2021, 12:45pm UTC](https://discourse.julialang.org/t/fast-hash-for-custom-type/68135 "2021-09-17T12:45:34Z")

</div>

We have a custom type and we are not satisfied with the Base.hash performance. See here for the real world example. What are the best practice for defining a custom hash? This is what we did: julia\> struct S{T}; value…

---

## [Hashing for big structs is slow - any alternative?](https://discourse.julialang.org/t/hashing-for-big-structs-is-slow-any-alternative/53815)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 12\
**Last updated:** [January 25, 2021, 7:36pm UTC](https://discourse.julialang.org/t/hashing-for-big-structs-is-slow-any-alternative/53815 "2021-01-25T19:36:06Z")

</div>

I have three structs, one mutable and two immutable, defined as: mutable struct Node label::NodeEdge comp::Vector{UInt8} comp\_weights::Vector{UInt8} cc::UInt8 fps::Vector{F…
