E
- public static class AddressTrie.AddressComparator<E extends Address> extends Object implements Comparator<E>, Serializable
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.
Constructor and Description |
---|
AddressComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(E o1,
E o2) |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong