@Override public double compare(final byte[] h1, final byte[] h2) { TByteHashSet union = new TByteHashSet(h1); union.addAll(h2); TByteHashSet intersection = new TByteHashSet(h1); intersection.retainAll(h2.clone()); //retainAll sorts the input, so we need to make a copy return 1.0 - (((double)intersection.size()) / (double)union.size()); } },
public byte[] toByteArray() { TByteSet byteSet = new TByteHashSet(); Set<byte[]> extras = new HashSet<byte[]>(); for (Language l : langs) { short id = l.getId(); if (id < 256) { byteSet.add((byte) (id-128)); } else { byte[] temp = new byte[2]; temp[0] = (byte) -128; temp[1] = (byte) (id-255-128); extras.add(temp); } } byte[] output = byteSet.toArray(); for (byte[] b : extras) { output = ArrayUtils.addAll(output, b); } return output; }
@Override public double compare(final byte[] h1, final byte[] h2) { TByteHashSet union = new TByteHashSet(h1); union.addAll(h2); TByteHashSet intersection = new TByteHashSet(h1); intersection.retainAll(h2.clone()); //retainAll sorts the input, so we need to make a copy return 1.0 - (((double)intersection.size()) / (double)union.size()); } },
/** * Creates index converted manager for specified index converters. * * @param converters index converters * @throws IllegalArgumentException if several converters have the same index type */ public IndexConverterManager(IndexSymbolConverter[] converters) { TByteHashSet types = new TByteHashSet(converters.length); for (IndexSymbolConverter converter : converters) { if (types.contains(converter.getType())) throw new IllegalArgumentException("Several converters for same type."); types.add(converter.getType()); } this.converters = converters; }
@Override public double compare(final SparseByteArray h1, final SparseByteArray h2) { byte[] h1v = h1.values(); byte[] h2v = h2.values(); TByteHashSet union = new TByteHashSet(h1v); union.addAll(h2v); if (h1v.length != h1.length || h2v.length != h2.length) union.add((byte)0); TByteHashSet intersection = new TByteHashSet(h1v); intersection.retainAll(h2v); if (h1v.length != h1.length && h2v.length != h2.length) union.add((byte)0); return 1.0 - (((double)intersection.size()) / (double)union.size()); } },
@Override public double compare(final SparseByteArray h1, final SparseByteArray h2) { byte[] h1v = h1.values(); byte[] h2v = h2.values(); TByteHashSet union = new TByteHashSet(h1v); union.addAll(h2v); if (h1v.length != h1.length || h2v.length != h2.length) union.add((byte)0); TByteHashSet intersection = new TByteHashSet(h1v); intersection.retainAll(h2v); if (h1v.length != h1.length && h2v.length != h2.length) union.add((byte)0); return 1.0 - (((double)intersection.size()) / (double)union.size()); } },