OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 39... Line 39...
39
     *        SimpleBloomFilter (often called 'n').
39
     *        SimpleBloomFilter (often called 'n').
40
     */
40
     */
41
    public BloomFilter(int bitArraySize, int expectedElements) {
41
    public BloomFilter(int bitArraySize, int expectedElements) {
42
        this.bitArraySize = bitArraySize;
42
        this.bitArraySize = bitArraySize;
43
        this.expectedElements = expectedElements;
43
        this.expectedElements = expectedElements;
44
        this.k = (int) Math.ceil((bitArraySize / expectedElements) * Math.log(2.0));
44
        this.k = (int) Math.ceil(((double) bitArraySize / expectedElements) * Math.log(2.0));
45
        bitSet = new BitSet(bitArraySize);
45
        bitSet = new BitSet(bitArraySize);
46
    }
46
    }
47
 
47
 
48
    /**
48
    /**
49
     * Calculates the approximate probability of the contains() method returning true for an object
49
     * Calculates the approximate probability of the contains() method returning true for an object
Line 146... Line 146...
146
    public int getBitLength() {
146
    public int getBitLength() {
147
        return bitSet.length();
147
        return bitSet.length();
148
    }
148
    }
149
 
149
 
150
    public static void main(String[] args) {
150
    public static void main(String[] args) {
151
        BloomFilter<String> set = new BloomFilter<String>(100, 5);
151
        BloomFilter<String> set = new BloomFilter<>(100, 5);
152
 
152
 
153
        // Add some things to the bloom filter
153
        // Add some things to the bloom filter
154
        set.add("dog");
154
        set.add("dog");
155
        set.add("doq");
155
        set.add("doq");
156
        set.add("cat");
156
        set.add("cat");