namespace Cobra.Core class HashCodeUtils """ Provides convenient .combine methods for combining hash codes. The default implementation here is good enough for many applications, but if your application is heavily affected by hash codes then you will want to do your own hash code study and choose your own algorithm. to-do: should this be switched to the "Jenkins One at a time hash"? see: http://stackoverflow.com/questions/1079192/is-it-possible-to-combine-hash-codes-for-private-members-to-generate-a-new-hash """ test assert .combine(3, 4) == .combine(3, 4) assert .combine(3, 4) <> .combine(4, 3) assert .combine(6, 7) <> .combine(8, 9) shared pro defaultStart from var = 37 pro defaultFactor from var = 23 def combine(hashCodes as vari int) as int """ Accepts variable number of args such as: HashCodeUtils.combine(a.getHashCode, b.getHashCode, c.hashCode) """ return .combine(hashCodes, _defaultStart, _defaultFactor) def combine(hashCodes as int*) as int """ Accepts a stream of hash codes (int*, lists, arrays, IEnumerable, Iterable, etc.). """ return .combine(hashCodes, _defaultStart, _defaultFactor) def combine(hashCodes as int*, start as int, factor as int) as int hash = start for code in hashCodes hash = hash * factor + code return hash