IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
HashCodeExtensions.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Collections.Immutable;
4using System.Linq;
5
7{
8
9 internal static class HashCodeExtensions
10 {
11
18 public static void AddRange<T>(this ref HashCode self, IEnumerable<T>? items)
19 {
20 if (items is null)
21 {
22 self.Add(0);
23 }
24 else
25 {
26 self.Add(1);
27 foreach (var i in items)
28 self.Add(i);
29 }
30 }
31
38 public static void AddRange<T>(this ref HashCode self, T[]? items)
39 {
40 if (items is null)
41 {
42 self.Add(0);
43 }
44 else
45 {
46 self.Add(1);
47 foreach (var i in items)
48 self.Add(i);
49 }
50 }
51
58 public static void AddRange<T>(this ref HashCode self, ImmutableArray<T> items)
59 {
60 if (items.IsDefault)
61 {
62 self.Add(0);
63 }
64 else
65 {
66 self.Add(1);
67 foreach (var i in items)
68 self.Add(i);
69 }
70 }
71
79 public static void AddRange<T>(this ref HashCode self, ImmutableHashSet<T> items, IComparer<T> comparer)
80 {
81 if (comparer is null)
82 throw new ArgumentNullException(nameof(comparer));
83
84 if (items is null)
85 {
86 self.Add(0);
87 }
88 else
89 {
90 var l = items.ToArray();
91 Array.Sort(l, comparer);
92
93 self.Add(1);
94 foreach (var i in items)
95 self.Add(i);
96 }
97 }
98
105 public static void AddRange<T>(this ref HashCode self, ImmutableHashSet<T> items)
106 {
107 AddRange(ref self, items, Comparer<T>.Default);
108 }
109
117 public static void AddRange<T>(this ref HashCode self, ISet<T> items, IComparer<T> comparer)
118 {
119 if (comparer is null)
120 throw new ArgumentNullException(nameof(comparer));
121
122 if (items is null)
123 {
124 self.Add(0);
125 }
126 else
127 {
128 var l = items.ToArray();
129 Array.Sort(l, comparer);
130
131 self.Add(1);
132 foreach (var i in items)
133 self.Add(i);
134 }
135 }
136
143 public static void AddRange<T>(this ref HashCode self, ISet<T> items)
144 {
145 AddRange(ref self, items, Comparer<T>.Default);
146 }
147
148 }
149
150}