Class RadixTrie<T>
java.lang.Object
org.opendaylight.lispflowmapping.inmemorydb.radixtrie.RadixTrie<T>
- Type Parameters:
T
- Data type stored in each tree node
Radix trie/tree (also known as Patricia tree) implementation. Supports CRD operations for
generic, big endian (network byte order) prefixes. It can do exact and longest prefix matching,
post order iteration over the entries in the tree and can lookup widest negative prefixes (i.e.,
shortest overlapping prefix not registered in the tree).
- Author:
- Florin Coras
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
getRoot()
long
getSize()
Insert prefix-data tuple into radix trie.lookupBest
(byte[] prefix, int preflen) Longest prefix match of prefix/preflen.lookupCoveringLessSpecific
(byte[] prefix, int preflen) Look up the covering prefix for the argument, but exclude the argument itself, so the result is always less specific than the lookup key.lookupExact
(byte[] prefix, int preflen) Exact prefix match of prefix/preflen.lookupParent
(byte[] prefix, int preflen) Given an EID, lookup the longest prefix match, then return its parent node.lookupSibling
(byte[] prefix, int preflen) Given an EID, lookup the longest prefix match, then return its sibling node.lookupSubtree
(byte[] prefix, int preflen) Return the subtree for a prefix, including the prefix itself if present, excluding virtual nodes.lookupVirtualParentSibling
(byte[] prefix, int preflen) Given an EID, lookup the longest prefix match, then return its direct parent's sibling node, if the parent is a virtual node.lookupWidestNegative
(byte[] prefix, int preflen) Lookup widest negative (i.e., overlapping but not present in trie) prefix for given prefix and prefix length.void
remove
(byte[] prefix, int preflen) Remove prefix from radix trie.void
Remove all entries in the trie.
-
Constructor Details
-
RadixTrie
public RadixTrie(int bits) RadixTrie constructor.- Parameters:
bits
- Maximum prefix length supported.
-
RadixTrie
public RadixTrie(int bits, boolean rootZero) Radix trie constructors.- Parameters:
bits
- Maximum prefix length supportedrootZero
- Flag that decides if 0/0 should be inserted as a non-prefix root node or not
-
-
Method Details
-
getRoot
-
getMaxbits
public int getMaxbits() -
getSize
public long getSize() -
insert
Insert prefix-data tuple into radix trie.- Parameters:
prefix
- Big endian (network order) byte array representation of the prefixpreflen
- Prefix lengthdata
- Data to be stored in the tree- Returns:
- Newly inserted TrieNode
-
lookupBest
Longest prefix match of prefix/preflen.- Parameters:
prefix
- Big endian byte array representation of the prefix to be looked up.preflen
- Prefix length- Returns:
- Node with longest prefix match or null if nothing is found.
-
lookupCoveringLessSpecific
Look up the covering prefix for the argument, but exclude the argument itself, so the result is always less specific than the lookup key.- Parameters:
prefix
- Big endian byte array representation of the prefix argumentpreflen
- Prefix length- Returns:
- Covering node
-
lookupParent
Given an EID, lookup the longest prefix match, then return its parent node.- Parameters:
prefix
- Prefix looked up.preflen
- Prefix length.- Returns:
- Parent node of longest prefix match or null if nothing is found.
-
lookupSibling
Given an EID, lookup the longest prefix match, then return its sibling node.- Parameters:
prefix
- Prefix looked up.preflen
- Prefix length.- Returns:
- Sibling node of longest prefix match or null if nothing is found.
-
lookupVirtualParentSibling
Given an EID, lookup the longest prefix match, then return its direct parent's sibling node, if the parent is a virtual node.- Parameters:
prefix
- Prefix looked up.preflen
- Prefix length.- Returns:
- The longest prefix match node's virtual parent's sibling or null if nothing is found.
-
lookupWidestNegative
Lookup widest negative (i.e., overlapping but not present in trie) prefix for given prefix and prefix length.- Parameters:
prefix
- Prefix looked up.preflen
- Prefix length.- Returns:
- Node containing the widest negative prefix.
-
lookupExact
Exact prefix match of prefix/preflen.- Parameters:
prefix
- Big endian byte array representation of the prefix to be looked up.preflen
- Prefix length- Returns:
- Node with exact prefix match or null
-
lookupSubtree
Return the subtree for a prefix, including the prefix itself if present, excluding virtual nodes.- Parameters:
prefix
- Big endian byte array representation of the prefix to be looked up.preflen
- Prefix length- Returns:
- Subtree from the prefix
-
remove
public void remove(byte[] prefix, int preflen) Remove prefix from radix trie.- Parameters:
prefix
- Big endian byte array representation of the prefix to be removed.preflen
- Prefix length.
-
removeAll
public void removeAll()Remove all entries in the trie.
-