Skip to content

Support set-like array/map fields #14

@fumoboy007

Description

@fumoboy007

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions