[libgee] Fix some bugs in TreeSet implementation
- From: Didier 'Ptitjes' Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Fix some bugs in TreeSet implementation
- Date: Tue, 15 Sep 2009 23:54:55 +0000 (UTC)
commit e8b2a13943cb2c1273b341cf677d7735a4a67bb8
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Wed Sep 16 01:51:28 2009 +0200
Fix some bugs in TreeSet implementation
Fixes part of bug 594868.
The access to child nodes two level deeper does not check that the
child at the intermediate level is not null.
Also has_next was incorrectly handled in case of an empty set.
gee/treeset.vala | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/gee/treeset.vala b/gee/treeset.vala
index be49d62..7593f53 100644
--- a/gee/treeset.vala
+++ b/gee/treeset.vala
@@ -159,7 +159,7 @@ public class Gee.TreeSet<G> : AbstractSet<G> {
private void move_red_left (ref Node<G> root) {
root.flip ();
- if (is_red (root.right.left)) {
+ if (root.right != null && is_red (root.right.left)) {
rotate_right (ref root.right);
rotate_left (ref root);
root.flip ();
@@ -168,7 +168,7 @@ public class Gee.TreeSet<G> : AbstractSet<G> {
private void move_red_right (ref Node<G> root) {
root.flip ();
- if (is_red (root.left.left)) {
+ if (root.left != null && is_red (root.left.left)) {
rotate_right (ref root.right);
root.flip ();
}
@@ -231,7 +231,7 @@ public class Gee.TreeSet<G> : AbstractSet<G> {
fix_removal (ref node, null);
return true;
}
- if (is_black (r) && is_black (r.left)) {
+ if (r == null || (is_black (r) && is_black (r.left))) {
move_red_right (ref node);
}
if (compare_func (item, node.key) == 0) {
@@ -370,6 +370,9 @@ public class Gee.TreeSet<G> : AbstractSet<G> {
public bool has_next () {
assert (stamp == _set.stamp);
+ if (_set.size == 0) {
+ return false;
+ }
return (current == null && state == Iterator.State.BEFORE_THE_BEGIN) ||
(current == null && state == Iterator.State.NORMAL && _next != null) ||
(current != null && current.next != null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]