Top Description Inners Fields Constructors Methods
org.pcollections

pack-priv Class IntTree<V>

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.AbstractMap.SimpleImmutableEntry, .Iterator, .Map.Entry, .NoSuchElementException

A non-public utility class for persistent balanced tree maps with integer keys.

To allow for efficiently increasing all keys above a certain value or decreasing all keys below a certain value, the keys values are stored relative to their parent. This makes this map a good backing for fast insertion and removal of indices in a vector. Null values are supported.

This implementation is thread-safe except for its iterators.

Other than that, this tree is based on the Glasgow Haskell Compiler's Data.Map implementation, which in turn is based on "size balanced binary trees" as described by:

Stephen Adams, "Efficient sets: a balancing act", Journal of Functional Programming 3(4):553-562, October 1993, http://www.swiss.ai.mit.edu/~adams/BB/.

J. Nievergelt and E.M. Reingold, "Binary search trees of bounded balance", SIAM journal of computing 2(1), March 1973.

Author
harold

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv static final IntTree<Object>
private final long
private final IntTree<V>
private static final int
private final IntTree<V>
private static final long
private final int
private final V

Constructor Summary

AccessConstructor and Description
private
private
IntTree(final long key, final V value, final IntTree<V> left, final IntTree<V> right)

Method Summary

Modifier and TypeMethod and Description
pack-priv IntTree<V>
changeKeysAbove(final long key, final int delta)

Changes every key k>=key to k+delta.

pack-priv IntTree<V>
changeKeysBelow(final long key, final int delta)

Changes every key k<key to k+delta. 0 and the distance between the largest k<key in this and the smallest j>=key in this is delta or less.

pack-priv boolean
containsKey(final long key)

pack-priv V
get(final long key)

pack-priv Iterator<Map.Entry<Integer, V>>
private long
pack-priv IntTree<V>
minus(final long key)

pack-priv IntTree<V>
plus(final long key, final V value)

private IntTree<V>
rebalanced(final IntTree<V> newLeft, final IntTree<V> newRight)

private static <V> IntTree<V>
rebalanced(final long key, final V value, final IntTree<V> left, final IntTree<V> right)

pack-priv int
size()

private IntTree<V>
withKey(final long newKey)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALPHAback to summary
private static final int ALPHA
EMPTYNODEback to summary
pack-priv static final IntTree<Object> EMPTYNODE
keyback to summary
private final long key
leftback to summary
private final IntTree<V> left
OMEGAback to summary
private static final int OMEGA
serialVersionUIDback to summary
private static final long serialVersionUID
sizeback to summary
private final int size
valueback to summary
private final V value

Constructor Detail

IntTreeback to summary
private IntTree()
IntTreeback to summary
private IntTree(final long key, final V value, final IntTree<V> left, final IntTree<V> right)

Method Detail

changeKeysAboveback to summary
pack-priv IntTree<V> changeKeysAbove(final long key, final int delta)

Changes every key k>=key to k+delta.

This method will create an _invalid_ tree if delta<0 and the distance between the smallest k>=key in this and the largest jIn other words, this method must not result in any change in the order of the keys in this, since the tree structure is not being changed at all.

changeKeysBelowback to summary
pack-priv IntTree<V> changeKeysBelow(final long key, final int delta)

Changes every key kThis method will create an _invalid_ tree if delta>0 and the distance between the largest k=key in this is delta or less.

In other words, this method must not result in any overlap or change in the order of the keys in this, since the tree _structure_ is not being changed at all.

containsKeyback to summary
pack-priv boolean containsKey(final long key)
getback to summary
pack-priv V get(final long key)
iteratorback to summary
pack-priv Iterator<Map.Entry<Integer, V>> iterator()
minKeyback to summary
private long minKey()
minusback to summary
pack-priv IntTree<V> minus(final long key)
plusback to summary
pack-priv IntTree<V> plus(final long key, final V value)
rebalancedback to summary
private IntTree<V> rebalanced(final IntTree<V> newLeft, final IntTree<V> newRight)
rebalancedback to summary
private static <V> IntTree<V> rebalanced(final long key, final V value, final IntTree<V> left, final IntTree<V> right)
sizeback to summary
pack-priv int size()
withKeyback to summary
private IntTree<V> withKey(final long newKey)
org.pcollections back to summary

private final Class IntTree.EntryIterator<V>

extends Object
implements Iterator<Map.Entry<Integer, V>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private PStack<IntTree<V>>

Constructor Summary

AccessConstructor and Description
pack-priv
EntryIterator(final IntTree<V> root)

Method Summary

Modifier and TypeMethod and Description
private void
gotoMinOf(IntTree<V> node)

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Map.Entry<Integer, V>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

keyback to summary
private int key
stackback to summary
private PStack<IntTree<V>> stack

Constructor Detail

EntryIteratorback to summary
pack-priv EntryIterator(final IntTree<V> root)

Method Detail

gotoMinOfback to summary
private void gotoMinOf(IntTree<V> node)
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextback to summary
public Map.Entry<Integer, V> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Map.Entry<Integer, V>

the next element in the iteration

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.