1 /* Copyright (C) 2011 Jonathan Alvarsson <jonalv@users.sf.net> 2 * 3 * Contact: cdk-devel@lists.sourceforge.net 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; either version 2.1 8 * of the License, or (at your option) any later version. 9 * All we ask is that proper credit is given for our work, which includes 10 * - but is not limited to - adding the above copyright notice to the beginning 11 * of your source code files, and to any copyright notice that you may distribute 12 * with programs based on this work. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 */ 23 package org.openscience.cdk.fingerprint; 24 25 import java.io.Serializable; 26 import java.util.BitSet; 27 28 /** 29 * Interface for bit fingerprint representations. 30 * 31 * @author jonalv 32 * @cdk.module core 33 * @cdk.githash 34 */ 35 public interface IBitFingerprint extends Serializable { 36 37 /** 38 * Returns the number of bits set to true in the fingerprint. 39 * 40 * @return the number of true bits. 41 */ cardinality()42 public int cardinality(); 43 44 /** 45 * Returns the size of the fingerprint, i.e., the number of hash bins. 46 * 47 * @return the size of the fingerprint. 48 */ size()49 public long size(); 50 51 /** 52 * Performs a logical <b>AND</b> of the bits in this target bit set with 53 * the bits in the argument fingerprint. This fingerprint is modified so 54 * that each bit in it has the value <code>true</code> if and only if 55 * it both initially had the value <code>true</code> and the 56 * corresponding bit in the fingerprint argument also had the value 57 * <code>true</code>. 58 * 59 * @param fingerprint the fingerprint with which to perform the AND operation 60 * @throws IllegalArgumentException if the two fingerprints are 61 * not of same size 62 */ and(IBitFingerprint fingerprint)63 public void and(IBitFingerprint fingerprint); 64 65 /** 66 * Performs a logical <b>OR</b> of the bits in this target bit set with 67 * the bits in the argument fingerprint. This operation can also be seen 68 * as merging two fingerprints. This fingerprint is modified so 69 * that each bit in it has the value <code>true</code> if and only if 70 * it either already had the value <code>true</code> or the corresponding 71 * bit in the bit set argument has the value <code>true</code>. 72 * 73 * @param fingerprint the fingerprint with which to perform the OR operation 74 * @throws IllegalArgumentException if the two fingerprints are 75 * not of same size 76 */ or(IBitFingerprint fingerprint)77 public void or(IBitFingerprint fingerprint); 78 79 /** 80 * Returns the value of the bit with the specified index. The value 81 * is <code>true</code> if the bit with the index <code>index</code> 82 * is currently set in this fingerprint; otherwise, the result 83 * is <code>false</code>. 84 * @param index the index of the bit to return the value for 85 * @return the value of the bit at <code>index</code> 86 */ get(int index)87 public boolean get(int index); 88 89 /** 90 * Sets the bit at the specified index to the specified value. 91 * 92 * @param index the index of the bit to change 93 * @param value the new value for the bit at position <code>index</code> 94 */ set(int index, boolean value)95 public void set(int index, boolean value); 96 97 /** 98 * Returns a <code>BitSet</code> representation of the fingerprint. 99 * This might take significantly more memory! 100 * 101 * @return the fingerprint as a <code>BitSet</code> 102 */ asBitSet()103 public BitSet asBitSet(); 104 105 /** 106 * Sets the bit at the specified index to true. 107 * @param i index 108 */ set(int i)109 public void set(int i); 110 111 /** 112 * Returns a listing of the bits in the fingerprint that are set to true. 113 * 114 * @return listing of all bits that are set 115 */ getSetbits()116 public int[] getSetbits(); 117 } 118