class Prefix implements Comparable<Prefix>, Serializable {

  public static Prefix longestCommonPrefix(Prefix p1, Prefix p2) {
    if (p1.containsPrefix(p2)) {
      return p1;
    }
    if (p2.containsPrefix(p1)) {
      return p2;
    }
    long l1 = p1.getStartIp().asLong();
    long l2 = p2.getStartIp().asLong();
    long oneAtFirstDifferentBit = Long.highestOneBit(l1 ^ l2);
    int lengthInCommon = MAX_PREFIX_LENGTH - 1 - Long.numberOfTrailingZeros(oneAtFirstDifferentBit);
    return Prefix.create(Ip.create(l1), lengthInCommon);
  }

  private  Prefix(Ip ip, int prefixLength);

}