X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Futil%2FBalancedTree.java;h=0f8b62ef4d1f134c782ea0de65c4d8f2bea539d1;hb=e38866b923f273eb263e1bdc3782f4a04791682d;hp=52ac71be0b2089969c1af77fc517708df5d8f21a;hpb=eb8d7e6a8fa6091bc2e4999c21faee5cfccbfbf2;p=org.ibex.core.git diff --git a/src/org/xwt/util/BalancedTree.java b/src/org/xwt/util/BalancedTree.java index 52ac71b..0f8b62e 100644 --- a/src/org/xwt/util/BalancedTree.java +++ b/src/org/xwt/util/BalancedTree.java @@ -1,4 +1,10 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright (C) 2003 Adam Megacz all rights reserved. +// +// You may modify, copy, and redistribute this code under the terms of +// the GNU Library Public License version 2.1, with the exception of +// the portion of clause 6a after the semicolon (aka the "obnoxious +// relink clause") + package org.xwt.util; // FEATURE: private void intersection() { } @@ -60,7 +66,7 @@ public class BalancedTree { if (parent == 0) return size(left[slot]); // we are on the far left edge // all nodes after parent and before us are in our left subtree - return size(left[slot]) + indexNode(objects[parent]) + 1; + return size(left[slot]) + (parent <= 0 ? 0 : indexNode(objects[parent])) + 1; } /** returns the object at index; runs in O(log n) time unless cache hit */ @@ -304,7 +310,7 @@ public class BalancedTree { } else { int left_childs_rightmost = delete(size(left[slot]) - 1, left[slot], slot); left[left_childs_rightmost] = left[slot]; - left[left_childs_rightmost] = right[slot]; + right[left_childs_rightmost] = right[slot]; if (parent == 0) root = left_childs_rightmost; else (left[parent] == slot ? left : right)[parent] = left_childs_rightmost; // fix parent's pointer balance(left_childs_rightmost, parent);