public void addPrefix(Prefix prefix, long bits, int prefixLength, int depth) { if (prefixLength == depth) { _prefix = prefix; return; } else { boolean currentBit = Ip.getBitAtPosition(bits, depth); if (currentBit) { if (_right == null) { _right = new ByteTrieNode(); } _right.addPrefix(prefix, bits, prefixLength, depth + 1); } else { if (_left == null) { _left = new ByteTrieNode(); } _left.addPrefix(prefix, bits, prefixLength, depth + 1); } } }
public boolean containsPathFromPrefix(long bits, int prefixLength, int depth) { if (prefixLength == depth) { if (depth == 0 && _prefix == null) { return false; } else { return true; } } else { boolean currentBit = Ip.getBitAtPosition(bits, depth); if (currentBit) { if (_right == null) { return false; } else { return _right.containsPathFromPrefix(bits, prefixLength, depth + 1); } } else { if (_left == null) { return false; } else { return _left.containsPathFromPrefix(bits, prefixLength, depth + 1); } } } }
public Prefix getLongestPrefixMatch(Ip address, long bits, int index) { Prefix longestPrefixMatch = getLongestPrefixMatch(address); if (index == Prefix.MAX_PREFIX_LENGTH) { return longestPrefixMatch; } boolean currentBit = Ip.getBitAtPosition(bits, index); Prefix longerMatch = null; if (currentBit) { if (_right != null) { longerMatch = _right.getLongestPrefixMatch(address, bits, index + 1); } } else { if (_left != null) { longerMatch = _left.getLongestPrefixMatch(address, bits, index + 1); } } if (longerMatch == null) { return longestPrefixMatch; } else { return longerMatch; } } }
public ByteTrie() { _root = new ByteTrieNode(); }
public boolean containsPathFromPrefix(Prefix prefix) { int prefixLength = prefix.getPrefixLength(); long bits = prefix.getStartIp().asLong(); return _root.containsPathFromPrefix(bits, prefixLength, 0); }
public Prefix getLongestPrefixMatch(Ip address) { long addressBits = address.asLong(); return _root.getLongestPrefixMatch(address, addressBits, 0); } }
public void addPrefix(Prefix prefix) { int prefixLength = prefix.getPrefixLength(); long bits = prefix.getStartIp().asLong(); _root.addPrefix(prefix, bits, prefixLength, 0); }