-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Go doesn’t have a native set type. That means developers have to use either an array type or a map type. In both cases, there is high potential for a developer to make a backwards-incompatible change (in terms of hashing).
In the array case, the order of the array is significant for the hashing algorithm. However, for a developer to deduplicate the array, they would most likely use an intermediate map. The problem is Go forces the order of the map to be non-deterministic, so the order of the final array and thus the hash becomes non-deterministic. In this case, we should sort the array before hashing to ensure determinism.
In the map case, the values of the map are insignificant. We should ignore them to prevent the developer breaking the determinism of the hash by using a different map value.
I propose introducing a new struct tag called set that is a Boolean true or false. If true, the library will deduplicate and sort the set values. It would support arrays and maps.