001    /*
002     * Copyright (c) 1998-2014 ChemAxon Ltd. All Rights Reserved.
003     *
004     * This software is the confidential and proprietary information of
005     * ChemAxon. You shall not disclose such Confidential Information
006     * and shall use it only in accordance with the terms of the agreements
007     * you entered into with ChemAxon.
008     *
009     */
010    
011    package com.chemaxon.overlap.unguarded;
012    
013    import java.io.Serializable;
014    
015    /**
016     * Unguarded Manhattan comparator for binary fingerprints represented as <code>long []</code>.
017     *
018     * <p><b>Use with extreme care!</b> This implementation wont check vector length equality.</p>
019     *
020     * @author Gabor Imre
021     */
022    public class UnguardedBinaryLongManhattan implements UnguardedDissimilarityCalculator<long[]>, Serializable {
023    
024        /**
025         * Serial version.
026         */
027        private static final long serialVersionUID = 0;
028    
029        @Override
030        public double dissimilarity(long[] target, long[] query) {
031            int diffs = 0;
032            for (int i = 0; i < target.length; i++) {
033                diffs += Long.bitCount(target[i] ^ query[i]);
034            }
035            return (double) diffs;
036        }
037    
038        @Override
039        public String toString() {
040            return "Manhattan dissimilarity of binary fingerprints represented as long []";
041        }
042    
043    
044    
045    
046    }