[folks] Added a LinkedHashSet ordered set.
- From: Eitan Isaacson <eitani src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Added a LinkedHashSet ordered set.
- Date: Tue, 18 Jan 2011 17:25:45 +0000 (UTC)
commit da5e0d35d5800bb03ff1e0818c1b51f4284e7c76
Author: Eitan Isaacson <eitan monotonous org>
Date: Sun Jan 16 11:46:27 2011 +0200
Added a LinkedHashSet ordered set.
NEWS | 3 +
folks/Makefile.am | 1 +
folks/linked-hash-set.vala | 203 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 207 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 0205d4a..b1ea5e5 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ Overview of changes from libfolks 0.3.3 to libfolks 0.3.4
Major changes:
* Add folks-inspect tool
+API changes:
+* New type: LinkedHashSet, similar to Gee.HashSet, but ordered.
+
Bugs fixed:
* Bug 637240 â?? libfolks-telepathy.so exports private symbols
* Bug 638311 â?? Add a HACKING file that outlines development policies and
diff --git a/folks/Makefile.am b/folks/Makefile.am
index c18f227..afe0fda 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -22,6 +22,7 @@ libfolks_la_SOURCES = \
imable.vala \
individual.vala \
individual-aggregator.vala \
+ linked-hash-set.vala \
persona.vala \
persona-store.vala \
types.vala \
diff --git a/folks/linked-hash-set.vala b/folks/linked-hash-set.vala
new file mode 100644
index 0000000..607feaf
--- /dev/null
+++ b/folks/linked-hash-set.vala
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Eitan Isaacson <eitan isaacson collabora co uk>
+ */
+
+using Gee;
+
+/* Linked list implementation of the { link Gee.Set} interface.
+ * This implementation provides an ordered set with predictable iteration.
+ *
+ * @since 0.3.UNRELEASED
+ */
+public class Folks.LinkedHashSet<G> : AbstractList<G>,
+ Set<G>
+{
+ /* A hash set that maintains a unique set. */
+ private HashSet<G> _hash_set;
+ /* A linked list that maintains the order of the items. */
+ private LinkedList<G> _linked_list;
+
+ /**
+ * Constructs a new empty set.
+ *
+ * If no function parameters are provided, the default functions for the
+ * set's item type are used.
+ *
+ * @param hash_func an optional hash function
+ * @param equal_func an optional equality testing function
+ */
+ public LinkedHashSet (HashFunc? hash_func = null,
+ EqualFunc? equal_func = null)
+ {
+ this._hash_set = new HashSet<G> (hash_func, equal_func);
+ this._linked_list = new LinkedList<G> (equal_func);
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override int size
+ {
+ get { return this._linked_list.size; }
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override bool contains (G item)
+ {
+ return this._hash_set.contains (item);
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override bool add (G item)
+ {
+ if (this._hash_set.add (item))
+ {
+ this._linked_list.add (item);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override bool remove (G item)
+ {
+ if (this._hash_set.remove (item))
+ {
+ this._linked_list.remove (item);
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override void clear ()
+ {
+ this._hash_set.clear ();
+ this._linked_list.clear ();
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override G get (int index)
+ {
+ return this._linked_list.get (index);
+ }
+
+ /**
+ * Unimplemented method (incompatable with ordered set).
+ */
+ public override void set (int index, G item)
+ {
+ assert_not_reached ();
+ }
+
+ /**
+ * Unimplemented method (incompatable with ordered set).
+ */
+ public override void insert (int index, G item)
+ {
+ assert_not_reached ();
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override int index_of (G item)
+ {
+ if (!this._hash_set.contains (item))
+ return -1;
+ return this._linked_list.index_of (item);
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override G remove_at (int index)
+ {
+ G item = this._linked_list.remove_at (index);
+ if (item != null)
+ this._hash_set.remove (item);
+ return item;
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override Gee.List<G>? slice (int start, int stop)
+ {
+ return this._linked_list.slice (start, stop);
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override G first ()
+ {
+ return this._linked_list.first ();
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override G last ()
+ {
+ return this._linked_list.last ();
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override bool add_all (Collection<G> collection)
+ {
+ bool modified = false;
+
+ foreach (G item in collection)
+ modified |= add(item);
+
+ return modified;
+ }
+
+
+ /**
+ * { inheritDoc}
+ */
+ public override Gee.Iterator<G> iterator ()
+ {
+ return this._linked_list.iterator ();
+ }
+
+ /**
+ * { inheritDoc}
+ */
+ public override ListIterator<G> list_iterator ()
+ {
+ return this._linked_list.list_iterator ();
+ }
+}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]