wasSharp – Diff between revs 23 and 27

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 23 Rev 27
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6 // Based on the work of Herman Schoenfeld 6 // Based on the work of Herman Schoenfeld
7   7  
8 using System; 8 using System;
9 using System.Collections.Generic; 9 using System.Collections.Generic;
10 using System.Linq; 10 using System.Linq;
11   11  
12 namespace wasSharp.Collections.Specialized 12 namespace wasSharp.Collections.Specialized
13 { 13 {
14 public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>> 14 public class MultiKeyDictionary<K1, K2, V> : Dictionary<K1, Dictionary<K2, V>>
15 { 15 {
16 public V this[K1 key1, K2 key2] 16 public V this[K1 key1, K2 key2]
17 { 17 {
18 get 18 get
19 { 19 {
20 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 20 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
21 throw new ArgumentOutOfRangeException(); 21 throw new ArgumentOutOfRangeException();
22 return base[key1][key2]; 22 return base[key1][key2];
23 } 23 }
24 set 24 set
25 { 25 {
26 if (!ContainsKey(key1)) 26 if (!ContainsKey(key1))
27 this[key1] = new Dictionary<K2, V>(); 27 this[key1] = new Dictionary<K2, V>();
28 this[key1][key2] = value; 28 this[key1][key2] = value;
29 } 29 }
30 } 30 }
31   31  
32 public new IEnumerable<V> Values => 32 public new IEnumerable<V> Values =>
33 base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]); 33 base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]);
34   34  
35 public void Add(K1 key1, K2 key2, V value) 35 public void Add(K1 key1, K2 key2, V value)
36 { 36 {
37 if (!ContainsKey(key1)) 37 if (!ContainsKey(key1))
38 this[key1] = new Dictionary<K2, V>(); 38 this[key1] = new Dictionary<K2, V>();
39 this[key1][key2] = value; 39 this[key1][key2] = value;
40 } 40 }
41   41  
42 public void Remove(K1 key1, K2 key2) 42 public void Remove(K1 key1, K2 key2)
43 { 43 {
44 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 44 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
45 return; 45 return;
46 this[key1].Remove(key2); 46 this[key1].Remove(key2);
47 Remove(key1); 47 Remove(key1);
48 } 48 }
49   49  
50 public bool ContainsKey(K1 key1, K2 key2) 50 public bool ContainsKey(K1 key1, K2 key2)
51 { 51 {
52 return ContainsKey(key1) && this[key1].ContainsKey(key2); 52 return ContainsKey(key1) && this[key1].ContainsKey(key2);
53 } 53 }
54   54  
55 public bool TryGetValue(K1 key1, K2 key2, out V value) 55 public bool TryGetValue(K1 key1, K2 key2, out V value)
56 { 56 {
57 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2)) 57 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
58 { 58 {
59 value = default(V); 59 value = default(V);
60 return false; 60 return false;
61 } 61 }
62 value = base[key1][key2]; 62 value = base[key1][key2];
63 return true; 63 return true;
64 } 64 }
65 } 65 }
66   66  
67 public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>> 67 public class MultiKeyDictionary<K1, K2, K3, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, V>>
68 { 68 {
69 public V this[K1 key1, K2 key2, K3 key3] 69 public V this[K1 key1, K2 key2, K3 key3]
70 { 70 {
71 get { return ContainsKey(key1) ? this[key1][key2, key3] : default(V); } 71 get { return ContainsKey(key1) ? this[key1][key2, key3] : default(V); }
72 set 72 set
73 { 73 {
74 if (!ContainsKey(key1)) 74 if (!ContainsKey(key1))
75 this[key1] = new MultiKeyDictionary<K2, K3, V>(); 75 this[key1] = new MultiKeyDictionary<K2, K3, V>();
76 this[key1][key2, key3] = value; 76 this[key1][key2, key3] = value;
77 } 77 }
78 } 78 }
79   79  
80 public bool ContainsKey(K1 key1, K2 key2, K3 key3) 80 public bool ContainsKey(K1 key1, K2 key2, K3 key3)
81 { 81 {
82 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3); 82 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3);
83 } 83 }
84   84  
85 public void Add(K1 key1, K2 key2, K3 key3, V value) 85 public void Add(K1 key1, K2 key2, K3 key3, V value)
86 { 86 {
87 if (!ContainsKey(key1)) 87 if (!ContainsKey(key1))
88 this[key1] = new MultiKeyDictionary<K2, K3, V>(); 88 this[key1] = new MultiKeyDictionary<K2, K3, V>();
89 this[key1][key2, key3] = value; 89 this[key1][key2, key3] = value;
90 } 90 }
91   91  
92 public void Remove(K1 key1, K2 key2, K3 key3) 92 public void Remove(K1 key1, K2 key2, K3 key3)
93 { 93 {
94 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) 94 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
95 return; 95 return;
96 this[key1][key2].Remove(key3); 96 this[key1][key2].Remove(key3);
97 this[key1].Remove(key2); 97 this[key1].Remove(key2);
98 Remove(key1); 98 Remove(key1);
99 } 99 }
100   100  
101 public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value) 101 public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value)
102 { 102 {
103 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3)) 103 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
104 { 104 {
105 value = default(V); 105 value = default(V);
106 return false; 106 return false;
107 } 107 }
108 value = base[key1][key2, key3]; 108 value = base[key1][key2, key3];
109 return true; 109 return true;
110 } 110 }
111 } 111 }
112   112  
113 public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>> 113 public class MultiKeyDictionary<K1, K2, K3, K4, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, V>>
114 { 114 {
115 public V this[K1 key1, K2 key2, K3 key3, K4 key4] 115 public V this[K1 key1, K2 key2, K3 key3, K4 key4]
116 { 116 {
117 get { return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); } 117 get { return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); }
118 set 118 set
119 { 119 {
120 if (!ContainsKey(key1)) 120 if (!ContainsKey(key1))
121 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); 121 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>();
122 this[key1][key2, key3, key4] = value; 122 this[key1][key2, key3, key4] = value;
123 } 123 }
124 } 124 }
125   125  
126 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) 126 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4)
127 { 127 {
128 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); 128 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4);
129 } 129 }
130 } 130 }
131   131  
132 public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>> 132 public class MultiKeyDictionary<K1, K2, K3, K4, K5, V> : Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, V>>
133 { 133 {
134 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5] 134 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5]
135 { 135 {
136 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); } 136 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5] : default(V); }
137 set 137 set
138 { 138 {
139 if (!ContainsKey(key1)) 139 if (!ContainsKey(key1))
140 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); 140 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>();
141 this[key1][key2, key3, key4, key5] = value; 141 this[key1][key2, key3, key4, key5] = value;
142 } 142 }
143 } 143 }
144   144  
145 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5) 145 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5)
146 { 146 {
147 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); 147 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5);
148 } 148 }
149 } 149 }
150   150  
151 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : 151 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> :
152 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> 152 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>>
153 { 153 {
154 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6] 154 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6]
155 { 155 {
156 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); } 156 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6] : default(V); }
157 set 157 set
158 { 158 {
159 if (!ContainsKey(key1)) 159 if (!ContainsKey(key1))
160 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); 160 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>();
161 this[key1][key2, key3, key4, key5, key6] = value; 161 this[key1][key2, key3, key4, key5, key6] = value;
162 } 162 }
163 } 163 }
164   164  
165 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6) 165 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6)
166 { 166 {
167 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); 167 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6);
168 } 168 }
169 } 169 }
170   170  
171 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : 171 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> :
172 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> 172 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>>
173 { 173 {
174 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7] 174 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7]
175 { 175 {
176 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); } 176 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7] : default(V); }
177 set 177 set
178 { 178 {
179 if (!ContainsKey(key1)) 179 if (!ContainsKey(key1))
180 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); 180 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>();
181 this[key1][key2, key3, key4, key5, key6, key7] = value; 181 this[key1][key2, key3, key4, key5, key6, key7] = value;
182 } 182 }
183 } 183 }
184   184  
185 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7) 185 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7)
186 { 186 {
187 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); 187 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7);
188 } 188 }
189 } 189 }
190   190  
191 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> : 191 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, V> :
192 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> 192 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>>
193 { 193 {
194 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8] 194 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8]
195 { 195 {
196 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); } 196 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8] : default(V); }
197 set 197 set
198 { 198 {
199 if (!ContainsKey(key1)) 199 if (!ContainsKey(key1))
200 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>(); 200 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>();
201 this[key1][key2, key3, key4, key5, key6, key7, key8] = value; 201 this[key1][key2, key3, key4, key5, key6, key7, key8] = value;
202 } 202 }
203 } 203 }
204   204  
205 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8) 205 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8)
206 { 206 {
207 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8); 207 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8);
208 } 208 }
209 } 209 }
210   210  
211 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> : 211 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, V> :
212 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>> 212 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>>
213 { 213 {
214 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9] 214 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9]
215 { 215 {
216 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); } 216 get { return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9] : default(V); }
217 set 217 set
218 { 218 {
219 if (!ContainsKey(key1)) 219 if (!ContainsKey(key1))
220 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>(); 220 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, V>();
221 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; 221 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value;
222 } 222 }
223 } 223 }
224   224  
225 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9) 225 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9)
226 { 226 {
227 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9); 227 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9);
228 } 228 }
229 } 229 }
230   230  
231 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> : 231 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, V> :
232 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>> 232 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>>
233 { 233 {
234 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10] 234 public V this[K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10]
235 { 235 {
236 get 236 get
237 { 237 {
238 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] : default(V); 238 return ContainsKey(key1) ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] : default(V);
239 } 239 }
240 set 240 set
241 { 241 {
242 if (!ContainsKey(key1)) 242 if (!ContainsKey(key1))
243 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>(); 243 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, V>();
244 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value; 244 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10] = value;
245 } 245 }
246 } 246 }
247   247  
248 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, 248 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9,
249 K10 key10) 249 K10 key10)
250 { 250 {
251 return ContainsKey(key1) && 251 return ContainsKey(key1) &&
252 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10); 252 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10);
253 } 253 }
254 } 254 }
255   255  
256 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> : 256 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V> :
257 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>> 257 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>>
258 { 258 {
259 public V this[ 259 public V this[
260 K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11] 260 K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, K10 key10, K11 key11]
261 { 261 {
262 get 262 get
263 { 263 {
264 return ContainsKey(key1) 264 return ContainsKey(key1)
265 ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] 265 ? this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11]
266 : default(V); 266 : default(V);
267 } 267 }
268 set 268 set
269 { 269 {
270 if (!ContainsKey(key1)) 270 if (!ContainsKey(key1))
271 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>(); 271 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, V>();
272 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value; 272 this[key1][key2, key3, key4, key5, key6, key7, key8, key9, key10, key11] = value;
273 } 273 }
274 } 274 }
275   275  
276 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9, 276 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4, K5 key5, K6 key6, K7 key7, K8 key8, K9 key9,
277 K10 key10, K11 key11) 277 K10 key10, K11 key11)
278 { 278 {
279 return ContainsKey(key1) && 279 return ContainsKey(key1) &&
280 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11); 280 this[key1].ContainsKey(key2, key3, key4, key5, key6, key7, key8, key9, key10, key11);
281 } 281 }
282 } 282 }
283 } -  
284   283 }
-   284  
285
Generated by GNU Enscript 1.6.5.90.
-  
286   -  
287   -  
288   -