@@ -6,9 +6,20 @@ export setproperties
66export constructorof
77
88
9- import Base: get
9+ import Base: get, hash, ==
1010using Base: getproperty
1111
12+
13+ # used for hashing
14+ function make_salt (s64:: UInt64 ):: UInt
15+ if UInt === UInt64
16+ return s64
17+ else
18+ return UInt32 (s64 >> 32 ) ^ UInt32 (s64 & 0x00000000ffffffff )
19+ end
20+ end
21+
22+
1223"""
1324 Lens
1425
@@ -99,6 +110,7 @@ struct IdentityLens <: Lens end
99110get (obj, :: IdentityLens ) = obj
100111set (obj, :: IdentityLens , val) = val
101112
113+
102114struct PropertyLens{fieldname} <: Lens end
103115
104116function get (obj, l:: PropertyLens{field} ) where {field}
@@ -115,6 +127,13 @@ struct ComposedLens{LO, LI} <: Lens
115127 inner:: LI
116128end
117129
130+ function == (l1:: ComposedLens{LO, LI} , l2:: ComposedLens{LO, LI} ) where {LO, LI}
131+ return l1. outer == l2. outer && l1. inner == l2. inner
132+ end
133+
134+ const SALT_COMPOSEDLENS = make_salt (0xcf7322dcc2129a31 )
135+ hash (l:: ComposedLens , h:: UInt ) = hash (l. outer, hash (l. inner, SALT_INDEXLENS + h))
136+
118137"""
119138 compose([lens₁, [lens₂, [lens₃, ...]]])
120139
@@ -174,6 +193,11 @@ struct IndexLens{I <: Tuple} <: Lens
174193 indices:: I
175194end
176195
196+ == (l1:: IndexLens{I} , l2:: IndexLens{I} ) where {I} = l1. indices == l2. indices
197+
198+ const SALT_INDEXLENS = make_salt (0x8b4fd6f97c6aeed6 )
199+ hash (l:: IndexLens , h:: UInt ) = hash (l. indices, SALT_INDEXLENS + h)
200+
177201Base. @propagate_inbounds function get (obj, l:: IndexLens )
178202 getindex (obj, l. indices... )
179203end
0 commit comments