Java Order Statistic TreeMap
http://ift.tt/1T0RRUp
final Entry<K,V> getIthEntry(Entry<K,V> entry, int i) {
if (i > size || i<=0)
throw new IndexOutOfBoundsException("Size is " + size
+ ", requested i=" + i + " out of bounds");
int r = 1;
if (entry.left != null)
r += entry.left.size;
if (i == r)
return entry;
else if (i < r)
return getIthEntry(entry.left, i);
else
return getIthEntry(entry.right, i-r);
}
static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left = null;
Entry<K,V> right = null;
Entry<K,V> parent;
boolean color = BLACK;
int size = 1;
}
http://ift.tt/1T0RRUp
final Entry<K,V> getIthEntry(Entry<K,V> entry, int i) {
if (i > size || i<=0)
throw new IndexOutOfBoundsException("Size is " + size
+ ", requested i=" + i + " out of bounds");
int r = 1;
if (entry.left != null)
r += entry.left.size;
if (i == r)
return entry;
else if (i < r)
return getIthEntry(entry.left, i);
else
return getIthEntry(entry.right, i-r);
}
static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left = null;
Entry<K,V> right = null;
Entry<K,V> parent;
boolean color = BLACK;
int size = 1;
}
from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1T0RQ2O
via LifeLong Community
No comments:
Post a Comment