- All Implemented Interfaces:
AddressTrieOps<IPv6Address>
,TreeOps<IPv6Address>
,Serializable
,Cloneable
,Iterable<IPv6Address>
- Enclosing class:
IPv6AddressTrie
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class inet.ipaddr.format.util.BinaryTreeNode
BinaryTreeNode.CachingIterator<N extends BinaryTreeNode<E>,
E, C> 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallNodeIterator
(boolean forward) Iterates through all the nodes of the sub-tree with this node as the root, in forward or reverse tree order.allNodeSpliterator
(boolean forward) Creates aSpliterator
over the nodes in forward or reverse natural tree order.Creates a new sub-trie, copying the nodes starting with this node as root.blockSizeAllNodeIterator
(boolean lowerSubNodeFirst) Iterates all the nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.Iterates all nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.blockSizeNodeIterator
(boolean lowerSubNodeFirst) Iterates the added nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.ceilingAddedNode
(IPv6Address addr) Returns the added node whose address is the lowest address greater than or equal to the given address.clone()
Clones the node.Clones the sub-tree starting with this node as root.containedFirstAllNodeIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a post-order binary tree traversal.containedFirstIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a post-order binary tree traversal of the added nodes.containingFirstAllNodeIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a pre-order binary tree traversal.containingFirstIterator
(boolean forwardSubNodeOrder) Returns an iterator that does a pre-order binary tree traversal of the added nodes.Checks if a part of this trie is contained by the given prefix block subnet or individual address.Finds the added subnets and/or addresses in the trie that contain the given individual address or prefix block subnet.boolean
Returns whether the key values match those of the given nodeReturns the first (lowest valued) added node in the sub-tree originating from this node, or null if there are no added entries in this tree or sub-treeReturns the first (lowest valued) node in the sub-tree originating from this node.floorAddedNode
(IPv6Address addr) Returns the added node whose address is the highest address less than or equal to the given address.getAddedNode
(IPv6Address addr) Gets trie nodes representing added elements.Returns the sub node whose address is smallest in valuegetNode
(IPv6Address addr) Gets the node corresponding to the given address, returns null if not such element exists.Returns the node for the subnet block containing this node.Returns the sub-node whose address is largest in valuehigherAddedNode
(IPv6Address addr) Returns the added node whose address is the lowest address strictly greater than the given address.Returns the last (highest valued) added node in the sub-tree originating from this node, or null if there are no added entries in this tree or sub-treelastNode()
Returns the last (highest valued) node in the sub-tree originating from this node.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
(IPv6Address addr) Returns the added node whose address is the highest address strictly less than the given address.Returns the next node in the tree that is an added node, following the tree order, or null if there is no such node.nextNode()
Returns the node that follows this node following the tree ordernodeIterator
(boolean forward) Iterates through the added nodes of the sub-tree with this node as the root, in forward or reverse tree order.nodeSpliterator
(boolean forward) Creates aSpliterator
over the added nodes in forward or reverse natural tree order.Returns the previous node in the tree that is an added node, following the tree order in reverse, or null if there is no such node.Returns the node that precedes this node following the tree order.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.TrieNode
contains, descendingSpliterator, elementContains, longestPrefixMatch, remove, spliterator
Methods inherited from class inet.ipaddr.format.util.BinaryTreeNode
clear, descendingIterator, getKey, hashCode, isAdded, isEmpty, isLeaf, isRoot, iterator, nodeSize, remove, setAdded, size, toString, toTreeString, treeEquals, treeHashCode
Methods inherited from interface inet.ipaddr.format.util.TreeOps
descendingIterator, iterator
-
Constructor Details
-
IPv6TrieNode
public IPv6TrieNode()
-
-
Method Details
-
getUpperSubNode
Description copied from class:AddressTrie.TrieNode
Returns the sub-node whose address is largest in value- Overrides:
getUpperSubNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
getLowerSubNode
Description copied from class:AddressTrie.TrieNode
Returns the sub node whose address is smallest in value- Overrides:
getLowerSubNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
getParent
Description copied from class:AddressTrie.TrieNode
Returns the node for the subnet block containing this node.- Overrides:
getParent
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
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<IPv6Address>
- Overrides:
removeElementsContainedBy
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
elementsContainedBy
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
elementsContaining
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
longestPrefixMatchNode
in classAddressTrie.TrieNode<IPv6Address>
- 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.- 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<IPv6Address>
- Overrides:
getNode
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
addr
-- Returns:
- See Also:
-
nodeIterator
Description copied from class:BinaryTreeNode
Iterates through the added nodes of the sub-tree with this node as the root, in forward or reverse tree order.- Specified by:
nodeIterator
in interfaceAddressTrieOps<IPv6Address>
- Specified by:
nodeIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
nodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
allNodeIterator
Description copied from class:BinaryTreeNode
Iterates through all the nodes of the sub-tree with this node as the root, in forward or reverse tree order.- Specified by:
allNodeIterator
in interfaceAddressTrieOps<IPv6Address>
- Specified by:
allNodeIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
allNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
blockSizeNodeIterator
Description copied from class:AddressTrie.TrieNode
Iterates the added nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.This iterator supports the
Iterator.remove()
operation.- Overrides:
blockSizeNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
lowerSubNodeFirst
- if true, for blocks of equal size the lower is first, otherwise the reverse order- Returns:
-
blockSizeAllNodeIterator
Description copied from class:AddressTrie.TrieNode
Iterates all the nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.This iterator supports the
Iterator.remove()
operation.- Overrides:
blockSizeAllNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
lowerSubNodeFirst
- if true, for blocks of equal size the lower is first, otherwise the reverse order- Returns:
-
blockSizeCachingAllNodeIterator
public <C> BinaryTreeNode.CachingIterator<IPv6AddressTrie.IPv6TrieNode,IPv6Address, blockSizeCachingAllNodeIterator()C> Description copied from class:AddressTrie.TrieNode
Iterates all nodes, ordered by keys from largest prefix blocks to smallest and then to individual addresses, in the sub-trie with this node as the root.- Overrides:
blockSizeCachingAllNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
containingFirstIterator
public <C> BinaryTreeNode.CachingIterator<IPv6AddressTrie.IPv6TrieNode,IPv6Address, containingFirstIteratorC> (boolean forwardSubNodeOrder) 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<IPv6Address>
- Specified by:
containingFirstIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
containingFirstIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forwardSubNodeOrder
- 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<IPv6AddressTrie.IPv6TrieNode,IPv6Address, containingFirstAllNodeIteratorC> (boolean forwardSubNodeOrder) 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<IPv6Address>
- Specified by:
containingFirstAllNodeIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
containingFirstAllNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forwardSubNodeOrder
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
containedFirstIterator
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<IPv6Address>
- Specified by:
containedFirstIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
containedFirstIterator
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6AddressTrie.IPv6TrieNode> 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<IPv6Address>
- Specified by:
containedFirstAllNodeIterator
in interfaceTreeOps<IPv6Address>
- Overrides:
containedFirstAllNodeIterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forwardSubNodeOrder
- if true, a left sub-node will be visited before the right sub-node of the same parent node.- Returns:
-
nodeSpliterator
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<IPv6Address>
- Specified by:
nodeSpliterator
in interfaceTreeOps<IPv6Address>
- Overrides:
nodeSpliterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
allNodeSpliterator
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<IPv6Address>
- Specified by:
allNodeSpliterator
in interfaceTreeOps<IPv6Address>
- Overrides:
allNodeSpliterator
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
forward
- if true, goes in ascending order, otherwise descending- Returns:
-
previousAddedNode
Description copied from class:BinaryTreeNode
Returns the previous node in the tree that is an added node, following the tree order in reverse, or null if there is no such node.- Overrides:
previousAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
nextAddedNode
Description copied from class:BinaryTreeNode
Returns the next node in the tree that is an added node, following the tree order, or null if there is no such node.- Overrides:
nextAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
nextNode
Description copied from class:BinaryTreeNode
Returns the node that follows this node following the tree order- Overrides:
nextNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
previousNode
Description copied from class:BinaryTreeNode
Returns the node that precedes this node following the tree order.- Overrides:
previousNode
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
lowerAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
floorAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
higherAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- 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<IPv6Address>
- Overrides:
ceilingAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- Parameters:
addr
-- Returns:
-
firstNode
Description copied from class:BinaryTreeNode
Returns the first (lowest valued) node in the sub-tree originating from this node.- Specified by:
firstNode
in interfaceAddressTrieOps<IPv6Address>
- Overrides:
firstNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
lastNode
Description copied from class:BinaryTreeNode
Returns the last (highest valued) node in the sub-tree originating from this node.- Specified by:
lastNode
in interfaceAddressTrieOps<IPv6Address>
- Overrides:
lastNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
firstAddedNode
Description copied from class:BinaryTreeNode
Returns the first (lowest valued) added node in the sub-tree originating from this node, or null if there are no added entries in this tree or sub-tree- Specified by:
firstAddedNode
in interfaceAddressTrieOps<IPv6Address>
- Overrides:
firstAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
lastAddedNode
Description copied from class:BinaryTreeNode
Returns the last (highest valued) added node in the sub-tree originating from this node, or null if there are no added entries in this tree or sub-tree- Specified by:
lastAddedNode
in interfaceAddressTrieOps<IPv6Address>
- Overrides:
lastAddedNode
in classAddressTrie.TrieNode<IPv6Address>
- Returns:
-
asNewTrie
Description copied from class:AddressTrie.TrieNode
Creates a new sub-trie, copying the nodes starting with this node as root. The nodes are copies of the nodes in this sub-trie, but their keys and values are not copies.- Overrides:
asNewTrie
in classAddressTrie.TrieNode<IPv6Address>
-
cloneTree
Description copied from class:BinaryTreeNode
Clones the sub-tree starting with this node as root. The nodes are cloned, but their keys and values are not cloned.- Overrides:
cloneTree
in classAddressTrie.TrieNode<IPv6Address>
-
clone
Description copied from class:BinaryTreeNode
Clones the node. Keys remain the same, but the parent node and the lower and upper sub-nodes are all set to null.- Overrides:
clone
in classAddressTrie.TrieNode<IPv6Address>
-
equals
Description copied from class:BinaryTreeNode
Returns whether the key values match those of the given node- Overrides:
equals
in classAddressTrie.TrieNode<IPv6Address>
-