[libgee] Implement TreeMultiMap
- From: Didier Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Implement TreeMultiMap
- Date: Mon, 28 Sep 2009 14:35:13 +0000 (UTC)
commit 1eaef2b3d5f4329fd89ab951f5b54202ccadb3a9
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Mon Sep 28 13:57:52 2009 +0200
Implement TreeMultiMap
gee/Makefile.am | 1 +
gee/treemultimap.vala | 53 +++++++++++++++++++++++++++++++++++++++++++
tests/Makefile.am | 1 +
tests/testmain.vala | 1 +
tests/testtreemultimap.vala | 53 +++++++++++++++++++++++++++++++++++++++++++
5 files changed, 109 insertions(+), 0 deletions(-)
---
diff --git a/gee/Makefile.am b/gee/Makefile.am
index e6294f7..189bc1b 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -50,6 +50,7 @@ libgee_la_VALASOURCES = \
sortedset.vala \
timsort.vala \
treemap.vala \
+ treemultimap.vala \
treemultiset.vala \
treeset.vala \
$(NULL)
diff --git a/gee/treemultimap.vala b/gee/treemultimap.vala
new file mode 100644
index 0000000..f318a78
--- /dev/null
+++ b/gee/treemultimap.vala
@@ -0,0 +1,53 @@
+/* treemultimap.vala
+ *
+ * Copyright (C) 2009 Didier Villevalois
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Didier 'Ptitjes Villevalois <ptitjes free fr>
+ */
+
+/**
+ * Left-leaning red-black tree implementation of the { link MultiMap}
+ * interface.
+ */
+public class Gee.TreeMultiMap<K,V> : AbstractMultiMap<K,V> {
+ public CompareFunc key_compare_func {
+ get { return ((TreeMap<K, Set<V>>) _storage_map).key_compare_func; }
+ }
+
+ public CompareFunc value_compare_func { private set; get; }
+
+ public TreeMultiMap (CompareFunc? key_compare_func = null, CompareFunc? value_compare_func = null) {
+ base (new TreeMap<K, Set<V>> (key_compare_func, direct_equal));
+ if (value_compare_func == null) {
+ value_compare_func = Functions.get_compare_func_for (typeof (V));
+ }
+ this.value_compare_func = value_compare_func;
+ }
+
+ protected override Collection<V> create_value_storage () {
+ return new TreeSet<V> (_value_compare_func);
+ }
+
+ protected override MultiSet<K> create_multi_key_set () {
+ return new TreeMultiSet<K> (key_compare_func);
+ }
+
+ protected override EqualFunc get_value_equal_func () {
+ return Functions.get_equal_func_for (typeof (V));
+ }
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba30e77..343859a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ tests_VALASOURCES = \
testset.vala \
testsortedset.vala \
testtreemap.vala \
+ testtreemultimap.vala \
testtreemultiset.vala \
testtreeset.vala \
$(NULL)
diff --git a/tests/testmain.vala b/tests/testmain.vala
index 2d55446..ad6e992 100644
--- a/tests/testmain.vala
+++ b/tests/testmain.vala
@@ -38,6 +38,7 @@ void main (string[] args) {
TestSuite.get_root ().add_suite (new ReadOnlyMapTests ().get_suite ());
TestSuite.get_root ().add_suite (new ReadOnlySetTests ().get_suite ());
TestSuite.get_root ().add_suite (new TreeMapTests ().get_suite ());
+ TestSuite.get_root ().add_suite (new TreeMultiMapTests ().get_suite ());
TestSuite.get_root ().add_suite (new TreeMultiSetTests ().get_suite ());
TestSuite.get_root ().add_suite (new TreeSetTests ().get_suite ());
diff --git a/tests/testtreemultimap.vala b/tests/testtreemultimap.vala
new file mode 100644
index 0000000..34374a9
--- /dev/null
+++ b/tests/testtreemultimap.vala
@@ -0,0 +1,53 @@
+/* testtreemultimap.vala
+ *
+ * Copyright (C) 2008 Jürg Billeter
+ * Copyright (C) 2009 Didier Villevalois, Julien Peeters
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j bitron ch>
+ * Didier 'Ptitjes Villevalois <ptitjes free fr>
+ * Julien Peeters <contact julienpeeters fr>
+ */
+
+using Gee;
+
+public class TreeMultiMapTests : MultiMapTests {
+
+ public TreeMultiMapTests () {
+ base ("TreeMultiMap");
+ add_test ("[TreeMultiMap] selected functions", test_selected_functions);
+ }
+
+ public override void set_up () {
+ test_multi_map = new TreeMultiMap<string,string> ();
+ }
+
+ public override void tear_down () {
+ test_multi_map = null;
+ }
+
+ private void test_selected_functions () {
+ var test_tree_multi_map = test_multi_map as TreeMultiMap<string,string>;
+
+ // Check the map exists
+ assert (test_tree_multi_map != null);
+
+ // Check the selected compare functions
+ assert (test_tree_multi_map.key_compare_func == (CompareFunc) strcmp);
+ assert (test_tree_multi_map.value_compare_func == (CompareFunc) strcmp);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]