diff options
author | Maciej Piechotka <uzytkownik2@gmail.com> | 2013-07-15 19:36:12 +0200 |
---|---|---|
committer | Maciej Piechotka <uzytkownik2@gmail.com> | 2013-07-15 19:36:12 +0200 |
commit | b0cbe378a7e3cc1498d3e4af24f9695ca05ac27f (patch) | |
tree | 3b0c058cbccdbeb6d1d1b208d77feb0e2290cc26 | |
parent | bd7598ae5653301235dfe0a990f5064cfb563cc2 (diff) | |
download | libgee-b0cbe378a7e3cc1498d3e4af24f9695ca05ac27f.tar.gz |
Fix the HashSet.Iterator.foreach
-rw-r--r-- | gee/hashset.vala | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/gee/hashset.vala b/gee/hashset.vala index d6f10c4..65c8f40 100644 --- a/gee/hashset.vala +++ b/gee/hashset.vala @@ -45,7 +45,7 @@ public class Gee.HashSet<G> : AbstractSet<G> { public override int size { get { return _nnodes; } } - + /** * {@inheritDoc} */ @@ -275,13 +275,13 @@ public class Gee.HashSet<G> : AbstractSet<G> { _node = null; _stamp = _set._stamp; } - + public bool read_only { get { return false; } } - + public bool valid { get { return _node != null; @@ -290,23 +290,40 @@ public class Gee.HashSet<G> : AbstractSet<G> { public bool foreach (ForallFunc<G> f) { assert (_stamp == _set._stamp); - if (_node != null) { - if (!f (_node.key)) { + unowned Node<G>? node = _node, next = _next, current = null, prev = null; + if (node != null) { + if (!f (node.key)) { return false; } + prev = node; + current = node.next; } - while (_index + 1 < _set._array_size || _next != null) { - if (_next != null) { - _node = _next; - if (!f (_node.key)) { + if (next != null) { + if (!f (next.key)) { + _node = next; + _next = null; + return false; + } + prev = next; + current = next.next; + } + do { + while (current != null) { + if (!f (current.key)) { + _node = current; + _next = null; return false; } - _next = _node.next; - } else { + prev = current; + current = current.next; + } + while (current == null && _index + 1 < _set._array_size) { _index++; - _next = _set._nodes[_index]; + current = _set._nodes[_index]; } - } + } while (current != null); + _node = prev; + _next = null; return true; } } |