**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.C5 / hashing / HashDictionary.cs
blob325aee15cfbb11ce97ccda861542a58a495d1fba
1 #if NET_2_0
2 /*
3 Copyright (c) 2003-2004 Niels Kokholm <kokholm@itu.dk> and Peter Sestoft <sestoft@dina.kvl.dk>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
23 using System;
24 using System.Diagnostics;
25 using MSG = System.Collections.Generic;
27 namespace C5
29 /// <summary>
30 /// A generic dictionary class based on a hash set class <see cref="T:C5.HashSet!1"/>.
31 /// </summary>
32 public class HashDictionary<K,V>: DictionaryBase<K,V>, IDictionary<K,V>
34 /// <summary>
35 /// Create a hash dictionary using a default hasher for the keys.
36 /// Initial capacity of internal table will be 16 entries and threshold for
37 /// expansion is 66% fill.
38 /// </summary>
39 public HashDictionary()
41 pairs = new HashSet<KeyValuePair<K,V>>(new KeyValuePairHasher<K,V>());
44 /// <summary>
45 /// Create a hash dictionary using a custom hasher for the keys.
46 /// Initial capacity of internal table will be 16 entries and threshold for
47 /// expansion is 66% fill.
48 /// </summary>
49 /// <param name="h">The external key hasher</param>
50 public HashDictionary(IHasher<K> h)
52 pairs = new HashSet<KeyValuePair<K,V>>(new KeyValuePairHasher<K,V>(h));
56 /// <summary>
57 /// Create a hash dictionary using a custom hasher and prescribing the
58 /// initial size of the dictionary and a non-default threshold for internal table expansion.
59 /// </summary>
60 /// <param name="capacity">The initial capacity. Will be rounded upwards to nearest
61 /// power of 2, at least 16.</param>
62 /// <param name="fill">The expansion threshold. Must be between 10% and 90%.</param>
63 /// <param name="h">The external key hasher</param>
64 public HashDictionary(int capacity, double fill, IHasher<K> h)
66 KeyValuePairHasher<K,V> kvph = new KeyValuePairHasher<K,V>(h);
68 pairs = new HashSet<KeyValuePair<K,V>>(capacity, fill, kvph);
72 #endif