@@ -0,0 +1,1319 @@
+package jkanvas.util;%0A%0Aimport java.util.BitSet;%0A%0Aimport jkanvas.table.Metric;%0A%0A/**%0A * Defines metrics for bit sets.%0A * %0A * @author Joschi %3Cjosua.krause@gmail.com%3E%0A */%0Apublic class BitSetMetrics %7B%0A%0A  /** No constructor. */%0A  private BitSetMetrics() %7B%0A    throw new AssertionError();%0A  %7D%0A%0A  /**%0A   * The Jaccard distance of two sets.%0A   * %3Ccode%3E(%7CA &cup; B%7C - %7CA &cap; B%7C) / %7CA &cup; B%7C%3C/code%3E%0A   */%0A  public static final Metric%3CBitSet%3E JACCARD = new Metric%3CBitSet%3E() %7B%0A%0A    @Override%0A    public double distance(final BitSet a, final BitSet b) %7B%0A      final int size = Math.max(a.length(), b.length());%0A      final BitSet and = new BitSet(size);%0A      and.or(a);%0A      and.and(b);%0A      final BitSet or = new BitSet(size);%0A      or.or(a);%0A      or.or(b);%0A      final double union = or.cardinality();%0A      final double intersection = and.cardinality();%0A      return (union - intersection) / union;%0A    %7D%0A%0A  %7D;%0A%0A  /**%0A   * The Hamming distance of two sets. %3Ccode%3E%7CA &oplus; B%7C%3C/code%3E%0A   */%0A  public static final Metric%3CBitSet%3E HAMMING = new Metric%3CBitSet%3E() %7B%0A%0A    @Override%0A    public double distance(final BitSet a, final BitSet b) %7B%0A      final int size = Math.max(a.length(), b.length());%0A      final BitSet hamm = new BitSet(size);%0A      hamm.or(a);%0A      hamm.xor(b);%0A      return hamm.cardinality();%0A    %7D%0A%0A  %7D;%0A%0A%7D%0A

set metrics