[libgee] Move stream_impl to Traversable
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Move stream_impl to Traversable
- Date: Sun, 19 Aug 2012 02:59:36 +0000 (UTC)
commit de1736192e25f062aac7d51c111d20a64c58668c
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Sat Aug 18 19:53:44 2012 -0700
Move stream_impl to Traversable
gee/abstractmultiset.vala | 4 --
gee/arraylist.vala | 4 --
gee/arrayqueue.vala | 4 --
gee/concurrentlist.vala | 4 --
gee/hashmap.vala | 12 -------
gee/hashset.vala | 4 --
gee/iterable.vala | 5 ---
gee/iterator.vala | 64 ----------------------------------------
gee/linkedlist.vala | 4 --
gee/priorityqueue.vala | 4 --
gee/traversable.vala | 71 ++++++++++++++++++++++++++++++++++++++++++++-
gee/treemap.vala | 24 ---------------
gee/treeset.vala | 8 -----
gee/unfolditerator.vala | 4 --
tests/testcollection.vala | 5 ---
15 files changed, 70 insertions(+), 151 deletions(-)
---
diff --git a/gee/abstractmultiset.vala b/gee/abstractmultiset.vala
index 1a5e55b..088b19d 100644
--- a/gee/abstractmultiset.vala
+++ b/gee/abstractmultiset.vala
@@ -165,9 +165,5 @@ public abstract class Gee.AbstractMultiSet<G> : AbstractCollection<G>, MultiSet<
public Type element_type {
get { return typeof (G); }
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
}
}
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 017eebe..fb59d5d 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -402,10 +402,6 @@ public class Gee.ArrayList<G> : AbstractBidirList<G> {
}
_index = _list._size;
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
}
}
diff --git a/gee/arrayqueue.vala b/gee/arrayqueue.vala
index 0e18473..01b1d56 100644
--- a/gee/arrayqueue.vala
+++ b/gee/arrayqueue.vala
@@ -322,10 +322,6 @@ public class Gee.ArrayQueue<G> : Gee.AbstractQueue<G>, Deque<G> {
}
}
- public Gee.Iterator<A> stream<A> (owned StreamFunc<G, A> f) {
- return Gee.Iterator.stream_impl<G, A> (this, (owned)f);
- }
-
private ArrayQueue _queue;
private int _stamp;
private int _offset = -1;
diff --git a/gee/concurrentlist.vala b/gee/concurrentlist.vala
index 5ef30c9..fa5acf9 100644
--- a/gee/concurrentlist.vala
+++ b/gee/concurrentlist.vala
@@ -357,10 +357,6 @@ public class Gee.ConcurrentList<G> : AbstractList<G> {
}
}
- public Gee.Iterator<G> stream<A> (owned StreamFunc<G, A> f) {
- return Gee.Iterator.stream_impl<G, A> (this, (owned)f);
- }
-
private bool _started;
private bool _removed;
private int _index;
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index eef1c18..c7d988b 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -568,10 +568,6 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
break;
} while(true);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, K> f) {
- return Gee.Iterator.stream_impl<K, A>(this, (owned)f);
- }
}
private class MapIterator<K,V> : NodeIterator<K,V>, Gee.MapIterator<K,V> {
@@ -657,10 +653,6 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
break;
} while(true);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, V> f) {
- return Gee.Iterator.stream_impl<V, A>(this, (owned)f);
- }
}
private class EntryIterator<K,V> : NodeIterator<K,V>, Traversable<Map.Entry<K,V>>, Iterator<Map.Entry<K,V>> {
@@ -700,10 +692,6 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
break;
} while(true);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<Map.Entry<K,V>, A> f) {
- return Gee.Iterator.stream_impl<Map.Entry<K,V>, A>(this, (owned)f);
- }
}
}
diff --git a/gee/hashset.vala b/gee/hashset.vala
index b17d415..9af1a2c 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -305,10 +305,6 @@ public class Gee.HashSet<G> : AbstractSet<G> {
}
}
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
}
}
diff --git a/gee/iterable.vala b/gee/iterable.vala
index 965bdab..5330c2f 100644
--- a/gee/iterable.vala
+++ b/gee/iterable.vala
@@ -27,11 +27,6 @@ using GLib;
*/
public interface Gee.Iterable<G> : Object, Traversable<G> {
/**
- * The type of the elements in this collection.
- */
- public abstract Type element_type { get; }
-
- /**
* Returns a { link Iterator} that can be used for simple iteration over a
* collection.
*
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 65bd8af..b22fa10 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -78,70 +78,6 @@ public interface Gee.Iterator<G> : Object, Traversable<G> {
public abstract bool read_only { get; }
/**
- * Default implementation of { link Traversable.stream}.
- *
- * @param self Current Iterator
- * @param f Stream function
- * @return Transformed stream
- * @see Traversable.stream
- */
- public static Iterator<A> stream_impl<G, A> (Iterator<G> self, owned StreamFunc<G, A> f) {
- Traversable.Stream str;
- Lazy<A>? initial = null;
- bool need_next = true;
- str = f (Traversable.Stream.YIELD, null, out initial);
- switch (str) {
- case Traversable.Stream.CONTINUE:
- if (self.valid) {
- str = f (Traversable.Stream.CONTINUE, new Lazy<G> (() => {return self.get ();}), out initial);
- switch (str) {
- case Traversable.Stream.YIELD:
- case Traversable.Stream.CONTINUE:
- break;
- case Traversable.Stream.END:
- return unfold<A> (() => {return null;});
- default:
- assert_not_reached ();
- }
- }
- break;
- case Traversable.Stream.YIELD:
- if (self.valid)
- need_next = false;
- break;
- case Traversable.Stream.END:
- return unfold<A> (() => {return null;});
- default:
- assert_not_reached ();
- }
- return unfold<A> (() => {
- Lazy<A>? val = null;
- if (str != Traversable.Stream.CONTINUE)
- str = f (Traversable.Stream.YIELD, null, out val);
- while (str == Traversable.Stream.CONTINUE) {
- if (need_next) {
- if (!self.next ()) {
- str = f (Traversable.Stream.END, null, out val);
- assert (str != Traversable.Stream.CONTINUE);
- break;
- }
- } else {
- need_next = true;
- }
- str = f (Traversable.Stream.CONTINUE, new Lazy<G> (() => {return self.get ();}), out val);
- }
- switch (str) {
- case Traversable.Stream.YIELD:
- return val;
- case Traversable.Stream.END:
- return null;
- default:
- assert_not_reached ();
- }
- }, initial);
- }
-
- /**
* Create iterator from unfolding function. The lazy value is
* force-evaluated before progressing to next element.
*
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index 0bc17e5..26e8a68 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -623,10 +623,6 @@ public class Gee.LinkedList<G> : AbstractBidirList<G>, Queue<G>, Deque<G> {
}
position = _list._tail;
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
}
private unowned Node<G>? _get_node_at (int index) {
diff --git a/gee/priorityqueue.vala b/gee/priorityqueue.vala
index 67c764a..c865dc6 100644
--- a/gee/priorityqueue.vala
+++ b/gee/priorityqueue.vala
@@ -1045,9 +1045,5 @@ public class Gee.PriorityQueue<G> : Gee.AbstractQueue<G> {
while (next ())
f (position.data);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
}
}
diff --git a/gee/traversable.vala b/gee/traversable.vala
index c3d53bb..7b5cea6 100644
--- a/gee/traversable.vala
+++ b/gee/traversable.vala
@@ -102,7 +102,70 @@ public interface Gee.Traversable<G> : Object {
* @param f function generating stream
* @return iterator containing values yielded by stream
*/
- public abstract Iterator<A> stream<A> (owned StreamFunc<G, A> f);
+ public virtual Iterator<A> stream<A> (owned StreamFunc<G, A> f) {
+ Iterator<G>? self;
+ Iterable<G>? iself;
+ // Yes - I've heard of polimorphism ;) but I don't want users to need to implement the method.
+ if ((self = this as Iterator<G>) != null) {
+ Traversable.Stream str;
+ Lazy<A>? initial = null;
+ bool need_next = true;
+ str = f (Stream.YIELD, null, out initial);
+ switch (str) {
+ case Stream.CONTINUE:
+ if (self.valid) {
+ str = f (Stream.CONTINUE, new Lazy<G> (() => {return self.get ();}), out initial);
+ switch (str) {
+ case Stream.YIELD:
+ case Stream.CONTINUE:
+ break;
+ case Stream.END:
+ return Iterator.unfold<A> (() => {return null;});
+ default:
+ assert_not_reached ();
+ }
+ }
+ break;
+ case Stream.YIELD:
+ if (self.valid)
+ need_next = false;
+ break;
+ case Stream.END:
+ return Iterator.unfold<A> (() => {return null;});
+ default:
+ assert_not_reached ();
+ }
+ return Iterator.unfold<A> (() => {
+ Lazy<A>? val = null;
+ if (str != Stream.CONTINUE)
+ str = f (Traversable.Stream.YIELD, null, out val);
+ while (str == Stream.CONTINUE) {
+ if (need_next) {
+ if (!self.next ()) {
+ str = f (Traversable.Stream.END, null, out val);
+ assert (str != Traversable.Stream.CONTINUE);
+ break;
+ }
+ } else {
+ need_next = true;
+ }
+ str = f (Stream.CONTINUE, new Lazy<G> (() => {return self.get ();}), out val);
+ }
+ switch (str) {
+ case Stream.YIELD:
+ return val;
+ case Stream.END:
+ return null;
+ default:
+ assert_not_reached ();
+ }
+ }, initial);
+ } else if ((iself = this as Iterable<G>) != null) {
+ return iself.iterator().stream<A> ((owned) f);
+ } else {
+ assert_not_reached ();
+ }
+ }
/**
* Standard aggregation function.
@@ -300,6 +363,12 @@ public interface Gee.Traversable<G> : Object {
});
}
+
+ /**
+ * The type of the elements in this collection.
+ */
+ public virtual Type element_type { get { return typeof (G); } }
+
public enum Stream {
YIELD,
CONTINUE,
diff --git a/gee/treemap.vala b/gee/treemap.vala
index a5bda43..ec47a22 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -1650,10 +1650,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
for (; current != null; current = current.next)
f (current.key);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, K> f) {
- return Gee.Iterator.stream_impl<K, A>(this, (owned)f);
- }
}
private class SubKeyIterator<K,V> : SubNodeIterator<K,V>, Traversable<K>, Gee.Iterator<K>, BidirIterator<K> {
@@ -1680,10 +1676,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
while (iterator.next ())
f (iterator.current.key);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, K> f) {
- return Gee.Iterator.stream_impl<K, A>(this, (owned)f);
- }
}
private class ValueIterator<K,V> : NodeIterator<K,V>, Traversable<V>, Gee.Iterator<V>, Gee.BidirIterator<V> {
@@ -1722,10 +1714,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
for (; current != null; current = current.next)
f (current.key);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, V> f) {
- return Gee.Iterator.stream_impl<V, A>(this, (owned)f);
- }
}
private class SubValueIterator<K,V> : SubNodeIterator<K,V>, Traversable<V>, Gee.Iterator<V>, BidirIterator<V> {
@@ -1752,10 +1740,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
while (iterator.next ())
f (iterator.current.key);
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, V> f) {
- return Gee.Iterator.stream_impl<V, A>(this, (owned)f);
- }
}
private class EntryIterator<K,V> : NodeIterator<K,V>, Traversable<Map.Entry<K, V>>, Gee.Iterator<Map.Entry<K,V>>, Gee.BidirIterator<Map.Entry<K,V>> {
@@ -1798,10 +1782,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
for (; current != null; current = current.next)
f (Entry.entry_for<K,V> (current));
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<Map.Entry<K, V>, A> f) {
- return Gee.Iterator.stream_impl<Map.Entry<K, V>, A>(this, (owned)f);
- }
}
private class SubEntryIterator<K,V> : SubNodeIterator<K,V>, Traversable<Map.Entry<K, V>>, Gee.Iterator<Map.Entry<K,V>>, Gee.BidirIterator<Map.Entry<K,V>> {
@@ -1832,10 +1812,6 @@ public class Gee.TreeMap<K,V> : Gee.AbstractBidirSortedMap<K,V> {
while (iterator.next ())
f (Entry.entry_for<K,V> (iterator.current));
}
-
- public Gee.Iterator<A> stream<A> (owned StreamFunc<Map.Entry<K, V>, A> f) {
- return Gee.Iterator.stream_impl<Map.Entry<K, V>, A>(this, (owned)f);
- }
}
private class MapIterator<K,V> : NodeIterator<K,V>, Gee.MapIterator<K,V>, BidirMapIterator<K,V> {
diff --git a/gee/treeset.vala b/gee/treeset.vala
index 771879e..4b7e06b 100644
--- a/gee/treeset.vala
+++ b/gee/treeset.vala
@@ -734,10 +734,6 @@ public class Gee.TreeSet<G> : AbstractBidirSortedSet<G> {
}
}
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
-
private weak Node<G>? current = null;
private weak Node<G>? _next = null;
private weak Node<G>? _prev = null;
@@ -1133,10 +1129,6 @@ public class Gee.TreeSet<G> : AbstractBidirSortedSet<G> {
f(get());
}
- public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
- }
-
private new TreeSet<G> set;
private Range<G> range;
private Iterator<G>? iterator = null;
diff --git a/gee/unfolditerator.vala b/gee/unfolditerator.vala
index 3a4c6c6..8ca4ee8 100644
--- a/gee/unfolditerator.vala
+++ b/gee/unfolditerator.vala
@@ -90,10 +90,6 @@ internal class Gee.UnfoldIterator<G> : Object, Traversable<G>, Iterator<G> {
_end = true;
}
- public Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
- return Iterator.stream_impl<G, A>(this, (owned)f);
- }
-
private UnfoldFunc<G> _func;
private Lazy<G>? _current;
private Lazy<G>? _next;
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index 0794369..bf90eaf 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -739,11 +739,6 @@ public abstract class CollectionTests : Gee.TestCase {
assert (test_collection != null);
Value value;
- value = Value (typeof (Type));
- test_collection.get_property ("element-type", ref value);
- assert (value.get_gtype () == test_collection.element_type);
- value.unset ();
-
value = Value (typeof (int));
test_collection.get_property ("size", ref value);
assert (value.get_int () == test_collection.size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]