JuliaServices / AutoHashEquals.jl

A Julia macro to add == and hash() to composite types.
Other
57 stars 12 forks source link

Permit `@auto_hash_equals cached=true` with mutable struct types. #34

Open gafter opened 1 year ago

gafter commented 1 year ago

Either

  1. Require that all declared fields are const, or
  2. Add const to each declared field (with a warning?) if not already declared so.

The advantage of doing this is that we get both an efficient hash code and an efficient equality (because of the === shortcut)

const on a field is only available in Julia 1.8 and later.

NHDaly commented 1 year ago

(The disadvantage is that every field access has to go to the heap. With an immutable struct, fields can be pulled onto the stack or into registers, which can improve the performance of a function that spends a lot of time with those fields. If you're just hopping off to the next child in a tree or something, this probably matters less.)