public class IPv4AddressTrie extends AddressTrie<IPv4Address>
AddressTrie for more details.| Modifier and Type | Class and Description |
|---|---|
static class |
IPv4AddressTrie.IPv4TrieNode |
AddressTrie.AddressComparator<E extends Address>, AddressTrie.TrieComparator<E extends Address>, AddressTrie.TrieNode<E extends Address>AddressTrieOps.AddressTrieAddOps<E extends Address>, AddressTrieOps.AssociativeAddressTrieOps<K extends Address,V>, AddressTrieOps.AssociativeAddressTriePutOps<K extends Address,V>| Constructor and Description |
|---|
IPv4AddressTrie() |
| Modifier and Type | Method and Description |
|---|---|
IPv4AddressTrie.IPv4TrieNode |
addNode(IPv4Address addr)
Adds the given single address or prefix block subnet to the trie, if not already there.
|
IPv4AddressTrie.IPv4TrieNode |
addTrie(AddressTrie.TrieNode<IPv4Address> trie)
Adds nodes matching the given sub-root node and all of its sub-nodes to the trie, if not already there.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
allNodeIterator(boolean forward)
Iterates through the nodes (not just the added nodes) in forward or reverse tree order.
|
Spliterator<IPv4AddressTrie.IPv4TrieNode> |
allNodeSpliterator(boolean forward)
Creates a
Spliterator over the nodes in forward or reverse natural tree order. |
Iterator<IPv4AddressTrie.IPv4TrieNode> |
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<IPv4AddressTrie.IPv4TrieNode,IPv4Address,C> |
blockSizeCachingAllNodeIterator()
Iterates all nodes, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
blockSizeNodeIterator(boolean lowerSubNodeFirst)
Iterates the added nodes in the trie, ordered by keys from largest prefix blocks to smallest, and then to individual addresses.
|
IPv4AddressTrie.IPv4TrieNode |
ceilingAddedNode(IPv4Address addr)
Returns the added node whose address is the lowest address greater than or equal to the given address.
|
IPv4AddressTrie |
clone()
Copies the trie, but not the keys or values.
|
AddedTree<IPv4Address> |
constructAddedNodesTree()
Provides an associative trie in which the root and each added node are mapped to a list of their respective direct added nodes.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
containedFirstAllNodeIterator(boolean forwardSubNodeOrder)
Returns an iterator that does a post-order binary tree traversal.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
containedFirstIterator(boolean forwardSubNodeOrder)
Returns an iterator that does a post-order binary tree traversal of the added nodes.
|
<C> BinaryTreeNode.CachingIterator<IPv4AddressTrie.IPv4TrieNode,IPv4Address,C> |
containingFirstAllNodeIterator(boolean forwardSubNodeOrder)
Returns an iterator that does a pre-order binary tree traversal.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
containingFirstIterator(boolean forwardSubNodeOrder)
Returns an iterator that does a pre-order binary tree traversal of the added nodes.
|
Iterator<E> |
descendingIterator()
Traverses the added node keys in reverse natural tree order.
|
IPv4AddressTrie.IPv4TrieNode |
elementsContainedBy(IPv4Address addr)
Checks if a part of this trie is contained by the given prefix block subnet or individual address.
|
IPv4AddressTrie.IPv4TrieNode |
elementsContaining(IPv4Address addr)
Finds the added subnets and/or addresses in the trie that contain the given individual address or prefix block subnet.
|
boolean |
equals(Object o)
Returns whether the given argument is a trie with a set of nodes that equal the set of nodes in this trie
|
IPv4AddressTrie.IPv4TrieNode |
firstNode()
Returns the node with the first (lowest valued) key, whether the node is added or not
|
IPv4AddressTrie.IPv4TrieNode |
floorAddedNode(IPv4Address addr)
Returns the added node whose address is the highest address less than or equal to the given address.
|
IPv4AddressTrie.IPv4TrieNode |
getAddedNode(IPv4Address addr)
Gets trie nodes representing added elements.
|
IPv4AddressTrie.IPv4TrieNode |
getNode(IPv4Address addr)
Gets the node corresponding to the given address, returns null if not such element exists.
|
IPv4AddressTrie.IPv4TrieNode |
getRoot()
Returns the root of this trie
|
int |
hashCode() |
IPv4AddressTrie.IPv4TrieNode |
higherAddedNode(IPv4Address addr)
Returns the added node whose address is the lowest address strictly greater than the given address.
|
Iterator<E> |
iterator()
Traverses the added node keys in natural tree order.
|
IPv4AddressTrie.IPv4TrieNode |
lastNode()
Returns the node with the last (highest valued) key, whether the node is added or not
|
IPv4AddressTrie.IPv4TrieNode |
longestPrefixMatchNode(IPv4Address 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.
|
IPv4AddressTrie.IPv4TrieNode |
lowerAddedNode(IPv4Address addr)
Returns the added node whose address is the highest address strictly less than the given address.
|
Iterator<IPv4AddressTrie.IPv4TrieNode> |
nodeIterator(boolean forward)
Iterates through the added nodes in forward or reverse natural tree order.
|
Spliterator<IPv4AddressTrie.IPv4TrieNode> |
nodeSpliterator(boolean forward)
Creates a
Spliterator over the added nodes in forward or reverse natural tree order. |
IPv4AddressTrie.IPv4TrieNode |
removeElementsContainedBy(IPv4Address addr)
Removes any single address or prefix block subnet from the trie that is contained in the given individual address or prefix block subnet.
|
String |
toAddedNodesTreeString()
Provides a flattened version of the trie showing only the contained added nodes and their containment structure, which is non-binary.
|
add, asSet, ceiling, clear, contains, decrement, descendingSpliterator, elementContains, firstAddedNode, floor, getComparator, higher, increment, isEmpty, lastAddedNode, longestPrefixMatch, lower, nodeSize, remove, shortestPrefixMatch, shortestPrefixMatchNode, size, spliterator, toString, toString, toStringpublic IPv4AddressTrie.IPv4TrieNode getRoot()
getRoot in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode removeElementsContainedBy(IPv4Address addr)
AddressTrieOps
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,
while AddressTrieOps.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.
See AddressTrieOps.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.
removeElementsContainedBy in interface AddressTrieOps<IPv4Address>removeElementsContainedBy in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode elementsContainedBy(IPv4Address addr)
AddressTrieOpsIf 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.
See AddressTrieOps.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.
elementsContainedBy in interface AddressTrieOps<IPv4Address>elementsContainedBy in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode elementsContaining(IPv4Address addr)
AddressTrieOpsIf 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.
See AddressTrieOps.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.
elementsContaining in interface AddressTrieOps<IPv4Address>elementsContaining in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode longestPrefixMatchNode(IPv4Address addr)
AddressTrieOpsIf 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.
See AddressTrieOps.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, use AddressTrieOps.elementsContaining(Address).
Use AddressTrieOps.longestPrefixMatch(Address) to get the address corresponding to the result of this method.
longestPrefixMatchNode in interface AddressTrieOps<IPv4Address>longestPrefixMatchNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode getAddedNode(IPv4Address addr)
AddressTrieOps
Use AddressTrieOps.contains(Address) to check for the existence of a given address in the trie,
as well as AddressTrieOps.getNode(Address) to search for all nodes including those not-added but also auto-generated nodes for subnet blocks.
public IPv4AddressTrie.IPv4TrieNode getNode(IPv4Address addr)
AddressTrieOpsIf 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.
See AddressTrieOps.AddressTrieAddOps.add(Address) for more details.
getNode in interface AddressTrieOps<IPv4Address>getNode in class AddressTrie<IPv4Address>AddressTrieOps.contains(Address)public IPv4AddressTrie.IPv4TrieNode addNode(IPv4Address addr)
AddressTrieOps.AddressTrieAddOpsIf 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.
See AddressTrieOps.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 use AddressTrieOps.getAddedNode(Address)
addNode in interface AddressTrieOps.AddressTrieAddOps<IPv4Address>addNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode addTrie(AddressTrie.TrieNode<IPv4Address> trie)
AddressTrieOps.AddressTrieAddOpsFor 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), 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.
You can add associative nodes to tries with this method but associated values will all be null.
If you want to preserve the values, use AssociativeAddressTriePutOps#putTrie(AssociativeTrieNode) instead.
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.
addTrie in interface AddressTrieOps.AddressTrieAddOps<IPv4Address>addTrie in class AddressTrie<IPv4Address>public Iterator<IPv4AddressTrie.IPv4TrieNode> nodeIterator(boolean forward)
TreeOps
This iterator supports the Iterator.remove() operation.
See TreeOps for more details on the ordering.
nodeIterator in interface AddressTrieOps<IPv4Address>nodeIterator in interface TreeOps<IPv4Address>nodeIterator in class AddressTrie<IPv4Address>forward - if true, goes in ascending order, otherwise descendingpublic Iterator<IPv4AddressTrie.IPv4TrieNode> allNodeIterator(boolean forward)
TreeOps
See TreeOps for more details on the ordering.
This iterator supports the Iterator.remove() operation.
allNodeIterator in interface AddressTrieOps<IPv4Address>allNodeIterator in interface TreeOps<IPv4Address>allNodeIterator in class AddressTrie<IPv4Address>forward - if true, goes in ascending order, otherwise descendingpublic Iterator<IPv4AddressTrie.IPv4TrieNode> blockSizeNodeIterator(boolean lowerSubNodeFirst)
AddressTrie
This iterator supports the Iterator.remove() operation.
blockSizeNodeIterator in class AddressTrie<IPv4Address>lowerSubNodeFirst - if true, for blocks of equal size the lower is first, otherwise the reverse orderpublic Iterator<IPv4AddressTrie.IPv4TrieNode> blockSizeAllNodeIterator(boolean lowerSubNodeFirst)
AddressTrie
This iterator supports the Iterator.remove() operation.
blockSizeAllNodeIterator in class AddressTrie<IPv4Address>lowerSubNodeFirst - if true, for blocks of equal size the lower is first, otherwise the reverse orderpublic <C> BinaryTreeNode.CachingIterator<IPv4AddressTrie.IPv4TrieNode,IPv4Address,C> blockSizeCachingAllNodeIterator()
AddressTrie
This iterator supports the Iterator.remove() operation.
blockSizeCachingAllNodeIterator in class AddressTrie<IPv4Address>public Iterator<IPv4AddressTrie.IPv4TrieNode> containingFirstIterator(boolean forwardSubNodeOrder)
TreeOps
This iterator supports the Iterator.remove() operation.
See the docs for TreeOps for more details on the ordering.
containingFirstIterator in interface AddressTrieOps<IPv4Address>containingFirstIterator in interface TreeOps<IPv4Address>containingFirstIterator in class AddressTrie<IPv4Address>forwardSubNodeOrder - if true, a left sub-node will be visited before the right sub-node of the same parent node.public <C> BinaryTreeNode.CachingIterator<IPv4AddressTrie.IPv4TrieNode,IPv4Address,C> containingFirstAllNodeIterator(boolean forwardSubNodeOrder)
TreeOps
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:
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");
}
}
The following iterative code provides the same functionality:
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.
containingFirstAllNodeIterator in interface AddressTrieOps<IPv4Address>containingFirstAllNodeIterator in interface TreeOps<IPv4Address>containingFirstAllNodeIterator in class AddressTrie<IPv4Address>forwardSubNodeOrder - if true, a left sub-node will be visited before the right sub-node of the same parent node.public Iterator<IPv4AddressTrie.IPv4TrieNode> containedFirstIterator(boolean forwardSubNodeOrder)
TreeOps
This iterator supports the Iterator.remove() operation.
See TreeOps for more details on the ordering.
containedFirstIterator in interface AddressTrieOps<IPv4Address>containedFirstIterator in interface TreeOps<IPv4Address>containedFirstIterator in class AddressTrie<IPv4Address>forwardSubNodeOrder - if true, a left sub-node will be visited before the right sub-node of the same parent node.public Iterator<IPv4AddressTrie.IPv4TrieNode> containedFirstAllNodeIterator(boolean forwardSubNodeOrder)
TreeOps
This iterator does not support the Iterator.remove() operation.
If Iterator.remove() is called it will throw UnsupportedOperationException.
See TreeOps for more details on the ordering.
containedFirstAllNodeIterator in interface AddressTrieOps<IPv4Address>containedFirstAllNodeIterator in interface TreeOps<IPv4Address>containedFirstAllNodeIterator in class AddressTrie<IPv4Address>forwardSubNodeOrder - if true, a left sub-node will be visited before the right sub-node of the same parent node.public Spliterator<IPv4AddressTrie.IPv4TrieNode> nodeSpliterator(boolean forward)
TreeOpsSpliterator over the added nodes in forward or reverse natural tree order.
See TreeOps for more details on the ordering.
nodeSpliterator in interface AddressTrieOps<IPv4Address>nodeSpliterator in interface TreeOps<IPv4Address>nodeSpliterator in class AddressTrie<IPv4Address>forward - if true, goes in ascending order, otherwise descendingpublic Spliterator<IPv4AddressTrie.IPv4TrieNode> allNodeSpliterator(boolean forward)
TreeOpsSpliterator over the nodes in forward or reverse natural tree order.
See TreeOps for more details on the ordering.
allNodeSpliterator in interface AddressTrieOps<IPv4Address>allNodeSpliterator in interface TreeOps<IPv4Address>allNodeSpliterator in class AddressTrie<IPv4Address>forward - if true, goes in ascending order, otherwise descendingpublic IPv4AddressTrie.IPv4TrieNode lowerAddedNode(IPv4Address addr)
AddressTrieOpslowerAddedNode in interface AddressTrieOps<IPv4Address>lowerAddedNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode floorAddedNode(IPv4Address addr)
AddressTrieOpsfloorAddedNode in interface AddressTrieOps<IPv4Address>floorAddedNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode higherAddedNode(IPv4Address addr)
AddressTrieOpshigherAddedNode in interface AddressTrieOps<IPv4Address>higherAddedNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode ceilingAddedNode(IPv4Address addr)
AddressTrieOpsceilingAddedNode in interface AddressTrieOps<IPv4Address>ceilingAddedNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode firstNode()
AddressTrieOpsfirstNode in interface AddressTrieOps<IPv4Address>firstNode in class AddressTrie<IPv4Address>public IPv4AddressTrie.IPv4TrieNode lastNode()
AddressTrieOpslastNode in interface AddressTrieOps<IPv4Address>lastNode in class AddressTrie<IPv4Address>public IPv4AddressTrie clone()
clone in class AddressTrie<IPv4Address>public boolean equals(Object o)
AddressTrieequals in class AddressTrie<IPv4Address>public AddedTree<IPv4Address> constructAddedNodesTree()
AddressTrieAddressTrie.toAddedNodesTreeString() to produce a string showing the alternative structure.
If there are no non-added nodes in this trie, then the alternative tree structure provided by this method is the same as the original trie.constructAddedNodesTree in class AddressTrie<IPv4Address>public String toAddedNodesTreeString()
AddressTrietoAddedNodesTreeString in class AddressTrie<IPv4Address>public Iterator<E> iterator()
TreeOps
This iterator supports the Iterator.remove() operation.
See TreeOps for more details on the ordering.
public Iterator<E> descendingIterator()
TreeOps
This iterator supports the Iterator.remove() operation.
See TreeOps for more details on the ordering.
descendingIterator in interface TreeOps<E extends Address>