wasSharp – Diff between revs 22 and 23

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 22 Rev 23
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 -  
33 { -  
34 get -  
35 { -  
36 return from baseDict in base.Values -  
37 from baseKey in baseDict.Keys 32 public new IEnumerable<V> Values =>
38 select baseDict[baseKey]; -  
39 } -  
40 } 33 base.Values.SelectMany(baseDict => baseDict.Keys, (baseDict, baseKey) => baseDict[baseKey]);
41   34  
42 public void Add(K1 key1, K2 key2, V value) 35 public void Add(K1 key1, K2 key2, V value)
43 { 36 {
44 if (!ContainsKey(key1)) 37 if (!ContainsKey(key1))
45 this[key1] = new Dictionary<K2, V>(); 38 this[key1] = new Dictionary<K2, V>();
46 this[key1][key2] = value; 39 this[key1][key2] = value;
47 } 40 }
-   41  
-   42 public void Remove(K1 key1, K2 key2)
-   43 {
-   44 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
-   45 return;
-   46 this[key1].Remove(key2);
-   47 Remove(key1);
-   48 }
48   49  
49 public bool ContainsKey(K1 key1, K2 key2) 50 public bool ContainsKey(K1 key1, K2 key2)
50 { 51 {
-   52 return ContainsKey(key1) && this[key1].ContainsKey(key2);
-   53 }
-   54  
-   55 public bool TryGetValue(K1 key1, K2 key2, out V value)
-   56 {
-   57 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2))
-   58 {
-   59 value = default(V);
-   60 return false;
-   61 }
-   62 value = base[key1][key2];
51 return base.ContainsKey(key1) && this[key1].ContainsKey(key2); 63 return true;
52 } 64 }
53 } 65 }
54   66  
55 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>>
56 { 68 {
57 public V this[K1 key1, K2 key2, K3 key3] 69 public V this[K1 key1, K2 key2, K3 key3]
58 { 70 {
59 get { return ContainsKey(key1) ? this[key1][key2, key3] : default(V); } 71 get { return ContainsKey(key1) ? this[key1][key2, key3] : default(V); }
60 set 72 set
61 { 73 {
62 if (!ContainsKey(key1)) 74 if (!ContainsKey(key1))
63 this[key1] = new MultiKeyDictionary<K2, K3, V>(); 75 this[key1] = new MultiKeyDictionary<K2, K3, V>();
64 this[key1][key2, key3] = value; 76 this[key1][key2, key3] = value;
65 } 77 }
66 } 78 }
67   79  
68 public bool ContainsKey(K1 key1, K2 key2, K3 key3) 80 public bool ContainsKey(K1 key1, K2 key2, K3 key3)
69 { 81 {
70 return base.ContainsKey(key1) && this[key1].ContainsKey(key2, key3); 82 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3);
-   83 }
-   84  
-   85 public void Add(K1 key1, K2 key2, K3 key3, V value)
-   86 {
-   87 if (!ContainsKey(key1))
-   88 this[key1] = new MultiKeyDictionary<K2, K3, V>();
-   89 this[key1][key2, key3] = value;
-   90 }
-   91  
-   92 public void Remove(K1 key1, K2 key2, K3 key3)
-   93 {
-   94 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
-   95 return;
-   96 this[key1][key2].Remove(key3);
-   97 this[key1].Remove(key2);
-   98 Remove(key1);
-   99 }
-   100  
-   101 public bool TryGetValue(K1 key1, K2 key2, K3 key3, out V value)
-   102 {
-   103 if (!ContainsKey(key1) || !this[key1].ContainsKey(key2, key3))
-   104 {
-   105 value = default(V);
-   106 return false;
-   107 }
-   108 value = base[key1][key2, key3];
-   109 return true;
71 } 110 }
72 } 111 }
73   112  
74 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>>
75 { 114 {
76 public V this[K1 key1, K2 key2, K3 key3, K4 key4] 115 public V this[K1 key1, K2 key2, K3 key3, K4 key4]
77 { 116 {
78 get { return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); } 117 get { return ContainsKey(key1) ? this[key1][key2, key3, key4] : default(V); }
79 set 118 set
80 { 119 {
81 if (!ContainsKey(key1)) 120 if (!ContainsKey(key1))
82 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>(); 121 this[key1] = new MultiKeyDictionary<K2, K3, K4, V>();
83 this[key1][key2, key3, key4] = value; 122 this[key1][key2, key3, key4] = value;
84 } 123 }
85 } 124 }
86   125  
87 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4) 126 public bool ContainsKey(K1 key1, K2 key2, K3 key3, K4 key4)
88 { 127 {
89 return base.ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4); 128 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4);
90 } 129 }
91 } 130 }
92   131  
93 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>>
94 { 133 {
95 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]
96 { 135 {
97 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); }
98 set 137 set
99 { 138 {
100 if (!ContainsKey(key1)) 139 if (!ContainsKey(key1))
101 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>(); 140 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, V>();
102 this[key1][key2, key3, key4, key5] = value; 141 this[key1][key2, key3, key4, key5] = value;
103 } 142 }
104 } 143 }
105   144  
106 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)
107 { 146 {
108 return base.ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5); 147 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5);
109 } 148 }
110 } 149 }
111   150  
112 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> : 151 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, V> :
113 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>> 152 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, V>>
114 { 153 {
115 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]
116 { 155 {
117 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); }
118 set 157 set
119 { 158 {
120 if (!ContainsKey(key1)) 159 if (!ContainsKey(key1))
121 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>(); 160 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, V>();
122 this[key1][key2, key3, key4, key5, key6] = value; 161 this[key1][key2, key3, key4, key5, key6] = value;
123 } 162 }
124 } 163 }
125   164  
126 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)
127 { 166 {
128 return base.ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6); 167 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6);
129 } 168 }
130 } 169 }
131   170  
132 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> : 171 public class MultiKeyDictionary<K1, K2, K3, K4, K5, K6, K7, V> :
133 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>> 172 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>>
134 { 173 {
135 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]
136 { 175 {
137 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); }
138 set 177 set
139 { 178 {
140 if (!ContainsKey(key1)) 179 if (!ContainsKey(key1))
141 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>(); 180 this[key1] = new MultiKeyDictionary<K2, K3, K4, K5, K6, K7, V>();
142 this[key1][key2, key3, key4, key5, key6, key7] = value; 181 this[key1][key2, key3, key4, key5, key6, key7] = value;
143 } 182 }
144 } 183 }
145   184  
146 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)
147 { 186 {
148 return base.ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7); 187 return ContainsKey(key1) && this[key1].ContainsKey(key2, key3, key4, key5, key6, key7);
149 } 188 }
150 } 189 }
151   190  
152 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> :
153 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>> 192 Dictionary<K1, MultiKeyDictionary<K2, K3, K4, K5, K6, K7, K8, V>>
154 { 193 {
155 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]
156 { 195 {
157 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); }
158 set 197 set
159 { 198 {
160 if (!ContainsKey(key1)) 199 if (!ContainsKey(key1))
161 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>();
162 this[key1][key2, key3, key4, key5, key6, key7, key8] = value; 201 this[key1][key2, key3, key4, key5, key6, key7, key8] = value;
163 } 202 }
164 } 203 }
165   204  
166 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)
167 { 206 {
168 return base.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);
169 } 208 }
170 } 209 }
171   210  
172 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> :
173 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>>
174 { 213 {
175 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]
176 { 215 {
177 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); }
178 set 217 set
179 { 218 {
180 if (!ContainsKey(key1)) 219 if (!ContainsKey(key1))
181 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>();
182 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value; 221 this[key1][key2, key3, key4, key5, key6, key7, key8, key9] = value;
183 } 222 }
184 } 223 }
185   224  
186 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)
187 { 226 {
188 return base.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);
189 } 228 }
190 } 229 }
191   230  
192 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> :
193 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>>
194 { 233 {
195 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]
196 { 235 {
197 get 236 get
198 { 237 {
199 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);
200 } 239 }
201 set 240 set
202 { 241 {
203 if (!ContainsKey(key1)) 242 if (!ContainsKey(key1))
204 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>();
205 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;
206 } 245 }
207 } 246 }
208   247  
209 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,
210 K10 key10) 249 K10 key10)
211 { 250 {
212 return base.ContainsKey(key1) && 251 return ContainsKey(key1) &&
213 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);
214 } 253 }
215 } 254 }
216   255  
217 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> :
218 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>>
219 { 258 {
220 public V this[ 259 public V this[
221 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]
222 { 261 {
223 get 262 get
224 { 263 {
225 return ContainsKey(key1) 264 return ContainsKey(key1)
226 ? 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]
227 : default(V); 266 : default(V);
228 } 267 }
229 set 268 set
230 { 269 {
231 if (!ContainsKey(key1)) 270 if (!ContainsKey(key1))
232 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>();
233 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;
234 } 273 }
235 } 274 }
236   275  
237 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,
238 K10 key10, K11 key11) 277 K10 key10, K11 key11)
239 { 278 {
240 return base.ContainsKey(key1) && 279 return ContainsKey(key1) &&
241 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);
242 } 281 }
243 } 282 }
244 } 283 }
245   284  
246
Generated by GNU Enscript 1.6.5.90.
285
Generated by GNU Enscript 1.6.5.90.
247   286  
248   287  
249   288