Class AddressTrie.AddressComparator<E extends Address>
- Type Parameters:
E
-
- All Implemented Interfaces:
Serializable
,Comparator<E>
- Enclosing class:
AddressTrie<E extends Address>
The comparator first compares the prefix of addresses, with the full address value considered the prefix when there is no prefix length, ie when it is a single address. It takes the minimum m of the two prefix lengths and compares those m prefix bits in both addresses. The ordering is determined by which of those two values is smaller or larger.
If those two values match, then it looks at the address with longer prefix. If both prefix lengths match then both addresses are equal. Otherwise it looks at bit m in the address with larger prefix. If 1 it is larger and if 0 it is smaller than the other.
When comparing an address with a prefix p and an address without, the first p bits in both are compared, and if equal, the bit at index p in the non-prefixed address determines the ordering, if 1 it is larger and if 0 it is smaller than the other.
When comparing an address with prefix length matching the bit count to an address with no prefix, they are considered equal if the bits match. For instance, 1.2.3.4/32 is equal to 1.2.3.4, and thus the trie does not allow 1.2.3.4/32 in the trie since it is indistinguishable from 1.2.3.4, instead 1.2.3.4/32 is converted to 1.2.3.4 when inserted into the trie.
When comparing 0.0.0.0/0, which has no prefix, to other addresses, the first bit in the other address determines the ordering. If 1 it is larger and if 0 it is smaller than 0.0.0.0/0.
- Author:
- scfoley
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
AddressComparator
public AddressComparator()
-
-
Method Details
-
compare
- Specified by:
compare
in interfaceComparator<E extends Address>
-