[libgee] Specialize foreach functions for ArrayList and LinkedList
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Specialize foreach functions for ArrayList and LinkedList
- Date: Sun, 30 Sep 2012 06:42:27 +0000 (UTC)
commit 0ef993058e4f1285d43c1419c4d22d352f2992e6
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]