[libgee/0.8] Specialize foreach functions for ArrayList and LinkedList



commit 770b6ffbee226bcc622bf9bf4f9d05c1e93ea0e4
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sun Sep 30 08:41:49 2012 +0200

    Specialize foreach functions for ArrayList and LinkedList

 gee/arraylist.vala  |   12 ++++++++++++
 gee/linkedlist.vala |   12 ++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index d6254e8..5242afe 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -82,6 +82,18 @@ public class Gee.ArrayList<G> : AbstractBidirList<G> {
 	/**
 	 * { inheritDoc}
 	 */
+	public override bool foreach(ForallFunc<G> f) {
+		for (int i = 0; i < _size; i++) {
+			if (!f (_items[i])) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
 	public override Gee.Iterator<G> iterator () {
 		return new Iterator<G> (this);
 	}
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index e20f377..4a5acd4 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -66,6 +66,18 @@ public class Gee.LinkedList<G> : AbstractBidirList<G>, Queue<G>, Deque<G> {
 	/**
 	 * { inheritDoc}
 	 */
+	public override bool foreach(ForallFunc<G> f) {
+		for (weak Node<G>? node = _head; node != null; node = node.next) {
+			if (!f (node.data)) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
 	public override Gee.Iterator<G> iterator () {
 		return new Iterator<G> (this);
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]