Class AssociativeAddressTrie<K extends Address,V>
- Type Parameters:
K
- the type of the address keysV
- the type of the associated values
- All Implemented Interfaces:
AddressTrieOps<K>
,AddressTrieOps.AddressTrieAddOps<K>
,AddressTrieOps.AssociativeAddressTrieOps<K,
,V> AddressTrieOps.AssociativeAddressTriePutOps<K,
,V> TreeOps<K>
,Serializable
,Cloneable
,Iterable<K>
- Direct Known Subclasses:
IPv4AddressAssociativeTrie
,IPv6AddressAssociativeTrie
,MACAddressAssociativeTrie
The trie can also be used as the backing data structure for a AddressTrieMap
which is a NavigableMap
.
Unlike TreeMap
this data structure provides access to the nodes and the associated sub-trie with each node as the sub-trie root,
which corresponds with their associated CIDR prefix block subnets.
Use one of the put methods to add nodes with values or to change the values of existing nodes.
You can also add to the trie using AddressTrie.add(Address)
and the associated value will be null.
Mapped tries are thread-safe when not being modified (ie mappings added or removed), but are not thread-safe when a thread is modifying the trie.
To make them thread-safe during addition and removal you could access them through the collection provided by Collections.synchronizedMap(java.util.Map<K, V>)
,
applied to the map from asMap()
- Author:
- scfoley
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Nested classes/interfaces inherited from class inet.ipaddr.format.util.AddressTrie
AddressTrie.AddressComparator<E extends Address>, AddressTrie.TrieComparator<E extends Address>, AddressTrie.TrieNode<E extends Address>
Nested classes/interfaces inherited from interface inet.ipaddr.format.util.AddressTrieOps
AddressTrieOps.AddressTrieAddOps<E extends Address>, AddressTrieOps.AssociativeAddressTrieOps<K extends Address,
V>, AddressTrieOps.AssociativeAddressTriePutOps<K extends Address, V> -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionAdds the given single address or prefix block subnet to the trie, if not already there.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> allNodeIterator
(boolean forward) Iterates through the nodes (not just the added nodes) in forward or reverse tree order.Spliterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> allNodeSpliterator
(boolean forward) Creates aSpliterator
over the nodes in forward or reverse natural tree order.asMap()
Returns a java.util.NavigableMap backed by this associative trie.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> blockSizeAllNodeIterator
(boolean lowerSubNodeFirst) Iterates all nodes in the trie, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.<C> BinaryTreeNode.CachingIterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>, K, C> Iterates all nodes, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> blockSizeNodeIterator
(boolean lowerSubNodeFirst) Iterates the added nodes in the trie, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.ceilingAddedNode
(K addr) Returns the added node whose address is the lowest address greater than or equal to the given address.clone()
Copies the trie, but not the keys or values.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> containedFirstAllNodeIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a post-order binary tree traversal.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> containedFirstIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a post-order binary tree traversal of the added nodes.<C> BinaryTreeNode.CachingIterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>, K, C> containingFirstAllNodeIterator
(boolean lowerSubNodeFirst) Returns an iterator that does a pre-order binary tree traversal.<C> BinaryTreeNode.CachingIterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>, K, C> containingFirstIterator
(boolean lowerSubNodeFirst) Returns an iterator that does a pre-order binary tree traversal of the added nodes.Traverses the added node keys in reverse natural tree order.elementsContainedBy
(K addr) Checks if a part of this trie is contained by the given prefix block subnet or individual address.elementsContaining
(K addr) Finds the added subnets and/or addresses in the trie that contain the given individual address or prefix block subnet.boolean
Returns whether the given argument is a trie with a set of nodes that equal the set of nodes in this trieReturns the added node with the first (lowest valued) key, or null if there are no added entries in this trie or subtrieReturns the node with the first (lowest valued) key, whether the node is added or notfloorAddedNode
(K addr) Returns the added node whose address is the highest address less than or equal to the given address.Gets the specified value for the specified key in this mapped trie or subtrie.getAddedNode
(K addr) Gets trie nodes representing added elements.Gets the node corresponding to the given address, returns null if not such element exists.getRoot()
Returns the root of this trieint
hashCode()
higherAddedNode
(K addr) Returns the added node whose address is the lowest address strictly greater than the given address.iterator()
Traverses the added node keys in natural tree order.Returns the added node with the last (highest valued) key, or null if there are no added elements in this trie or subtrielastNode()
Returns the node with the last (highest valued) key, whether the node is added or notlongestPrefixMatchNode
(K addr) Finds the containing subnet or address in the trie with the smallest subnet size, which is equivalent to finding the subnet or address with the longest matching prefix.lowerAddedNode
(K addr) Returns the added node whose address is the highest address strictly less than the given address.Iterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> nodeIterator
(boolean forward) Iterates through the added nodes in forward or reverse natural tree order.Spliterator
<? extends AssociativeAddressTrie.AssociativeTrieNode<K, V>> nodeSpliterator
(boolean forward) Creates aSpliterator
over the added nodes in forward or reverse natural tree order.Associates the specified value with the specified key in this map.boolean
Associates the specified value with the specified key in this map.Associates the specified value with the specified key in this map.Adds nodes matching the given sub-root node and all of its sub-nodes to the trie, if not already there.Remaps node values in the trie.remapIfAbsent
(K addr, Supplier<? extends V> remapper, boolean insertNull) Remaps node values in the trie, but only for nodes that do not exist or are mapped to null.removeElementsContainedBy
(K addr) Removes any single address or prefix block subnet from the trie that is contained in the given individual address or prefix block subnet.Methods inherited from class inet.ipaddr.format.util.AddressTrie
add, addTrie, asSet, clear, constructAddedNodesTree, contains, decrement, descendingSpliterator, elementContains, getComparator, increment, isEmpty, longestPrefixMatch, nodeSize, remove, size, spliterator, toAddedNodesTreeString, toString, toString, toString
Methods inherited from interface inet.ipaddr.format.util.AddressTrieOps
contains, elementContains, longestPrefixMatch, remove
Methods inherited from interface inet.ipaddr.format.util.TreeOps
descendingIterator, descendingSpliterator, iterator, spliterator
-
Constructor Details
-
AssociativeAddressTrie
-
-
Method Details
-
getRoot
Returns the root of this trie- Overrides:
getRoot
in classAddressTrie<K extends Address>
- Returns:
-
put
Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Associates the specified value with the specified key in this map.Unlike
AddressTrieOps.AssociativeAddressTriePutOps.putNew(Address, Object)
,AddressTrieOps.AssociativeAddressTriePutOps.put(Address, Object)
can provide the value to which to key was previously mapped.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.If this map previously contained a mapping for a key, the old value is replaced by the specified value, and the old value is returned. If this map did not previously contain a mapping for the key, null is returned.
- Specified by:
put
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
addr
-- Returns:
-
putNew
Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Associates the specified value with the specified key in this map.Unlike
AddressTrieOps.AssociativeAddressTriePutOps.put(Address, Object)
,AddressTrieOps.AssociativeAddressTriePutOps.put(Address, Object)
can distinguish between cases where the call results in a new entry, and cases where the call matched a previous entry that was mapped to null.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.If this map previously contained a mapping for a key, the old value is replaced by the specified value, and false is returned. If this map did not previously contain a mapping for the key, true is returned.
- Specified by:
putNew
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
addr
-- Returns:
-
addNode
Description copied from interface:AddressTrieOps.AddressTrieAddOps
Adds the given single address or prefix block subnet to the trie, if not already there.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns the node for the added address, whether it was already in the trie or not.
If you wish to know whether the node was already there when adding, use
AddressTrieOps.AddressTrieAddOps.add(Address)
, or before adding you can useAddressTrieOps.getAddedNode(Address)
- Specified by:
addNode
in interfaceAddressTrieOps.AddressTrieAddOps<K extends Address>
- Overrides:
addNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
putTrie
public AssociativeAddressTrie.AssociativeTrieNode<K,V> putTrie(AssociativeAddressTrie.AssociativeTrieNode<K, V> trie) Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Adds nodes matching the given sub-root node and all of its sub-nodes to the trie, if not already there.For each added in the given node that does not exist in the trie, a copy of each node will be made that matches the trie type (associative or not), the copy including the associated value, and the copy will be inserted into the trie.
The node type need not match the node type of the trie, although the address type/version E must match. So this means you can add non-associative nodes with this method, in which case, the new nodes will be associative but will be mapped to null.
When adding one trie to another, this method is more efficient than adding each node of the first trie individually. When using this method, searching for the location to add sub-nodes starts from the inserted parent node.
Returns the node corresponding to the given sub-root node, whether it was already in the trie or not.
- Specified by:
putTrie
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
trie
-- Returns:
-
putNode
Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Associates the specified value with the specified key in this map.Unlike
AddressTrieOps.AssociativeAddressTriePutOps.put(Address, Object)
,AddressTrieOps.AssociativeAddressTriePutOps.put(Address, Object)
can distinguish between cases where the call results in a new entry, and cases where the call matched a previous entry that was mapped to null.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns the node for the added address, whether it was already in the tree or not.
If you wish to know whether the node was already there when adding, use
AddressTrieOps.AssociativeAddressTriePutOps.putNew(Address, Object)
, or before adding you can useAddressTrieOps.getAddedNode(Address)
- Specified by:
putNode
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
addr
-- Returns:
-
remap
public AssociativeAddressTrie.AssociativeTrieNode<K,V> remap(K addr, Function<? super V, ? extends V> remapper) Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Remaps node values in the trie.This will lookup the node corresponding to the given key. It will call the remapping function with the key as the first argument, regardless of whether the node is found or not.
If the node is not found, the value argument will be null. If the node is found, the value argument will be the node's value, which can also be null.
If the remapping function returns null, then the matched node will be removed, if any. If it returns a non-null value, then it will either set the existing node to have that value, or if there was no matched node, it will create a new node with that value.
The method will return the node involved, which is either the matched node, or the newly created node, or null if there was no matched node nor newly created node.
If the remapping function modifies the trie during its computation, and the returned value specifies changes to be made, then the trie will not be changed and ConcurrentModificationException will be thrown instead.
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.- Specified by:
remap
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
addr
-remapper
-- Returns:
-
remapIfAbsent
public AssociativeAddressTrie.AssociativeTrieNode<K,V> remapIfAbsent(K addr, Supplier<? extends V> remapper, boolean insertNull) Description copied from interface:AddressTrieOps.AssociativeAddressTriePutOps
Remaps node values in the trie, but only for nodes that do not exist or are mapped to null.This will look up the node corresponding to the given key. If the node is not found or mapped to null, this will call the remapping function.
If the remapping function returns a non-null value, then it will either set the existing node to have that value, or if there was no matched node, it will create a new node with that value. If the remapping function returns null, then it will do the same if insertNull is true, otherwise it will do nothing.
The method will return the node involved, which is either the matched node, or the newly created node, or null if there was no matched node nor newly created node.
If the remapping function modifies the trie during its computation, and the returned value specifies changes to be made, then the trie will not be changed and ConcurrentModificationException will be thrown instead.
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.- Specified by:
remapIfAbsent
in interfaceAddressTrieOps.AssociativeAddressTriePutOps<K extends Address,
V> - Parameters:
addr
-remapper
-insertNull
- whether null values returned from remapper should be inserted into the map, or whether null values indicate no remapping- Returns:
-
get
Description copied from interface:AddressTrieOps.AssociativeAddressTrieOps
Gets the specified value for the specified key in this mapped trie or subtrie.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns the value for the given key. Returns null if the contains no mapping for that key or if the mapped value is null.
- Specified by:
get
in interfaceAddressTrieOps.AssociativeAddressTrieOps<K extends Address,
V> - Parameters:
addr
-- Returns:
-
getAddedNode
Description copied from interface:AddressTrieOps
Gets trie nodes representing added elements.Use
AddressTrieOps.contains(Address)
to check for the existence of a given address in the trie, as well asAddressTrieOps.getNode(Address)
to search for all nodes including those not-added but also auto-generated nodes for subnet blocks.- Specified by:
getAddedNode
in interfaceAddressTrieOps<K extends Address>
- Parameters:
addr
-- Returns:
-
getNode
Description copied from interface:AddressTrieOps
Gets the node corresponding to the given address, returns null if not such element exists.If added is true, returns only nodes representing added elements, otherwise returns any node, including a prefix block that was not added.
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.- Specified by:
getNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
getNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
- See Also:
-
removeElementsContainedBy
Description copied from interface:AddressTrieOps
Removes any single address or prefix block subnet from the trie that is contained in the given individual address or prefix block subnet.Goes further than
AddressTrieOps.remove(Address)
, not requiring a match to an inserted node, and also removing all the sub-nodes of any removed node or sub-node.For example, after inserting 1.2.3.0 and 1.2.3.1, passing 1.2.3.0/31 to
AddressTrieOps.removeElementsContainedBy(Address)
will remove them both, whileAddressTrieOps.remove(Address)
will remove nothing. After inserting 1.2.3.0/31, then #remove(Address) will remove 1.2.3.0/31, but will leave 1.2.3.0 and 1.2.3.1 in the trie.It cannot partially delete a node, such as deleting a single address from a prefix block represented by a node. It can only delete the whole node if the whole address or block represented by that node is contained in the given address or block.
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns the root node of the subtrie that was removed from the trie, or null if nothing was removed.
- Specified by:
removeElementsContainedBy
in interfaceAddressTrieOps<K extends Address>
- Overrides:
removeElementsContainedBy
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
elementsContainedBy
Description copied from interface:AddressTrieOps
Checks if a part of this trie is contained by the given prefix block subnet or individual address.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns the root node of the contained subtrie, or null if no subtrie is contained. The node returned need not be an "added" node, see
BinaryTreeNode.isAdded()
for more details on added nodes. The returned subtrie is backed by this trie, so changes in this trie are reflected in those nodes and vice-versa.- Specified by:
elementsContainedBy
in interfaceAddressTrieOps<K extends Address>
- Overrides:
elementsContainedBy
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
elementsContaining
Description copied from interface:AddressTrieOps
Finds the added subnets and/or addresses in the trie that contain the given individual address or prefix block subnet.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns a list of the nodes for prefix block subnets and addresses from the trie that contain the address or block. The list consists only of added nodes, see
BinaryTreeNode.isAdded()
for more details on added nodes. The list is constructed as a trie in which each parent node has only one sub-node.Use
AddressTrieOps.elementContains(Address)
to check for the existence of a containing address.- Specified by:
elementsContaining
in interfaceAddressTrieOps<K extends Address>
- Overrides:
elementsContaining
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
longestPrefixMatchNode
Description copied from interface:AddressTrieOps
Finds the containing subnet or address in the trie with the smallest subnet size, which is equivalent to finding the subnet or address with the longest matching prefix. Returns the node corresponding to that subnet.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
If not a single address nor prefix block, the
Partition
class can be used to convert the address before calling this method. SeeAddressTrieOps.AddressTrieAddOps.add(Address)
for more details.Returns null if no added subnet or address contains the given argument.
Use
AddressTrieOps.elementContains(Address)
to check for the existence of a containing address.
To get all the containing addresses, useAddressTrieOps.elementsContaining(Address)
.
UseAddressTrieOps.longestPrefixMatch(Address)
to get the address corresponding to the result of this method.- Specified by:
longestPrefixMatchNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
longestPrefixMatchNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
asMap
Returns a java.util.NavigableMap backed by this associative trie. The added elements of this trie are keys for the map, the associated values are the map values.- Returns:
-
nodeIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> nodeIterator(boolean forward) Description copied from interface:TreeOps
Iterates through the added nodes in forward or reverse natural tree order.This iterator supports the
Iterator.remove()
operation.See
TreeOps
for more details on the ordering.- Specified by:
nodeIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
nodeIterator
in interfaceTreeOps<K extends Address>
- Overrides:
nodeIterator
in classAddressTrie<K extends Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
allNodeIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> allNodeIterator(boolean forward) Description copied from interface:TreeOps
Iterates through the nodes (not just the added nodes) in forward or reverse tree order.See
TreeOps
for more details on the ordering. This iterator supports theIterator.remove()
operation.- Specified by:
allNodeIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
allNodeIterator
in interfaceTreeOps<K extends Address>
- Overrides:
allNodeIterator
in classAddressTrie<K extends Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
blockSizeCachingAllNodeIterator
public <C> BinaryTreeNode.CachingIterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>, blockSizeCachingAllNodeIterator()K, C> Description copied from class:AddressTrie
Iterates all nodes, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.This iterator supports the
Iterator.remove()
operation.- Overrides:
blockSizeCachingAllNodeIterator
in classAddressTrie<K extends Address>
- Returns:
-
blockSizeNodeIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> blockSizeNodeIterator(boolean lowerSubNodeFirst) Description copied from class:AddressTrie
Iterates the added nodes in the trie, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.This iterator supports the
Iterator.remove()
operation.- Overrides:
blockSizeNodeIterator
in classAddressTrie<K extends Address>
- Parameters:
lowerSubNodeFirst
- if true, for blocks of equal size the lower is first, otherwise the reverse order- Returns:
-
blockSizeAllNodeIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> blockSizeAllNodeIterator(boolean lowerSubNodeFirst) Description copied from class:AddressTrie
Iterates all nodes in the trie, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.This iterator supports the
Iterator.remove()
operation.- Overrides:
blockSizeAllNodeIterator
in classAddressTrie<K extends Address>
- Parameters:
lowerSubNodeFirst
- if true, for blocks of equal size the lower is first, otherwise the reverse order- Returns:
-
containingFirstIterator
public <C> BinaryTreeNode.CachingIterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>, containingFirstIteratorK, C> (boolean lowerSubNodeFirst) Description copied from interface:TreeOps
Returns an iterator that does a pre-order binary tree traversal of the added nodes. All added nodes will be visited before their added sub-nodes. For an address trie this means added containing subnet blocks will be visited before their added contained addresses and subnet blocks.This iterator supports the
Iterator.remove()
operation.Once a given node is visited, the iterator allows you to cache an object corresponding to the lower or upper sub-node that can be retrieved when you later visit that sub-node.
Objects are cached only with nodes to be visited. So for this iterator that means an object will be cached with the first added lower or upper sub-node, the next lower or upper sub-node to be visited, which is not necessarily the direct lower or upper sub-node of a given node.
The caching allows you to provide iteration context from a parent to its sub-nodes when iterating. The caching and retrieval is done in constant-time and linear space (proportional to tree size).
See
TreeOps
for more details on the ordering.- Specified by:
containingFirstIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
containingFirstIterator
in interfaceTreeOps<K extends Address>
- Overrides:
containingFirstIterator
in classAddressTrie<K extends Address>
- Parameters:
lowerSubNodeFirst
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
containingFirstAllNodeIterator
public <C> BinaryTreeNode.CachingIterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>, containingFirstAllNodeIteratorK, C> (boolean lowerSubNodeFirst) Description copied from interface:TreeOps
Returns an iterator that does a pre-order binary tree traversal. All nodes will be visited before their sub-nodes. For an address trie this means containing subnet blocks will be visited before their contained addresses and subnet blocks.This iterator supports the
Iterator.remove()
operation.Once a given node is visited, the iterator allows you to cache an object corresponding to the lower or upper sub-node that can be retrieved when you later visit that sub-node. That allows you to provide iteration context from a parent to its sub-nodes when iterating. The caching and retrieval is done in constant-time and linear space (proportional to tree size).
Here is an example showing usage of the caching. Consider this recursive code doing a pre-order traversal:
The following iterative code provides the same functionality:IPv6AddressTrie ipv6Tree = ...; visitRecursive(ipv6Tree.getRoot(), null); static <E> void visitRecursive(BinaryTreeNode<E> node, String direction) { if(direction == null) { direction = "root"; } System.out.println("visited " + direction + " " + node); BinaryTreeNode<E> sub = node.getLowerSubNode(); if(sub != null) { visitRecursive(sub, direction + " left"); } sub = node.getUpperSubNode(); if(sub != null) { visitRecursive(sub, direction + " right"); } }
visitIterative(ipv6Tree.getRoot()); static <E> void visitIterative(BinaryTreeNode<E> node) { CachingIterator<? extends BinaryTreeNode<E>, E, String>iterator = node.containingFirstAllNodeIterator(true); while(iterator.hasNext()) { BinaryTreeNode<E> next = iterator.next(); String direction = iterator.getCached(); if(direction == null) { direction = "root"; } System.out.println("visited " + direction + " " + next); iterator.cacheWithLowerSubNode(direction + " left"); iterator.cacheWithUpperSubNode(direction + " right"); } }
See
TreeOps
for more details on the ordering.- Specified by:
containingFirstAllNodeIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
containingFirstAllNodeIterator
in interfaceTreeOps<K extends Address>
- Overrides:
containingFirstAllNodeIterator
in classAddressTrie<K extends Address>
- Parameters:
lowerSubNodeFirst
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
containedFirstIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> containedFirstIterator(boolean forwardSubNodeOrder) Description copied from interface:TreeOps
Returns an iterator that does a post-order binary tree traversal of the added nodes. All added sub-nodes will be visited before their parent nodes. For an address trie this means contained addresses and subnets will be visited before their containing subnet blocks.This iterator supports the
Iterator.remove()
operation.See
TreeOps
for more details on the ordering.- Specified by:
containedFirstIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
containedFirstIterator
in interfaceTreeOps<K extends Address>
- Overrides:
containedFirstIterator
in classAddressTrie<K extends Address>
- Parameters:
forwardSubNodeOrder
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
containedFirstAllNodeIterator
public Iterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> containedFirstAllNodeIterator(boolean forwardSubNodeOrder) Description copied from interface:TreeOps
Returns an iterator that does a post-order binary tree traversal. All sub-nodes will be visited before their parent nodes. For an address trie this means contained addresses and subnets will be visited before their containing subnet blocks.This iterator does not support the
Iterator.remove()
operation. IfIterator.remove()
is called it will throwUnsupportedOperationException
.See
TreeOps
for more details on the ordering.- Specified by:
containedFirstAllNodeIterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
containedFirstAllNodeIterator
in interfaceTreeOps<K extends Address>
- Overrides:
containedFirstAllNodeIterator
in classAddressTrie<K extends Address>
- Parameters:
forwardSubNodeOrder
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
nodeSpliterator
public Spliterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> nodeSpliterator(boolean forward) Description copied from interface:TreeOps
Creates aSpliterator
over the added nodes in forward or reverse natural tree order.See
TreeOps
for more details on the ordering.- Specified by:
nodeSpliterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
nodeSpliterator
in interfaceTreeOps<K extends Address>
- Overrides:
nodeSpliterator
in classAddressTrie<K extends Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
allNodeSpliterator
public Spliterator<? extends AssociativeAddressTrie.AssociativeTrieNode<K,V>> allNodeSpliterator(boolean forward) Description copied from interface:TreeOps
Creates aSpliterator
over the nodes in forward or reverse natural tree order.See
TreeOps
for more details on the ordering.- Specified by:
allNodeSpliterator
in interfaceAddressTrieOps<K extends Address>
- Specified by:
allNodeSpliterator
in interfaceTreeOps<K extends Address>
- Overrides:
allNodeSpliterator
in classAddressTrie<K extends Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
firstNode
Description copied from interface:AddressTrieOps
Returns the node with the first (lowest valued) key, whether the node is added or not- Specified by:
firstNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
firstNode
in classAddressTrie<K extends Address>
- Returns:
-
lastNode
Description copied from interface:AddressTrieOps
Returns the node with the last (highest valued) key, whether the node is added or not- Specified by:
lastNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
lastNode
in classAddressTrie<K extends Address>
- Returns:
-
firstAddedNode
Description copied from interface:AddressTrieOps
Returns the added node with the first (lowest valued) key, or null if there are no added entries in this trie or subtrie- Specified by:
firstAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
firstAddedNode
in classAddressTrie<K extends Address>
- Returns:
-
lastAddedNode
Description copied from interface:AddressTrieOps
Returns the added node with the last (highest valued) key, or null if there are no added elements in this trie or subtrie- Specified by:
lastAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
lastAddedNode
in classAddressTrie<K extends Address>
- Returns:
-
lowerAddedNode
Description copied from interface:AddressTrieOps
Returns the added node whose address is the highest address strictly less than the given address.- Specified by:
lowerAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
lowerAddedNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
floorAddedNode
Description copied from interface:AddressTrieOps
Returns the added node whose address is the highest address less than or equal to the given address.- Specified by:
floorAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
floorAddedNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
higherAddedNode
Description copied from interface:AddressTrieOps
Returns the added node whose address is the lowest address strictly greater than the given address.- Specified by:
higherAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
higherAddedNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
ceilingAddedNode
Description copied from interface:AddressTrieOps
Returns the added node whose address is the lowest address greater than or equal to the given address.- Specified by:
ceilingAddedNode
in interfaceAddressTrieOps<K extends Address>
- Overrides:
ceilingAddedNode
in classAddressTrie<K extends Address>
- Parameters:
addr
-- Returns:
-
clone
Copies the trie, but not the keys or values.- Overrides:
clone
in classAddressTrie<K extends Address>
-
equals
Description copied from class:AddressTrie
Returns whether the given argument is a trie with a set of nodes that equal the set of nodes in this trie- Overrides:
equals
in classAddressTrie<K extends Address>
-
iterator
Description copied from interface:TreeOps
Traverses the added node keys in natural tree order.See
TreeOps
for more details on the ordering. -
descendingIterator
Description copied from interface:TreeOps
Traverses the added node keys in reverse natural tree order.See
TreeOps
for more details on the ordering.- Specified by:
descendingIterator
in interfaceTreeOps<E extends Address>
- Returns:
-
hashCode
public int hashCode()
-