3 * Copyright (C) 2009 Ali Sabil
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.
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.
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
20 * Ali Sabil <ali.sabil@gmail.com>
24 * Hash table implementation of the {@link MultiMap} interface.
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; }
31 public EqualDataFunc<K> key_equal_func {
32 get { return ((HashMap<K, Set<V>>) _storage_map).key_equal_func; }
35 [CCode (notify = false)]
36 public HashDataFunc<V> value_hash_func { private set; get; }
38 [CCode (notify = false)]
39 public EqualDataFunc<V> value_equal_func { private set; get; }
42 * Constructs a new, empty hash multimap.
44 * If not provided, the functions parameters are requested to the
45 * {@link Functions} function factory methods.
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
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));
58 if (value_equal_func == null) {
59 value_equal_func = Functions.get_equal_func_for (typeof (V));
61 this.value_hash_func = value_hash_func;
62 this.value_equal_func = value_equal_func;
65 protected override Collection<V> create_value_storage () {
66 return new HashSet<V> (_value_hash_func, _value_equal_func);
69 protected override MultiSet<K> create_multi_key_set () {
70 return new HashMultiSet<K> (key_hash_func, key_equal_func);
73 protected override EqualDataFunc get_value_equal_func () {
74 return _value_equal_func;