AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
HashCodes.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 namespace HoloToolkit.Unity
5 {
10  public static class HashCodes
11  {
12  public static int Combine(int first, int second)
13  {
14  // This algorithm is based on .Net 4.6.1's implementation of Tuple.
15  return (((first << 5) + first) ^ second);
16  }
17 
18  // NOTE: The following are generic to avoid boxing structs:
19 
20  public static int FromNullable<T1>(T1 toHash)
21  {
22  return (toHash == null)
23  ? 0
24  : toHash.GetHashCode();
25  }
26 
27  public static int Combine<T1, T2>(T1 first, T2 second)
28  {
29  return Combine(FromNullable(first), FromNullable(second));
30  }
31 
32  public static int Combine<T1, T2, T3>(T1 first, T2 second, T3 third)
33  {
34  return Combine(Combine(first, second), FromNullable(third));
35  }
36 
37  public static int Combine<T1, T2, T3, T4>(T1 first, T2 second, T3 third, T4 fourth)
38  {
39  return Combine(Combine(first, second, third), FromNullable(fourth));
40  }
41 
42  public static int Combine<T1, T2, T3, T4, T5>(T1 first, T2 second, T3 third, T4 fourth, T5 fifth)
43  {
44  return Combine(Combine(first, second, third, fourth), FromNullable(fifth));
45  }
46 
47  public static int Combine<T1, T2, T3, T4, T5, T6>(T1 first, T2 second, T3 third, T4 fourth, T5 fifth, T6 sixth)
48  {
49  return Combine(Combine(first, second, third, fourth, fifth), FromNullable(sixth));
50  }
51 
52  public static int Combine<T1, T2, T3, T4, T5, T6, T7>(T1 first, T2 second, T3 third, T4 fourth, T5 fifth, T6 sixth, T7 seventh)
53  {
54  return Combine(Combine(first, second, third, fourth, fifth, sixth), FromNullable(seventh));
55  }
56 
57  public static int Combine<T1, T2, T3, T4, T5, T6, T7, T8>(T1 first, T2 second, T3 third, T4 fourth, T5 fifth, T6 sixth, T7 seventh, T8 eighth)
58  {
59  return Combine(Combine(first, second, third, fourth, fifth, sixth, seventh), FromNullable(eighth));
60  }
61  }
62 }
static int Combine(int first, int second)
Definition: HashCodes.cs:12
Provides helper methods for combining hash codes of many properties or objects into an aggregated has...
Definition: HashCodes.cs:10