Q:

performance considerations of hashValue in swift protocol Hashable

Besides being a unique integer are there any performance considerations for the selection of a hashValue in a swift Hashable Type that may be inserted into a Set? For instance will the size of the integer values I choose affect the size of the backing array? i.e. if I assign a hashValue of 4000 to a Hashable type and insert that into a Set will the backing array need to be at least 4000 in length?

A:

hashValue does not have to be a unique. In the vast majority of cases it can't be unique (any type that is larger than 64-bits will necessarily have more possible states than its hash). You don't choose the size of the integer. It will always be Int (which is the machine word size).
hashValue should be fast, however, and ideally O(1). It is often used to help optimize equality checking (which may be very slow).
The simplest implementation of hashValue is:
var hashValue: Int { return 1 }

This is a perfectly valid hash. It's not a particularly good hash, but it meets all the requirements. It is fast to calculate, and all equal objects will have equal hashes (which is a requirement; the converse is not required: equal hashes may not imply equal objects).

