Update Changelog
[profile/ivi/libgee.git] / gee / hashmultimap.vala
1 /* hashmultimap.vala
2  *
3  * Copyright (C) 2009  Ali Sabil
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Author:
20  *      Ali Sabil <ali.sabil@gmail.com>
21  */
22
23 /**
24  * Hash table implementation of the {@link MultiMap} interface.
25  */
26 public class Gee.HashMultiMap<K,V> : AbstractMultiMap<K,V> {
27         public HashDataFunc<K> key_hash_func {
28                 get { return ((HashMap<K, Set<V>>) _storage_map).key_hash_func; }
29         }
30
31         public EqualDataFunc<K> key_equal_func {
32                 get { return ((HashMap<K, Set<V>>) _storage_map).key_equal_func; }
33         }
34
35         [CCode (notify = false)]
36         public HashDataFunc<V> value_hash_func { private set; get; }
37
38         [CCode (notify = false)]
39         public EqualDataFunc<V> value_equal_func { private set; get; }
40
41         /**
42          * Constructs a new, empty hash multimap.
43          *
44          * If not provided, the functions parameters are requested to the
45          * {@link Functions} function factory methods.
46          *
47          * @param key_hash_func an optional key hash function
48          * @param key_equal_func an optional key equality testing function
49          * @param value_hash_func an optional value hash function
50          * @param value_equal_func an optional value equality testing function
51          */
52         public HashMultiMap (owned HashDataFunc<K>? key_hash_func = null, owned EqualDataFunc<K>? key_equal_func = null,
53                              owned HashDataFunc<V>? value_hash_func = null, owned EqualDataFunc<V>? value_equal_func = null) {
54                 base (new HashMap<K, Set<V>> (key_hash_func, key_equal_func, Functions.get_equal_func_for (typeof (Set))));
55                 if (value_hash_func == null) {
56                         value_hash_func = Functions.get_hash_func_for (typeof (V));
57                 }
58                 if (value_equal_func == null) {
59                         value_equal_func = Functions.get_equal_func_for (typeof (V));
60                 }
61                 this.value_hash_func = value_hash_func;
62                 this.value_equal_func = value_equal_func;
63         }
64
65         protected override Collection<V> create_value_storage () {
66                 return new HashSet<V> (_value_hash_func, _value_equal_func);
67         }
68
69         protected override MultiSet<K> create_multi_key_set () {
70                 return new HashMultiSet<K> (key_hash_func, key_equal_func);
71         }
72
73         protected override EqualDataFunc get_value_equal_func () {
74                 return _value_equal_func;
75         }
76 }