Update Changelog
[profile/ivi/libgee.git] / gee / treemultimap.vala
1 /* treemultimap.vala
2  *
3  * Copyright (C) 2009  Didier Villevalois
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  *      Didier 'Ptitjes Villevalois <ptitjes@free.fr>
21  */
22
23 /**
24  * Left-leaning red-black tree implementation of the {@link MultiMap}
25  * interface.
26  */
27 public class Gee.TreeMultiMap<K,V> : AbstractMultiMap<K,V> {
28         public CompareDataFunc<K> key_compare_func {
29                 get { return ((TreeMap<K, Set<V>>) _storage_map).key_compare_func; }
30         }
31
32         [CCode (notify = false)]
33         public CompareDataFunc<V> value_compare_func { private set; get; }
34
35         /**
36          * Constructs a new, empty tree multimap.
37          *
38          * If not provided, the functions parameters are requested to the
39          * {@link Functions} function factory methods.
40          *
41          * @param key_compare_func an optional key comparator function
42          * @param value_compare_func an optional value comparator function
43          */
44         public TreeMultiMap (owned CompareDataFunc<K>? key_compare_func = null, owned CompareDataFunc<V>? value_compare_func = null) {
45                 base (new TreeMap<K, Set<V>> (key_compare_func, Functions.get_equal_func_for (typeof (Set))));
46                 if (value_compare_func == null) {
47                         value_compare_func = Functions.get_compare_func_for (typeof (V));
48                 }
49                 this.value_compare_func = value_compare_func;
50         }
51
52         protected override Collection<V> create_value_storage () {
53                 return new TreeSet<V> (_value_compare_func);
54         }
55
56         protected override MultiSet<K> create_multi_key_set () {
57                 return new TreeMultiSet<K> (key_compare_func);
58         }
59
60         protected override EqualDataFunc<V> get_value_equal_func () {
61                 return Functions.get_equal_func_for (typeof (V));
62         }
63 }