@Test public void testDistanceArray() { System.out.println("distance"); byte[] x = {1, 0, 1, 1, 1, 0, 1}; byte[] y = {1, 0, 0, 1, 0, 0, 1}; assertEquals(2, HammingDistance.d(x, y)); }
@Override public double d(BitSet x, BitSet y) { if (x.size() != y.size()) { throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size())); } int dist = 0; for (int i = 0; i < x.size(); i++) { if (x.get(i) != y.get(i)) dist++; } return dist; }
HammingDistance implements Distance<BitSet> { @Override public double d(BitSet x, BitSet y) { if (x.size() != y.size()) { throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size())); } int dist = 0; for (int i = 0; i < x.size(); i++) { if (x.get(i) != y.get(i)) dist++; } return dist; } }
HammingDistance implements Distance<BitSet> { @Override public double d(BitSet x, BitSet y) { if (x.size() != y.size()) { throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size())); } int dist = 0; for (int i = 0; i < x.size(); i++) { if (x.get(i) != y.get(i)) dist++; } return dist; } HammingDistance(); }
HammingDistance implements Distance<BitSet> { @Override public double d(BitSet x, BitSet y) { if (x.size() != y.size()) { throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size())); } int dist = 0; for (int i = 0; i < x.size(); i++) { if (x.get(i) != y.get(i)) dist++; } return dist; } HammingDistance(); @Override String toString(); @Override double d(BitSet x, BitSet y); static int d(byte x, byte y); static int d(short x, short y); static int d(int x, int y); static int d(long x, long y); static int d(byte[] x, byte[] y); static int d(short[] x, short[] y); static int d(int[] x, int[] y); }
HammingDistance implements Distance<BitSet> { @Override public double d(BitSet x, BitSet y) { if (x.size() != y.size()) { throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size())); } int dist = 0; for (int i = 0; i < x.size(); i++) { if (x.get(i) != y.get(i)) dist++; } return dist; } HammingDistance(); @Override String toString(); @Override double d(BitSet x, BitSet y); static int d(byte x, byte y); static int d(short x, short y); static int d(int x, int y); static int d(long x, long y); static int d(byte[] x, byte[] y); static int d(short[] x, short[] y); static int d(int[] x, int[] y);  }