wasSharp – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
23 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System.Collections.Generic; |
||
8 | |||
9 | namespace wasSharp |
||
10 | { |
||
11 | public struct NetHash |
||
12 | { |
||
13 | private readonly int hashCode; |
||
14 | |||
15 | public NetHash(int hashCode = 17) |
||
16 | { |
||
17 | this.hashCode = hashCode; |
||
18 | } |
||
19 | |||
20 | public static NetHash Init => new NetHash(); |
||
21 | |||
22 | public static implicit operator int(NetHash hashCode) |
||
23 | { |
||
24 | return hashCode.GetHashCode(); |
||
25 | } |
||
26 | |||
27 | public NetHash Hash<T>(T obj) |
||
28 | { |
||
29 | var c = EqualityComparer<T>.Default; |
||
30 | var h = c.Equals(obj, default(T)) ? 0 : obj.GetHashCode(); |
||
31 | unchecked |
||
32 | { |
||
33 | h += hashCode*31; |
||
34 | } |
||
35 | return new NetHash(h); |
||
36 | } |
||
37 | |||
38 | public override int GetHashCode() |
||
39 | { |
||
40 | return hashCode; |
||
41 | } |
||
42 | } |
||
43 | } |