├── nbproject
├── private
│ ├── config.properties
│ ├── private.properties
│ └── private.xml
├── project.xml
├── project.properties
└── build-impl.xml
├── lib
├── junit-4.6.jar
└── hamcrest-core.jar
├── .github
└── workflows
│ └── ci.yml
├── src
├── mvm
│ └── provenance
│ │ ├── SearchStatistics.java
│ │ ├── IDBloomFilterPair.java
│ │ ├── InsDelUpdateStatistics.java
│ │ ├── BloomIndex.java
│ │ ├── Hasher.java
│ │ ├── NaiveBloomFilterIndex.java
│ │ ├── QuickBenchmark.java
│ │ └── FlatBloomFilterIndex.java
└── com
│ ├── skjegstad
│ └── utils
│ │ ├── TestAC.java
│ │ └── BloomFilter.java
│ └── googlecode
│ └── javaewah
│ └── datastructure
│ └── BitSet.java
├── pom.xml
├── nbbuild.xml
├── test
├── mvm
│ └── provenance
│ │ ├── Bloofi1Test.java
│ │ ├── NaiveTest.java
│ │ └── FlatTest.java
└── com
│ └── skjegstad
│ └── utils
│ └── BloomFilterTest.java
├── README.md
├── COPYING.LESSER
└── COPYING
/nbproject/private/config.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/junit-4.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lemire/bloofi/HEAD/lib/junit-4.6.jar
--------------------------------------------------------------------------------
/lib/hamcrest-core.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lemire/bloofi/HEAD/lib/hamcrest-core.jar
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Java CI
2 |
3 | on:
4 | push:
5 | branches: [ main, master ]
6 | pull_request:
7 | branches: [ main, master ]
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v4
14 | - name: Set up JDK 8
15 | uses: actions/setup-java@v4
16 | with:
17 | java-version: '8'
18 | distribution: 'temurin'
19 | - name: Build with Maven
20 | run: mvn -B clean package
21 | - name: Run tests
22 | run: mvn test
23 |
--------------------------------------------------------------------------------
/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | application.args=-bloofi2 -falsePositiveProb 0.01 -expectedNbElemInBloomFilter 10000 -initialNbElemInBloomFilter 10000 -nbBloomFilters 100000 -bloofiOrder 2 -constructionMethod i -nbYesSearches 50000 -nbNoSearches 50000 -splitAllOneNodesIfOverflow false -metric Hamming -nbBFInsertsDeletes 0 -nbUpdates 0 -nonOverlappingRanges false
2 | compile.on.save=false
3 | do.depend=false
4 | do.jar=true
5 | javac.debug=true
6 | javadoc.preview=true
7 | user.properties.file=C:\\Users\\adina\\AppData\\Roaming\\NetBeans\\7.4\\build.properties
8 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 | java-bloomfilter
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/mvm/provenance/SearchStatistics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package mvm.provenance;
7 |
8 | /**
9 | *
10 | * @author adina
11 | */
12 | public class SearchStatistics {
13 |
14 | /** Number of BloomFilters checked for matches */
15 | public int nbBFChecks;
16 |
17 | public SearchStatistics() {
18 | nbBFChecks = 0;
19 | }
20 |
21 | /**
22 | * Reset the statistics to 0
23 | */
24 | public void clear() {
25 | nbBFChecks = 0;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/mvm/provenance/IDBloomFilterPair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package mvm.provenance;
7 |
8 | import com.skjegstad.utils.*;
9 |
10 | /**
11 | *
12 | * @author adina
13 | */
14 | public class IDBloomFilterPair {
15 | public int id;
16 | public BloomFilter bloomFilter;
17 |
18 | /**
19 | * Constructor
20 | * @param id
21 | * @param bf
22 | */
23 | public IDBloomFilterPair(int id, BloomFilter bf) {
24 | this.id = id;
25 | this.bloomFilter = bf;
26 | }
27 |
28 | /**
29 | * Get id
30 | * @return id
31 | */
32 | public int getID() {
33 | return this.id;
34 | }
35 |
36 |
37 | public BloomFilter getBloomFilter() {
38 | return this.bloomFilter;
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/src/com/skjegstad/utils/TestAC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 |
6 | package com.skjegstad.utils;
7 |
8 | import mvm.provenance.Hasher;
9 |
10 | import com.skjegstad.utils.BloomFilter;
11 |
12 | /**
13 | *
14 | * @author adina
15 | */
16 | public class TestAC {
17 |
18 | public static void main(String[] args) {
19 | Hasher h = new Hasher();
20 |
21 | BloomFilter bf = new BloomFilter(h,0.1,10,1);
22 | int i;
23 | for (i = 0; i< 10; i++) {
24 | bf.add(i);
25 | }
26 |
27 | for (i = 0; i< 15; i++) {
28 | if (bf.contains(i)) {
29 | System.out.println("Bloom filter contains " + i);
30 | }
31 | else {
32 | System.out.println("Bloom filter does not contain " + i);
33 | }
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/mvm/provenance/InsDelUpdateStatistics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package mvm.provenance;
6 |
7 | /**
8 | *
9 | * @author adina
10 | */
11 | public class InsDelUpdateStatistics {
12 |
13 | /** Number of BloomFilters accessed */
14 | public long nbBFAccessed;
15 | public long nbBFNodesAccessed;
16 | public int nbSplits;
17 | public int nbMerges;
18 | public int nbRedistributes;
19 |
20 | public InsDelUpdateStatistics() {
21 | this.clear();
22 | }
23 |
24 | /**
25 | * Reset the statistics to 0
26 | */
27 | public void clear() {
28 | nbBFAccessed = 0;
29 | nbBFNodesAccessed = 0;
30 | nbSplits = 0;
31 | nbMerges = 0;
32 | nbRedistributes = 0;
33 |
34 | }
35 |
36 | public String toString() {
37 | return "| nbBFAccessed | " + nbBFAccessed
38 | + "| nbBFNodesAccessed | "+ nbBFNodesAccessed
39 | + "| nbSplits |" + nbSplits
40 | + "| nbMerges |" + nbMerges
41 | + "| nbRedistributes |" + nbRedistributes;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | file://macallan.cs.usna.edu/home$/adina/Research/LTS/code/bloofi-bitBucket2/bloofi/code/src/mvm/provenance/TestAC.java
8 | file://macallan.cs.usna.edu/home$/adina/Research/LTS/code/bloofi-bitBucket2/bloofi/code/src/mvm/provenance/FlatBloomFilterIndex.java
9 | file://macallan.cs.usna.edu/home$/adina/Research/LTS/code/bloofi-bitBucket2/bloofi/code/src/mvm/provenance/InsDelUpdateStatistics.java
10 | file://macallan.cs.usna.edu/home$/adina/Research/LTS/code/bloofi-bitBucket2/bloofi/code/src/mvm/provenance/QuickBenchmark.java
11 | file://macallan.cs.usna.edu/home$/adina/Research/LTS/code/bloofi-bitBucket2/bloofi/code/src/mvm/provenance/SearchStatistics.java
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/mvm/provenance/BloomIndex.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.List;
4 | import java.util.Set;
5 |
6 | import com.skjegstad.utils.BloomFilter;
7 |
8 |
9 | /**
10 | * Generic interface for all Bloofi-like data structures.
11 | *
12 | *
13 | * @author Daniel Lemire
14 | *
15 | * @param
16 | */
17 | public interface BloomIndex {
18 | public int deleteFromIndex(int id, InsDelUpdateStatistics stat);
19 |
20 | /**
21 | * Return the size - number of bits in a Bloom Filter indexed by this
22 | * index
23 | *
24 | * @return
25 | */
26 | public int getBloomFilterSize();
27 |
28 | public int getHeight();
29 |
30 | public Set getIDs();
31 |
32 | public boolean getIsRootAllOne();
33 |
34 | public int getNbChildrenRoot();
35 |
36 | /**
37 | * Return the number of nodes in this Bloom Index
38 | *
39 | * @return
40 | */
41 | public int getSize();
42 |
43 | public void insertBloomFilter(BloomFilter bf,
44 | InsDelUpdateStatistics stat);
45 |
46 | /**
47 | * Return matching ids
48 | */
49 | public List search(E o, SearchStatistics stat);
50 |
51 | // TODO: it is not clear why we need an id parameter here?
52 | public int updateIndex(BloomFilter newBloomFilter,
53 | InsDelUpdateStatistics stat);
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/mvm/provenance/Hasher.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.Random;
4 |
5 | /**
6 | * Implements simple tabulation hashing.
7 | *
8 | * @author Daniel Lemire
9 | *
10 | */
11 | public class Hasher {
12 | Random r;
13 |
14 | public int getNumberOfHashFunctions() {
15 | return randomkeys.length;
16 | }
17 | public Hasher() {
18 | r = new Random();
19 | }
20 |
21 | public Hasher(int seed) {
22 | r = new Random(seed);
23 | }
24 |
25 | public int hash(Object o, int whichhash) {
26 | return (((o.hashCode() * randomkeys[whichhash])) & Integer.MAX_VALUE) % maxval;
27 | }
28 |
29 | /**
30 | * Should be called as soon as we know how many hash functions are
31 | * needed. If called again with a different number of hash functions,
32 | * and exception is thrown. (The number of hash functions should be
33 | * constant.)
34 | *
35 | * @param K
36 | */
37 | public void setNumberOfRandomKeys(int K) {
38 | if (randomkeys.length > 0) {
39 | if (K != randomkeys.length) {
40 | throw new RuntimeException(
41 | "You are changing the number of hash functions?");
42 | }
43 | return;
44 | }
45 | randomkeys = new int[K];
46 | for (int i = 0; i < randomkeys.length; ++i)
47 | randomkeys[i] = (r.nextInt()>>>2)*2 + 1;
48 |
49 | }
50 |
51 | int[] randomkeys = new int[0];
52 | int maxval = 0;
53 |
54 | public void setMaxValue(int bitSetSize) {
55 | if(maxval!=0) {
56 | if(bitSetSize != maxval)
57 | throw new RuntimeException("Resizing dynamically is not supported");
58 | }
59 | maxval = bitSetSize;
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/mvm/provenance/NaiveBloomFilterIndex.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Set;
6 | import java.util.TreeMap;
7 |
8 | import com.skjegstad.utils.BloomFilter;
9 |
10 | public class NaiveBloomFilterIndex implements BloomIndex {
11 | TreeMap> idMap = new TreeMap>();
12 |
13 |
14 | @Override
15 | public int deleteFromIndex(int id, InsDelUpdateStatistics stat) {
16 | idMap.remove(id);
17 | return 0;
18 | }
19 |
20 | @Override
21 | public int getBloomFilterSize() {
22 | return idMap.size();
23 | }
24 |
25 | @Override
26 | public int getHeight() {
27 | return 0;
28 | }
29 |
30 | @Override
31 | public Set getIDs() {
32 | return idMap.keySet();
33 | }
34 |
35 | @Override
36 | public boolean getIsRootAllOne() {
37 | return false;
38 | }
39 |
40 | @Override
41 | public int getNbChildrenRoot() {
42 | return 0;
43 | }
44 |
45 | @Override
46 | public int getSize() {
47 | return idMap.size();
48 | }
49 |
50 | @Override
51 | public void insertBloomFilter(BloomFilter bf,
52 | InsDelUpdateStatistics stat) {
53 | idMap.put(bf.getID(), bf);
54 | }
55 |
56 | @Override
57 | public List search(E o, SearchStatistics stat) {
58 | ArrayList al = new ArrayList();
59 | for(BloomFilter bf : idMap.values())
60 | if(bf.contains(o)) al.add(bf.getID());
61 | return al;
62 | }
63 |
64 | @Override
65 | public int updateIndex(BloomFilter newBloomFilter,
66 | InsDelUpdateStatistics stat) {
67 | idMap.put(newBloomFilter.getID(), newBloomFilter);
68 | return 0;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | com.skjegstad.utils
6 | bloofi
7 | 1.0.0-SNAPSHOT
8 | jar
9 | Bloofi
10 | Java project for Bloom filters and related data structures
11 | https://github.com/dlemire/bloofi
12 |
13 |
14 | GNU Lesser General Public License
15 | https://www.gnu.org/licenses/lgpl-3.0.html
16 |
17 |
18 |
19 | 1.8
20 | 1.8
21 | UTF-8
22 |
23 |
24 |
25 | junit
26 | junit
27 | 4.6
28 | test
29 |
30 |
31 | org.hamcrest
32 | hamcrest-core
33 | 1.3
34 | test
35 |
36 |
37 |
38 | src
39 | test
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-compiler-plugin
44 | 3.8.1
45 |
46 | 1.8
47 | 1.8
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | annotation.processing.enabled=true
2 | annotation.processing.enabled.in.editor=false
3 | annotation.processing.processors.list=
4 | annotation.processing.run.all.processors=true
5 | application.title=java-bloomfilter
6 | application.vendor=mag
7 | build.classes.dir=${build.dir}/classes
8 | build.classes.excludes=**/*.java,**/*.form
9 | # This directory is removed when the project is cleaned:
10 | build.dir=build
11 | build.generated.dir=${build.dir}/generated
12 | build.generated.sources.dir=${build.dir}/generated-sources
13 | # Only compile against the classpath explicitly listed here:
14 | build.sysclasspath=ignore
15 | build.test.classes.dir=${build.dir}/test/classes
16 | build.test.results.dir=${build.dir}/test/results
17 | buildfile=nbbuild.xml
18 | # Uncomment to specify the preferred debugger connection transport:
19 | #debug.transport=dt_socket
20 | debug.classpath=\
21 | ${run.classpath}
22 | debug.test.classpath=\
23 | ${run.test.classpath}
24 | # This directory is removed when the project is cleaned:
25 | dist.dir=dist
26 | dist.jar=${dist.dir}/java-bloomfilter.jar
27 | dist.javadoc.dir=${dist.dir}/javadoc
28 | endorsed.classpath=
29 | excludes=
30 | file.reference.java-bloomfilter-src=src
31 | file.reference.java-bloomfilter-test=test
32 | file.reference.junit-4.6.jar=lib/junit-4.6.jar
33 | includes=**
34 | jar.compress=false
35 | javac.classpath=\
36 | ${file.reference.junit-4.6.jar}
37 | # Space-separated list of extra javac options
38 | javac.compilerargs=
39 | javac.deprecation=false
40 | javac.processorpath=\
41 | ${javac.classpath}
42 | javac.source=1.6
43 | javac.target=1.6
44 | javac.test.classpath=\
45 | ${javac.classpath}:\
46 | ${build.classes.dir}:\
47 | ${libs.junit.classpath}:\
48 | ${libs.junit_4.classpath}
49 | javadoc.additionalparam=
50 | javadoc.author=false
51 | javadoc.encoding=${source.encoding}
52 | javadoc.noindex=false
53 | javadoc.nonavbar=false
54 | javadoc.notree=false
55 | javadoc.private=false
56 | javadoc.splitindex=true
57 | javadoc.use=true
58 | javadoc.version=false
59 | javadoc.windowtitle=
60 | main.class=mvm.provenance.TestAC
61 | manifest.file=manifest.mf
62 | meta.inf.dir=${src.dir}/META-INF
63 | mkdist.disabled=false
64 | platform.active=default_platform
65 | run.classpath=\
66 | ${javac.classpath}:\
67 | ${build.classes.dir}
68 | run.jvmargs=-ea -Xms7168m -Xmx7168m
69 | run.test.classpath=\
70 | ${javac.test.classpath}:\
71 | ${build.test.classes.dir}
72 | source.encoding=UTF-8
73 | src.dir=${file.reference.java-bloomfilter-src}
74 | test.src.dir=${file.reference.java-bloomfilter-test}
75 |
--------------------------------------------------------------------------------
/src/mvm/provenance/QuickBenchmark.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Random;
5 |
6 | import com.skjegstad.utils.BloomFilter;
7 |
8 | public class QuickBenchmark {
9 |
10 | public static void main(String[] args) {
11 | final int M = 1000;
12 | final int N = 10000;
13 | double proba = 0.01;
14 | basicBenchmark(M,N,proba,1);
15 | basicBenchmark(M,N,proba,0.1);
16 | for(int k = 0; k < 10 ; ++k ) {
17 | basicBenchmark(M,N,proba,0.01);
18 | }
19 | }
20 | public static void basicBenchmark(final int M, final int N, final double proba, final double fillpercentage) {
21 | FlatBloomFilterIndex f = new FlatBloomFilterIndex();
22 | Hasher h = new Hasher();
23 | ArrayList> allbf = new ArrayList>();
24 | Random r = new Random(0);
25 | System.out.println("M = "+M+" N = "+N+" proba = "+proba+" fillpercentage = "+fillpercentage);
26 | for (int k = 0; k < N; k++) {
27 | BloomFilter bf = new BloomFilter(h,
28 | proba, M, 1);
29 | bf.setID(k);
30 | if (bf.getID() != k)
31 | throw new RuntimeException("unexpected id " + k
32 | + " " + bf.getID());
33 | int i;
34 | for (i = 0; i < M; i += M/Math.max(1, Math.round(fillpercentage * M))) {
35 | final int v = r.nextInt();
36 | bf.add(v);
37 | }
38 | allbf.add(bf);
39 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
40 |
41 | }
42 | ArrayList> toremove = new ArrayList>();
43 | for(int k = 0; k < N; k += 3) {
44 | toremove.add(allbf.get(k));
45 | }
46 | long bef,aft;
47 | bef = System.nanoTime();
48 | for(BloomFilter R : toremove) {
49 | f.deleteFromIndex(R.getID(), new InsDelUpdateStatistics());
50 | }
51 | aft = System.nanoTime();
52 | System.out.println("delete = "+(aft-bef));
53 | bef = System.nanoTime();
54 | for(BloomFilter R : toremove) {
55 | f.insertBloomFilter(R, new InsDelUpdateStatistics());
56 | }
57 | aft = System.nanoTime();
58 | System.out.println("insert = "+(aft-bef));
59 | aft = System.nanoTime();
60 | bef = System.nanoTime();
61 | for(BloomFilter R : toremove) {
62 | R.add(1);
63 | f.updateIndex(R, new InsDelUpdateStatistics());
64 | }
65 | aft = System.nanoTime();
66 | System.out.println("update = "+(aft-bef));
67 | bef = System.nanoTime();
68 | for(BloomFilter R : toremove) {
69 | f.deleteFromIndex(R.getID(), new InsDelUpdateStatistics());
70 | }
71 | aft = System.nanoTime();
72 | System.out.println("delete = "+(aft-bef));
73 |
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/nbbuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project java-bloomfilter.
12 |
13 |
74 |
75 |
--------------------------------------------------------------------------------
/test/mvm/provenance/Bloofi1Test.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 | import java.util.Random;
7 | import junit.framework.Assert;
8 | import org.junit.Test;
9 | import com.skjegstad.utils.BloomFilter;
10 |
11 | @SuppressWarnings({ "static-method" })
12 | public class Bloofi1Test {
13 |
14 | @SuppressWarnings("unchecked")
15 | public void btest(int order, boolean splitfull) {
16 | Hasher h = new Hasher(0);
17 | final int M = 1000;
18 | final int N = 1000;
19 | double proba = 0.01;
20 | int metric = 1;
21 | BloomFilter proto = new BloomFilter(h, proba,
22 | M, metric);
23 | BloomFilterIndex f = new BloomFilterIndex(
24 | order, proto, splitfull);
25 | ArrayList> allbf = new ArrayList>();
26 | Random r = new Random(0);
27 | for (int k = 0; k < N; k++) {
28 | BloomFilter bf = new BloomFilter(h,
29 | proba, M, metric);
30 | bf.setID(k);
31 | if (bf.getID() != k)
32 | throw new RuntimeException("unexpected id " + k
33 | + " " + bf.getID());
34 | int i;
35 | for (i = 0; i < M; i += 3) {
36 | final int v = r.nextInt();
37 | bf.add(v);
38 | }
39 | allbf.add(bf);
40 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
41 |
42 | }
43 | f.validate();
44 | for (int i = 0; i < N + M; ++i) {
45 | Integer target = new Integer(i);
46 | List ans = f.search(target,
47 | new SearchStatistics());
48 | Collections.sort(ans);
49 | List ans2 = bruteForce(target, allbf);
50 | if (!ans.equals(ans2)) {
51 | System.out
52 | .println("By brute force, I expected "
53 | + ans2 + " but Bloofi got me "
54 | + ans);
55 | }
56 | Assert.assertEquals(ans, ans2);
57 | }
58 | long bef = System.currentTimeMillis();
59 | int bogus = 0;
60 | for (int i = 0; i < N + M; ++i) {
61 | Integer target = new Integer(i);
62 | List ans = f.search(target,
63 | new SearchStatistics());
64 | bogus += ans.size();
65 | }
66 |
67 | long aft = System.currentTimeMillis();
68 | System.out.println();
69 | System.out.println("[Time "+(aft-bef)+" for "+bogus+"]");
70 | System.out.println();
71 | List> x = ((List>) allbf.clone());
72 | f = new BloomFilterIndex(x, order,
73 | splitfull, new InsDelUpdateStatistics());
74 | if(x.size() != allbf.size()) throw new RuntimeException("Bloofi ate? "+x.size()+ " "+allbf.size());
75 | f.validate();
76 | for (int i = 0; i < N + M; ++i) {
77 | Integer target = new Integer(i);
78 | List ans = f.search(target,
79 | new SearchStatistics());
80 | Collections.sort(ans);
81 | List ans2 = bruteForce(target, allbf);
82 | if (!ans.equals(ans2)) {
83 | System.out
84 | .println("By brute force, I expected "
85 | + ans2 + " but Bloofi got me "
86 | + ans);
87 | }
88 | Assert.assertEquals(ans, ans2);
89 | }
90 |
91 | }
92 |
93 | @Test
94 | public void basicTest() {
95 | for (int order = 1; order < 10; ++order) {
96 | btest(order, true);
97 | btest(order, false);
98 | }
99 |
100 |
101 | }
102 |
103 |
104 |
105 | public static List bruteForce(Integer target,
106 | ArrayList> allbf) {
107 | List a = new ArrayList();
108 | for (int k = 0; k < allbf.size(); ++k) {
109 | if (allbf.get(k).contains(target)) {
110 | a.add(allbf.get(k).getID());
111 | }
112 | }
113 | return a;
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bloofi: A java implementation of multidimensional Bloom filters
2 | [](https://github.com/lemire/bloofi/actions/workflows/ci.yml)
3 |
4 | Bloom filters are probabilistic data structures commonly used for approximate membership problems in many areas of Computer Science (networking, distributed systems, databases, etc.). With the increase in data size and distribution of data, problems arise where a large number of Bloom filters are available, and all them need to be searched for potential matches. As an example, in a federated cloud environment, each cloud provider could encode the information using Bloom filters and share the Bloom filters with a central coordinator. The problem of interest is not only whether a given element is in any of the sets represented by the Bloom filters, but which of the existing sets contain the given element. This problem cannot be solved by just constructing a Bloom filter on the union of all the sets. Instead, we effectively have a multidimensional Bloom filter problem: given an element, we wish to receive a list of candidate sets where the element might be.
5 | To solve this problem, we consider 3 alternatives. Firstly, we can naively check many Bloom filters. Secondly, we propose to organize the Bloom filters in a hierarchical index structure akin to a B+ tree, that we call Bloofi. Finally, we propose another data structure that packs the Bloom filters in such a way as to exploit bit-level parallelism, which we call Flat-Bloofi.
6 | Our theoretical and experimental results show that Bloofi and Flat-Bloofi provide scalable and efficient solutions alternatives to search through a large number of Bloom filters.
7 |
8 | ### Prerequisites
9 |
10 | - Java (JDK 8 or later)
11 | - Maven (https://maven.apache.org/) for building and testing
12 | - (Optional) Ant (http://ant.apache.org/) — on a Mac, you can install Ant with `brew install ant` after installing Homebrew
13 |
14 | We build on an existing Bloom filter library (https://github.com/magnuss/java-bloomfilter) by Magnus Skjegstad, which we embedded and modified. We also use JUnit and Hamcrest, included as jar files for your convenience, but Maven will automatically download them if you use it.
15 |
16 |
17 | ### Usage
18 |
19 | We provide the necessary software to reproduce our experiments. The software includes unit testing. The documentation is minimal and the software is not meant for production use. It is provided mostly for research purposes and as a way to promote the ideas.
20 |
21 | #### Building and running unit tests with Maven
22 |
23 | You can use Maven to build the project and run the tests:
24 |
25 | ```
26 | mvn clean package
27 | mvn test
28 | ```
29 |
30 | #### Building and running unit tests with Ant
31 |
32 | ```
33 | ant
34 | ```
35 |
36 | #### Running experiments
37 |
38 | Main class to run the experiments: `mvm.provenance.TestAC`.
39 |
40 | Sample run:
41 | ```
42 | java -Xms7168m -Xmx7168m mvm.provenance.TestAC -bloofi -falsePositiveProb 0.01 -expectedNbElemInBloomFilter 10000 -initialNbElemInBloomFilter 100 -nbBloomFilters 1000 -bloofiOrder 2 -constructionMethod i -nbYesSearches 50000 -nbNoSearches 50000 -splitAllOneNodesIfOverflow false -metric Hamming -nbBFInsertsDeletes 0 -nbUpdates 0 -nonOverlappingRanges true -nbRuns 10
43 | ```
44 |
45 | Input parameters, with default values:
46 | ```
47 | -bloofi | -bloofi2 | -naive #this param is required and specifies which type of index tructure to construct - original bloofi (bloofi), flat bloofi (bloofi 2), or just store all the Bloom filters without indexing, in a map (naive)
48 | -falsePositiveProb falsePosProb #Default: 0.01
49 | -expectedNbElemInBloomFilter expectedNbElemInFilter #Default 10000
50 | -initialNbElemInBloomFilter initialNbElemInFilter #Default 100
51 | -nbBloomFilters nbBFs #Default 1000
52 | -bloofiOrder order #Default 2
53 | -constructionMethod b | i (bulk or incremental) #Default i
54 | -nbYesSearches nbyesSearches #searches for elements known to be in the Bloom filters. Default 1000
55 | -nbNoSearches nbNoSearches #searches for elements not in the Bloom filters. Default 1000
56 | -splitAllOneNodesIfOverflow true | false #if there is an overflow in the Bloofi index, and the value of the node is already all bits to one, should that node still split, or not? Default false
57 | -metric Hamming | Jaccard | Cosine #metric used to compare similarity between two Bloom filters. Default Hamming
58 | -nbBFInsertsDeletes nbBloomFiltersInsertsOrDeletes #Default 0
59 | -nbUpdates nbOfElementsToBeInsertedDuringUpdateInEachFilter #Default 0
60 | -nonOverlappingRanges true | false #if true, each Bloom filter i gets the integers in [(i-1)* initialNbElemInFilter,i*actualNbElemInFilter); if false, each bloom filter gets initialNbElemInFilter random integers from a random rangeDefault true
61 | -nbRuns numberOfRunsForExperiments #Default 10
62 | ```
63 |
64 | ### References
65 |
66 | - Adina Crainiceanu and Daniel Lemire. Bloofi: Multidimensional Bloom Filters. Information Systems,Volume 54, December 2015, pp.311-324 http://arxiv.org/abs/1501.01941
67 |
68 |
69 | ### Continuous Integration
70 |
71 | This project uses GitHub Actions for continuous integration. All pushes and pull requests to the main branch will automatically trigger a build and run the tests using Maven.
72 |
73 | You can find the workflow configuration in `.github/workflows/ci.yml`.
74 |
75 | ### License
76 |
77 | Because we built on Magnus Skjegstad's Bloom filter library, we use the lesser GPL software license.
78 |
--------------------------------------------------------------------------------
/test/mvm/provenance/NaiveTest.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 | import java.util.Random;
7 |
8 | import junit.framework.Assert;
9 |
10 | import org.junit.Test;
11 |
12 | import com.skjegstad.utils.BloomFilter;
13 |
14 | @SuppressWarnings("static-method")
15 | public class NaiveTest {
16 | @Test
17 | public void basicTest() {
18 | NaiveBloomFilterIndex f = new NaiveBloomFilterIndex();
19 | Hasher h = new Hasher();
20 | ArrayList> allbf = new ArrayList>();
21 | final int M = 1000;
22 | final int N = 1000;
23 | Random r = new Random(0);
24 | for (int k = 0; k < N; k++) {
25 | BloomFilter bf = new BloomFilter(h,
26 | 0.1, M, 1);
27 | bf.setID(k);
28 | if (bf.getID() != k)
29 | throw new RuntimeException("unexpected id " + k
30 | + " " + bf.getID());
31 | int i;
32 | for (i = 0; i < M; i += 3) {
33 | final int v = r.nextInt();
34 | bf.add(v);
35 | }
36 | allbf.add(bf);
37 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
38 |
39 | }
40 | for (int i = 0; i < N + M; ++i) {
41 | Integer target = new Integer(i);
42 | List ans = f.search(target,
43 | new SearchStatistics());
44 | List ans2 = bruteForce(target, allbf);
45 | Assert.assertEquals(ans, ans2);
46 |
47 | }
48 | long bef = System.currentTimeMillis();
49 | int bogus = 0;
50 | for (int i = 0; i < N + M; ++i) {
51 | Integer target = new Integer(i);
52 | List ans = f.search(target,
53 | new SearchStatistics());
54 | bogus += ans.size();
55 | }
56 |
57 | long aft = System.currentTimeMillis();
58 | System.out.println();
59 | System.out.println("[Time " + (aft - bef) + " for " + bogus
60 | + "]");
61 | System.out.println();
62 | }
63 | @Test
64 | public void basicTestWithDeletions() {
65 | NaiveBloomFilterIndex f = new NaiveBloomFilterIndex();
66 | Hasher h = new Hasher();
67 | ArrayList> allbf = new ArrayList>();
68 | final int M = 1000;
69 | final int N = 1000;
70 | Random r = new Random(0);
71 | for (int k = 0; k < N; k++) {
72 | BloomFilter bf = new BloomFilter(h,
73 | 0.1, M, 1);
74 | bf.setID(k);
75 | if (bf.getID() != k)
76 | throw new RuntimeException("unexpected id " + k
77 | + " " + bf.getID());
78 | int i;
79 | for (i = 0; i < M; i += 3) {
80 | final int v = r.nextInt();
81 | bf.add(v);
82 | }
83 | allbf.add(bf);
84 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
85 | }
86 | ArrayList> toremove = new ArrayList>();
87 | for(int k = 0; k < N; k += 3) {
88 | toremove.add(allbf.get(k));
89 | f.deleteFromIndex(allbf.get(k).getID(), new InsDelUpdateStatistics());
90 | }
91 | allbf.removeAll(toremove);
92 | for (int i = 0; i < N + M; ++i) {
93 | Integer target = new Integer(i);
94 | List ans = f.search(target,
95 | new SearchStatistics());
96 | List ans2 = bruteForce(target, allbf);
97 | Assert.assertEquals(ans, ans2);
98 | }
99 | long bef = System.currentTimeMillis();
100 | int bogus = 0;
101 | for (int i = 0; i < N + M; ++i) {
102 | Integer target = new Integer(i);
103 | List ans = f.search(target,
104 | new SearchStatistics());
105 | bogus += ans.size();
106 | }
107 |
108 | long aft = System.currentTimeMillis();
109 | System.out.println();
110 | System.out.println("[Time " + (aft - bef) + " for " + bogus
111 | + "]");
112 | System.out.println();
113 | for(BloomFilter bf : toremove) {
114 | allbf.add(bf);
115 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
116 | for (int i = 0; i < N + M; ++i) {
117 | Integer target = new Integer(i);
118 | List ans = f.search(target,
119 | new SearchStatistics());
120 | List ans2 = bruteForce(target, allbf);
121 | Collections.sort(ans);
122 | Collections.sort(ans2);
123 | Assert.assertEquals(ans, ans2);
124 | }
125 | }
126 | }
127 |
128 |
129 | public static List bruteForce(Integer target,
130 | ArrayList> allbf) {
131 | List a = new ArrayList();
132 | for (int k = 0; k < allbf.size(); ++k) {
133 | if (allbf.get(k).contains(target)) {
134 | a.add(allbf.get(k).getID());
135 | }
136 | }
137 | return a;
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/test/mvm/provenance/FlatTest.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 | import java.util.Random;
7 | import junit.framework.Assert;
8 | import org.junit.Test;
9 | import com.skjegstad.utils.BloomFilter;
10 |
11 | @SuppressWarnings({ "static-method" })
12 | public class FlatTest {
13 |
14 | @Test
15 | public void basicTest() {
16 | FlatBloomFilterIndex f = new FlatBloomFilterIndex();
17 | Hasher h = new Hasher();
18 | ArrayList> allbf = new ArrayList>();
19 | final int M = 1000;
20 | final int N = 1000;
21 | Random r = new Random(0);
22 | for (int k = 0; k < N; k++) {
23 | BloomFilter bf = new BloomFilter(h,
24 | 0.1, M, 1);
25 | bf.setID(k);
26 | if (bf.getID() != k)
27 | throw new RuntimeException("unexpected id " + k
28 | + " " + bf.getID());
29 | int i;
30 | for (i = 0; i < M; i += 3) {
31 | final int v = r.nextInt();
32 | bf.add(v);
33 | }
34 | allbf.add(bf);
35 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
36 |
37 | }
38 | for (int i = 0; i < N + M; ++i) {
39 | Integer target = new Integer(i);
40 | List ans = f.search(target,
41 | new SearchStatistics());
42 | List ans2 = bruteForce(target, allbf);
43 | Assert.assertEquals(ans, ans2);
44 | }
45 | long bef = System.currentTimeMillis();
46 | int bogus = 0;
47 | for (int i = 0; i < N + M; ++i) {
48 | Integer target = new Integer(i);
49 | List ans = f.search(target,
50 | new SearchStatistics());
51 | bogus += ans.size();
52 | }
53 |
54 | long aft = System.currentTimeMillis();
55 | System.out.println();
56 | System.out.println("[Time " + (aft - bef) + " for " + bogus
57 | + "]");
58 | System.out.println();
59 | }
60 |
61 |
62 |
63 | @Test
64 | public void basicTestWithDeletion() {
65 | FlatBloomFilterIndex f = new FlatBloomFilterIndex();
66 | Hasher h = new Hasher();
67 | ArrayList> allbf = new ArrayList>();
68 | final int M = 1000;
69 | final int N = 1000;
70 | Random r = new Random(0);
71 | for (int k = 0; k < N; k++) {
72 | BloomFilter bf = new BloomFilter(h,
73 | 0.1, M, 1);
74 | bf.setID(k);
75 | if (bf.getID() != k)
76 | throw new RuntimeException("unexpected id " + k
77 | + " " + bf.getID());
78 | int i;
79 | for (i = 0; i < M; i += 3) {
80 | final int v = r.nextInt();
81 | bf.add(v);
82 | }
83 | allbf.add(bf);
84 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
85 |
86 | }
87 | ArrayList> toremove = new ArrayList>();
88 | for(int k = 0; k < N; k += 3) {
89 | toremove.add(allbf.get(k));
90 | f.deleteFromIndex(allbf.get(k).getID(), new InsDelUpdateStatistics());
91 | }
92 | allbf.removeAll(toremove);
93 | for (int i = 0; i < N + M; ++i) {
94 | Integer target = new Integer(i);
95 | List ans = f.search(target,
96 | new SearchStatistics());
97 | List ans2 = bruteForce(target, allbf);
98 | Assert.assertEquals(ans, ans2);
99 | }
100 | long bef = System.currentTimeMillis();
101 | int bogus = 0;
102 | for (int i = 0; i < N + M; ++i) {
103 | Integer target = new Integer(i);
104 | List ans = f.search(target,
105 | new SearchStatistics());
106 | bogus += ans.size();
107 | }
108 |
109 | long aft = System.currentTimeMillis();
110 | System.out.println();
111 | System.out.println("[Time " + (aft - bef) + " for " + bogus
112 | + "]");
113 | System.out.println();
114 | for(BloomFilter bf : toremove) {
115 | allbf.add(bf);
116 | f.insertBloomFilter(bf, new InsDelUpdateStatistics());
117 | for (int i = 0; i < N + M; ++i) {
118 | Integer target = new Integer(i);
119 | List ans = f.search(target,
120 | new SearchStatistics());
121 | List ans2 = bruteForce(target, allbf);
122 | Collections.sort(ans);
123 | Collections.sort(ans2);
124 | Assert.assertEquals(ans, ans2);
125 | }
126 | }
127 |
128 |
129 | }
130 |
131 | public static List bruteForce(Integer target,
132 | ArrayList> allbf) {
133 | List a = new ArrayList();
134 | for (int k = 0; k < allbf.size(); ++k) {
135 | if (allbf.get(k).contains(target)) {
136 | a.add(allbf.get(k).getID());
137 | }
138 | }
139 | return a;
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/src/mvm/provenance/FlatBloomFilterIndex.java:
--------------------------------------------------------------------------------
1 | package mvm.provenance;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Hashtable;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.Set;
8 |
9 | import com.googlecode.javaewah.datastructure.BitSet;
10 | import com.skjegstad.utils.BloomFilter;
11 |
12 | /**
13 | * This is what Daniel called Bloofi2. Basically, instead of using a tree
14 | * structure like Bloofi (see BloomFilterIndex), we "transpose" the BitSets.
15 | *
16 | *
17 | * @author Daniel Lemire
18 | *
19 | * @param
20 | */
21 | public final class FlatBloomFilterIndex implements BloomIndex {
22 | public FlatBloomFilterIndex() {
23 | }
24 |
25 | @Override
26 | public int deleteFromIndex(int id, InsDelUpdateStatistics stat) {
27 | int index = idMap.remove(id);
28 | idMap.remove(id);
29 | busy.unset(index);
30 | if (busy.getWord(index / 64) == 0) {
31 | for (int k = index / 64 * 64; k < index / 64 * 64 + 64; ++k)
32 | fromindextoId.remove(k);
33 | buffer.remove(index / 64);
34 | busy.removeWord(index / 64);
35 | for (Map.Entry me : idMap.entrySet()) {
36 | if (me.getValue().intValue() / 64 >= index / 64) {
37 | idMap.put(me.getKey(), me.getValue()
38 | .intValue() - 64);
39 | }
40 | }
41 | } else {
42 | clearBloomAt(index);
43 | }
44 | return 0;
45 | }
46 |
47 | @Override
48 | public int getBloomFilterSize() {
49 | if (buffer.isEmpty())
50 | return 0;
51 | else
52 | return buffer.get(0).length;
53 | }
54 |
55 | @Override
56 | public int getHeight() {
57 | return 0;
58 | }
59 |
60 | @Override
61 | public Set getIDs() {
62 | return idMap.keySet();
63 | }
64 |
65 | @Override
66 | public boolean getIsRootAllOne() {
67 | return false;
68 | }
69 |
70 | @Override
71 | public int getNbChildrenRoot() {
72 | return 0;// no root
73 | }
74 |
75 | @Override
76 | public int getSize() {
77 | return idMap.size();
78 | }
79 |
80 | @Override
81 | public void insertBloomFilter(BloomFilter bf,
82 | InsDelUpdateStatistics stat) {
83 | if (h != null) {
84 | if (bf.getHasher() != h)
85 | throw new RuntimeException(
86 | "You are using more than one hasher");
87 | } else
88 | h = bf.getHasher();
89 | int i = busy.nextUnsetBit(0);
90 | if (i < 0) {
91 | i = busy.length();
92 | busy.resize(busy.length() + 64);
93 | buffer.add(new long[bf.getBitSet().length()]);
94 | }
95 | if (i < fromindextoId.size()) {
96 | fromindextoId.set(i, bf.getID());
97 | } else { // if(i == fromindextoId.size()) {
98 | fromindextoId.add(bf.getID());
99 | }
100 | setBloomAt(i, bf.getBitSet());
101 | idMap.put(bf.getID(), i);
102 | busy.set(i);
103 | }
104 |
105 | @Override
106 | public List search(E o, SearchStatistics stat) {
107 | ArrayList answer = new ArrayList();
108 | for (int i = 0; i < buffer.size(); ++i) {
109 | long w = ~0l;
110 | for (int l = 0; l < h.getNumberOfHashFunctions(); ++l) {
111 | final int hashvalue = h.hash(o, l);
112 | w &= buffer.get(i)[hashvalue];
113 | }
114 |
115 | while (w != 0) {
116 | long t = w & -w;
117 | answer.add(fromindextoId.get(i * 64
118 | + Long.bitCount(t - 1)));
119 | w ^= t;
120 | }
121 | }
122 | return answer;
123 | }
124 |
125 | @Override
126 | // this assumes that the bloom filter only received new values
127 | public int updateIndex(BloomFilter newBloomFilter,
128 | InsDelUpdateStatistics stat) {
129 | if (h != null) {
130 | if (newBloomFilter.getHasher() != h)
131 | throw new RuntimeException(
132 | "You are using more than one hasher");
133 | } else
134 | h = newBloomFilter.getHasher();
135 | setBloomAt(idMap.get(newBloomFilter.getID()),
136 | newBloomFilter.getBitSet());
137 | return 0;
138 | }
139 |
140 | // this is like updateIndex except that it does not
141 | // assume that the BloomFilter was only updated through the addition
142 | // of values.
143 | public int replaceIndex(BloomFilter newBloomFilter) {
144 | if (h != null) {
145 | if (newBloomFilter.getHasher() != h)
146 | throw new RuntimeException(
147 | "You are using more than one hasher");
148 | } else
149 | h = newBloomFilter.getHasher();
150 | replaceBloomAt(idMap.get(newBloomFilter.getID()),
151 | newBloomFilter.getBitSet());
152 | return 0;
153 | }
154 |
155 | private void clearBloomAt(int i) {
156 | final long[] mybuffer = buffer.get(i / 64);
157 | final long mask = ~(1l << i);
158 | for (int k = 0; k < mybuffer.length; ++k) {
159 | mybuffer[k] &= mask;
160 | }
161 | }
162 |
163 | private void setBloomAt(int i, BitSet bs) {
164 | final long[] mybuffer = buffer.get(i / 64);
165 | if (bs.length() != mybuffer.length)
166 | throw new RuntimeException("BitSet has unexpected size");
167 | final long mask = (1l << i);
168 | for (int k = bs.nextSetBit(0); k >= 0; k = bs.nextSetBit(k + 1)) {
169 | mybuffer[k] |= mask;
170 | }
171 | }
172 |
173 | private void replaceBloomAt(int i, BitSet bs) {
174 | long[] mybuffer = buffer.get(i / 64);
175 | if (bs.length() != mybuffer.length)
176 | throw new RuntimeException("BitSet has unexpected size");
177 | final long mask = (1l << i);
178 |
179 | for (int k = 0; k < mybuffer.length; ++k) {
180 | if (bs.get(k))
181 | mybuffer[k] |= mask;
182 | else
183 | mybuffer[k] &= ~mask;
184 | }
185 | }
186 |
187 |
188 | private ArrayList fromindextoId = new ArrayList();
189 |
190 | private Hashtable idMap = new Hashtable();
191 |
192 | ArrayList buffer = new ArrayList(0);
193 |
194 | BitSet busy = new BitSet(0);
195 |
196 | Hasher h;
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/src/com/googlecode/javaewah/datastructure/BitSet.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.javaewah.datastructure;
2 |
3 | import java.util.Arrays;
4 |
5 | /**
6 | * This is an optimized version of Java's BitSet.
7 | *
8 | * @author Daniel Lemire
9 | * @since 0.8.0
10 | **/
11 | public final class BitSet implements Cloneable {
12 | /**
13 | * Construct a bitset with the specified number of bits (initially all
14 | * false). The number of bits is rounded up to the nearest multiple of
15 | * 64.
16 | *
17 | * @param sizeinbits
18 | * the size in bits
19 | */
20 | public BitSet(final int sizeinbits) {
21 | if (sizeinbits < 0)
22 | throw new NegativeArraySizeException(
23 | "negative number of bits: " + sizeinbits);
24 | this.data = new long[(sizeinbits + 63) / 64];
25 | }
26 |
27 | public int andcardinality(BitSet bs) {
28 | if (data.length != bs.data.length)
29 | throw new IllegalArgumentException(
30 | "incompatible bitsets");
31 | int sum = 0;
32 | for (int k = 0; k < data.length; ++k) {
33 | sum += Long.bitCount(data[k] & bs.data[k]);
34 | }
35 | return sum;
36 | }
37 |
38 | /**
39 | * Compute the number of bits set to 1
40 | *
41 | * @return the number of bits
42 | */
43 | public int cardinality() {
44 | int sum = 0;
45 | for (long l : this.data)
46 | sum += Long.bitCount(l);
47 | return sum;
48 | }
49 |
50 | /**
51 | * Reset all bits to false
52 | */
53 | public void clear() {
54 | Arrays.fill(this.data, 0);
55 | }
56 |
57 | @Override
58 | public BitSet clone() {
59 | BitSet b;
60 | try {
61 | b = (BitSet) super.clone();
62 | b.data = Arrays.copyOf(this.data, this.data.length);
63 | return b;
64 | } catch (CloneNotSupportedException e) {
65 | return null;
66 | }
67 | }
68 |
69 | @Override
70 | public boolean equals(Object o) {
71 | if (!(o instanceof BitSet))
72 | return false;
73 | return Arrays.equals(data, ((BitSet) o).data);
74 | }
75 |
76 | /**
77 | * @param i
78 | * index
79 | * @return value of the bit
80 | */
81 | public boolean get(final int i) {
82 | return (this.data[i / 64] & (1l << (i % 64))) != 0;
83 | }
84 |
85 | public long getWord(int i) {
86 | return data[i];
87 | }
88 |
89 | @Override
90 | public int hashCode() {
91 | return Arrays.hashCode(data);
92 | }
93 |
94 | /**
95 | * Query the size
96 | *
97 | * @return the size in bits.
98 | */
99 | public int length() {
100 | return this.data.length * 64;
101 | }
102 |
103 | /**
104 | * Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) {
105 | * operate on index i here }
106 | *
107 | * @param i
108 | * current set bit
109 | * @return next set bit or -1
110 | */
111 | public int nextSetBit(final int i) {
112 | int x = i / 64;
113 | if (x >= this.data.length)
114 | return -1;
115 | long w = this.data[x];
116 | w >>>= (i % 64);
117 | if (w != 0) {
118 | return i + Long.numberOfTrailingZeros(w);
119 | }
120 | ++x;
121 | for (; x < this.data.length; ++x) {
122 | if (this.data[x] != 0) {
123 | return x
124 | * 64
125 | + Long.numberOfTrailingZeros(this.data[x]);
126 | }
127 | }
128 | return -1;
129 | }
130 |
131 | /**
132 | * Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1))
133 | * { operate on index i here }
134 | *
135 | * @param i
136 | * current unset bit
137 | * @return next unset bit or -1
138 | */
139 | public int nextUnsetBit(final int i) {
140 | int x = i / 64;
141 | if (x >= this.data.length)
142 | return -1;
143 | long w = ~this.data[x];
144 | w >>>= (i % 64);
145 | if (w != 0) {
146 | return i + Long.numberOfTrailingZeros(w);
147 | }
148 | ++x;
149 | for (; x < this.data.length; ++x) {
150 | if (this.data[x] != ~0) {
151 | return x
152 | * 64
153 | + Long.numberOfTrailingZeros(~this.data[x]);
154 | }
155 | }
156 | return -1;
157 | }
158 |
159 | /**
160 | * Compute bitwise OR, assumes that both bitsets have the same length.
161 | *
162 | * @param bs
163 | * other bitset
164 | */
165 | public void or(BitSet bs) {
166 | if (data.length != bs.data.length)
167 | throw new IllegalArgumentException(
168 | "incompatible bitsets");
169 | for (int k = 0; k < data.length; ++k) {
170 | data[k] |= bs.data[k];
171 | }
172 | }
173 |
174 | public int orcardinality(BitSet bs) {
175 | if (data.length != bs.data.length)
176 | throw new IllegalArgumentException(
177 | "incompatible bitsets");
178 | int sum = 0;
179 | for (int k = 0; k < data.length; ++k) {
180 | sum += Long.bitCount(data[k] | bs.data[k]);
181 | }
182 | return sum;
183 | }
184 |
185 | public void removeWord(int i) {
186 | long[] newdata = new long[data.length - 1];
187 | if (i == 0) {
188 | System.arraycopy(data, 1, newdata, 0, i - 1);
189 | }
190 | System.arraycopy(data, 0, newdata, 0, i - 1);
191 | System.arraycopy(data, i, newdata, i - 1, data.length - i);
192 | data = newdata;
193 | }
194 |
195 | /**
196 | * Resize the bitset
197 | *
198 | * @param sizeinbits
199 | * new number of bits
200 | */
201 | public void resize(int sizeinbits) {
202 | this.data = Arrays.copyOf(this.data, (sizeinbits + 63) / 64);
203 | }
204 |
205 | /**
206 | * Set to true
207 | *
208 | * @param i
209 | * index of the bit
210 | */
211 | public void set(final int i) {
212 | this.data[i / 64] |= (1l << (i % 64));
213 | }
214 |
215 | /**
216 | * @param i
217 | * index
218 | * @param b
219 | * value of the bit
220 | */
221 | public void set(final int i, final boolean b) {
222 | if (b)
223 | set(i);
224 | else
225 | unset(i);
226 | }
227 |
228 | /**
229 | * Set to false
230 | *
231 | * @param i
232 | * index of the bit
233 | */
234 | public void unset(final int i) {
235 | this.data[i / 64] &= ~(1l << (i % 64));
236 | }
237 |
238 | public int xorcardinality(BitSet bs) {
239 | if (data.length != bs.data.length)
240 | throw new IllegalArgumentException(
241 | "incompatible bitsets");
242 | int sum = 0;
243 | for (int k = 0; k < data.length; ++k) {
244 | sum += Long.bitCount(data[k] ^ bs.data[k]);
245 | }
246 | return sum;
247 | }
248 |
249 | private long[] data;
250 |
251 | }
252 |
--------------------------------------------------------------------------------
/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
--------------------------------------------------------------------------------
/test/com/skjegstad/utils/BloomFilterTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU Lesser General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * (at your option) any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with this program. If not, see .
14 | */
15 |
16 | package com.skjegstad.utils;
17 |
18 | import java.util.List;
19 | import java.io.UnsupportedEncodingException;
20 | import java.util.Random;
21 | import java.util.UUID;
22 | import java.util.ArrayList;
23 |
24 | import mvm.provenance.Hasher;
25 |
26 | import org.junit.Test;
27 | import static org.junit.Assert.*;
28 |
29 | /**
30 | * Tests for BloomFilter.java
31 | *
32 | * @author Magnus Skjegstad
33 | */
34 |
35 | @SuppressWarnings({"static-method","rawtypes"})
36 | public class BloomFilterTest {
37 | static Random r = new Random();
38 | @Test
39 | public void testConstructorCNK() throws Exception {
40 | System.out.println("BloomFilter(c,n,k)");
41 |
42 | for (int i = 0; i < 10000; i++) {
43 | double c = r.nextInt(20)+1 ;
44 | int n = r.nextInt(10000) + 1;
45 | int k = r.nextInt(20) + 1;
46 | BloomFilter bf = new BloomFilter(new Hasher(), c, n, k,1);
47 | assertEquals(bf.getK(), k);
48 | assertEquals(bf.getExpectedBitsPerElement(), c, 0);
49 | assertEquals(bf.getExpectedNumberOfElements(), n);
50 | assertEquals(bf.size(), c*n, 0);
51 | }
52 | }
53 |
54 |
55 | /**
56 | * Test of createHash method, of class BloomFilter.
57 | * @throws Exception
58 | */
59 | /*@Test
60 | public void testCreateHash_String() throws Exception {
61 | System.out.println("createHash");
62 | String val = UUID.randomUUID().toString();
63 | long result1 = BloomFilter.createHash(val);
64 | long result2 = BloomFilter.createHash(val);
65 | assertEquals(result2, result1);
66 | long result3 = BloomFilter.createHash(UUID.randomUUID().toString());
67 | assertNotSame(result3, result2);
68 |
69 | long result4 = BloomFilter.createHash(val.getBytes("UTF-8"));
70 | assertEquals(result4, result1);
71 | }*/
72 |
73 | /**
74 | * Test of createHash method, of class BloomFilter.
75 | * @throws UnsupportedEncodingException
76 | */
77 | /*Test
78 | public void testCreateHash_byteArr() throws UnsupportedEncodingException {
79 | System.out.println("createHash");
80 | String val = UUID.randomUUID().toString();
81 | byte[] data = val.getBytes("UTF-8");
82 | long result1 = BloomFilter.createHash(data);
83 | long result2 = BloomFilter.createHash(val);
84 | assertEquals(result1, result2);
85 | }*/
86 |
87 | /**
88 | * Test of equals method, of class BloomFilter.
89 | * @throws UnsupportedEncodingException
90 | */
91 | @Test
92 | public void testEquals() throws UnsupportedEncodingException {
93 | System.out.println("equals");
94 | Hasher h = new Hasher();
95 | BloomFilter instance1 = new BloomFilter(h,1000, 100);
96 | BloomFilter instance2 = new BloomFilter(h,1000, 100);
97 |
98 | for (int i = 0; i < 100; i++) {
99 | String val = UUID.randomUUID().toString();
100 | instance1.add(val);
101 | instance2.add(val);
102 | }
103 |
104 | assert(instance1.equals(instance2));
105 | assert(instance2.equals(instance1));
106 |
107 | instance1.add("Another entry"); // make instance1 and instance2 different before clearing
108 |
109 | instance1.clear();
110 | instance2.clear();
111 |
112 | assert(instance1.equals(instance2));
113 | assert(instance2.equals(instance1));
114 |
115 | for (int i = 0; i < 100; i++) {
116 | String val = UUID.randomUUID().toString();
117 | instance1.add(val);
118 | instance2.add(val);
119 | }
120 |
121 | assertTrue(instance1.equals(instance2));
122 | assertTrue(instance2.equals(instance1));
123 | }
124 |
125 | /**
126 | * Test of hashCode method, of class BloomFilter.
127 | * @throws UnsupportedEncodingException
128 | */
129 | @Test
130 | public void testHashCode() throws UnsupportedEncodingException {
131 | System.out.println("hashCode");
132 | Hasher h = new Hasher();
133 |
134 | BloomFilter instance1 = new BloomFilter(h,1000, 100);
135 | BloomFilter instance2 = new BloomFilter(h,1000, 100);
136 |
137 | assertTrue(instance1.hashCode() == instance2.hashCode());
138 |
139 | for (int i = 0; i < 100; i++) {
140 | String val = UUID.randomUUID().toString();
141 | instance1.add(val);
142 | instance2.add(val);
143 | }
144 |
145 | assertTrue(instance1.hashCode() == instance2.hashCode());
146 |
147 | instance1.clear();
148 | instance2.clear();
149 |
150 | assertTrue(instance1.hashCode() == instance2.hashCode());
151 |
152 | instance1 = new BloomFilter(new Hasher(),100, 10);
153 | instance2 = new BloomFilter(new Hasher(),100, 9);
154 | assertFalse(instance1.hashCode() == instance2.hashCode());
155 |
156 | instance1 = new BloomFilter(new Hasher(),100, 10);
157 | instance2 = new BloomFilter(new Hasher(),99, 9);
158 | assertFalse(instance1.hashCode() == instance2.hashCode());
159 |
160 | instance1 = new BloomFilter(new Hasher(),100, 10);
161 | instance2 = new BloomFilter(new Hasher(),50, 10);
162 | assertFalse(instance1.hashCode() == instance2.hashCode());
163 | }
164 |
165 | /**
166 | * Test of expectedFalsePositiveProbability method, of class BloomFilter.
167 | */
168 | @Test
169 | public void testExpectedFalsePositiveProbability() {
170 | // These probabilities are taken from the bloom filter probability table at
171 | // http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
172 | System.out.println("expectedFalsePositiveProbability");
173 | BloomFilter instance = new BloomFilter(new Hasher(),1000, 100);
174 | double expResult = 0.00819; // m/n=10, k=7
175 | double result = instance.expectedFalsePositiveProbability();
176 | assertEquals(instance.getK(), 7);
177 | assertEquals(expResult, result, 0.000009);
178 |
179 | instance = new BloomFilter(new Hasher(),100, 10);
180 | expResult = 0.00819; // m/n=10, k=7
181 | result = instance.expectedFalsePositiveProbability();
182 | assertEquals(instance.getK(), 7);
183 | assertEquals(expResult, result, 0.000009);
184 |
185 | instance = new BloomFilter(new Hasher(),20, 10);
186 | expResult = 0.393; // m/n=2, k=1
187 | result = instance.expectedFalsePositiveProbability();
188 | assertEquals(1, instance.getK());
189 | assertEquals(expResult, result, 0.0005);
190 |
191 | instance = new BloomFilter(new Hasher(),110, 10);
192 | expResult = 0.00509; // m/n=11, k=8
193 | result = instance.expectedFalsePositiveProbability();
194 | assertEquals(8, instance.getK());
195 | assertEquals(expResult, result, 0.00001);
196 | }
197 |
198 | /**
199 | * Test of clear method, of class BloomFilter.
200 | */
201 | @Test
202 | public void testClear() {
203 | System.out.println("clear");
204 | Hasher h = new Hasher();
205 | BloomFilter instance = new BloomFilter(h,1000, 100);
206 | for (int i = 0; i < instance.size(); i++)
207 | instance.setBit(i, true);
208 | instance.clear();
209 | for (int i = 0; i < instance.size(); i++)
210 | assertSame(instance.getBitSet().get(i), false);
211 | }
212 |
213 | /**
214 | * Test of add method, of class BloomFilter.
215 | * @throws Exception
216 | */
217 | @Test
218 | public void testAdd() throws Exception {
219 | System.out.println("add");
220 |
221 | Hasher h = new Hasher();
222 | BloomFilter instance = new BloomFilter(h,1000, 100);
223 |
224 | for (int i = 0; i < 100; i++) {
225 | String val = UUID.randomUUID().toString();
226 | instance.add(val);
227 | assert(instance.contains(val));
228 | }
229 | }
230 |
231 | /**
232 | * Test of addAll method, of class BloomFilter.
233 | * @throws Exception
234 | */
235 | @Test
236 | public void testAddAll() throws Exception {
237 | System.out.println("addAll");
238 | List v = new ArrayList();
239 |
240 | Hasher h = new Hasher();
241 | BloomFilter instance = new BloomFilter(h,1000, 100);
242 |
243 | for (int i = 0; i < 100; i++)
244 | v.add(UUID.randomUUID().toString());
245 |
246 | instance.addAll(v);
247 |
248 | for (int i = 0; i < 100; i++)
249 | assert(instance.contains(v.get(i)));
250 | }
251 |
252 | /**
253 | * Test of contains method, of class BloomFilter.
254 | * @throws Exception
255 | */
256 | @Test
257 | public void testContains() throws Exception {
258 | System.out.println("contains");
259 |
260 | Hasher h = new Hasher();
261 | BloomFilter instance = new BloomFilter(h,10000, 10);
262 |
263 | for (int i = 0; i < 10; i++) {
264 | instance.add(Integer.toBinaryString(i));
265 | assert(instance.contains(Integer.toBinaryString(i)));
266 | }
267 |
268 | assertFalse(instance.contains(UUID.randomUUID().toString()));
269 | }
270 |
271 | /**
272 | * Test of containsAll method, of class BloomFilter.
273 | * @throws Exception
274 | */
275 | @Test
276 | public void testContainsAll() throws Exception {
277 | System.out.println("containsAll");
278 | List v = new ArrayList();
279 |
280 | Hasher h = new Hasher();
281 | BloomFilter instance = new BloomFilter(h,1000, 100);
282 |
283 | for (int i = 0; i < 100; i++) {
284 | v.add(UUID.randomUUID().toString());
285 | instance.add(v.get(i));
286 | }
287 |
288 | assert(instance.containsAll(v));
289 | }
290 |
291 | /**
292 | * Test of getBit method, of class BloomFilter.
293 | */
294 | @Test
295 | public void testGetBit() {
296 | System.out.println("getBit");
297 |
298 | Hasher h = new Hasher();
299 | BloomFilter instance = new BloomFilter(h,1000, 100);
300 |
301 | for (int i = 0; i < 100; i++) {
302 | boolean b = r.nextBoolean();
303 | instance.setBit(i, b);
304 | assertSame(instance.getBitSet().get(i), b);
305 | }
306 | }
307 |
308 | /**
309 | * Test of setBit method, of class BloomFilter.
310 | */
311 | @Test
312 | public void testSetBit() {
313 | System.out.println("setBit");
314 |
315 | Hasher h = new Hasher();
316 | BloomFilter instance = new BloomFilter(h,1000, 100);
317 | //Random r = new Random();
318 |
319 | for (int i = 0; i < 100; i++) {
320 | instance.setBit(i, true);
321 | assertSame(instance.getBitSet().get(i), true);
322 | }
323 |
324 | for (int i = 0; i < 100; i++) {
325 | instance.setBit(i, false);
326 | assertSame(instance.getBitSet().get(i), false);
327 | }
328 | }
329 |
330 | /**
331 | * Test of size method, of class BloomFilter.
332 | */
333 | @Test
334 | public void testSize() {
335 | System.out.println("size");
336 |
337 | for (int i = 100; i < 1000; i++) {
338 | BloomFilter instance = new BloomFilter(new Hasher(),i, 10);
339 | assertEquals(instance.size(), i);
340 | }
341 | }
342 |
343 | /** Test error rate *
344 | * @throws UnsupportedEncodingException
345 | */
346 | @Test
347 | public void testFalsePositiveRate1() throws UnsupportedEncodingException {
348 | // Numbers are from // http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
349 | System.out.println("falsePositiveRate1");
350 |
351 | for (int j = 10; j < 21; j++) {
352 | System.out.print(j-9 + "/11");
353 | List v = new ArrayList();
354 | BloomFilter instance = new BloomFilter(new Hasher(),100*j,100);
355 |
356 | for (int i = 0; i < 100; i++) {
357 | v.add(UUID.randomUUID().toString());
358 | }
359 | instance.addAll(v);
360 |
361 | long rr = 0;
362 | double tests = 100000;
363 | for (int i = 0; i < tests; i++) {
364 | String s = UUID.randomUUID().toString();
365 | if (instance.contains(s)) {
366 | if (!v.contains(s)) {
367 | rr++;
368 | }
369 | }
370 | }
371 |
372 | double ratio = rr / tests;
373 |
374 | System.out.println(" - got " + ratio + ", math says " + instance.expectedFalsePositiveProbability());
375 | assertEquals(instance.expectedFalsePositiveProbability(), ratio, 0.01);
376 |
377 |
378 | }
379 | }
380 |
381 | /** Test for correct k **/
382 | @Test
383 | public void testGetK() {
384 | // Numbers are from http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
385 | System.out.println("testGetK");
386 |
387 | BloomFilter instance = null;
388 |
389 | instance = new BloomFilter(new Hasher(),2, 1);
390 | assertEquals(1, instance.getK());
391 |
392 | instance = new BloomFilter(new Hasher(),3, 1);
393 | assertEquals(2, instance.getK());
394 |
395 | instance = new BloomFilter(new Hasher(),4, 1);
396 | assertEquals(3, instance.getK());
397 |
398 | instance = new BloomFilter(new Hasher(),5, 1);
399 | assertEquals(3, instance.getK());
400 |
401 | instance = new BloomFilter(new Hasher(),6, 1);
402 | assertEquals(4, instance.getK());
403 |
404 | instance = new BloomFilter(new Hasher(),7, 1);
405 | assertEquals(5, instance.getK());
406 |
407 | instance = new BloomFilter(new Hasher(),8, 1);
408 | assertEquals(6, instance.getK());
409 |
410 | instance = new BloomFilter(new Hasher(),9, 1);
411 | assertEquals(6, instance.getK());
412 |
413 | instance = new BloomFilter(new Hasher(),10, 1);
414 | assertEquals(7, instance.getK());
415 |
416 | instance = new BloomFilter(new Hasher(),11, 1);
417 | assertEquals(8, instance.getK());
418 |
419 | instance = new BloomFilter(new Hasher(),12, 1);
420 | assertEquals(8, instance.getK());
421 | }
422 |
423 |
424 | }
--------------------------------------------------------------------------------
/src/com/skjegstad/utils/BloomFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU Lesser General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * (at your option) any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU Lesser General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU Lesser General Public License
13 | * along with this program. If not, see .
14 | */
15 |
16 | package com.skjegstad.utils;
17 |
18 | import java.io.Serializable;
19 | import com.googlecode.javaewah.datastructure.BitSet;
20 | import java.util.Collection;
21 | import java.util.List;
22 | import mvm.provenance.Hasher;
23 |
24 | /**
25 | *
26 | *
27 | * Implementation of a Bloom-filter, as described here:
28 | * http://en.wikipedia.org/wiki/Bloom_filter
29 | *
30 | * Inspired by the SimpleBloomFilter-class written by Ian Clarke. This
31 | * implementation provides a more evenly distributed Hash-function by using a
32 | * proper digest instead of the Java RNG. Many of the changes were proposed in
33 | * comments in his blog:
34 | * http://blog.locut.us/2008/01/12/a-decent-stand-alone-java
35 | * -bloom-filter-implementation/
36 | *
37 | * @param
38 | * Object type that is to be inserted into the Bloom filter, e.g.
39 | * String or Integer.
40 | * @author Magnus Skjegstad magnus@skjegstad.com
41 | */
42 | public final class BloomFilter implements Serializable {
43 |
44 | /**
45 | * Constructs an empty Bloom filter with a given false positive
46 | * probability. The number of bits per element and the number of hash
47 | * functions is estimated to match the false positive probability.
48 | *
49 | * @param falsePositiveProbability
50 | * is the desired false positive probability.
51 | * @param expectedNumberOfElements
52 | * is the expected number of elements in the Bloom
53 | * filter.
54 | */
55 | public BloomFilter(final Hasher hash, double falsePositiveProbability,
56 | int expectedNumberOfElements, int metric) {
57 | this(hash, Math
58 | .ceil(-(Math.log(falsePositiveProbability) / Math
59 | .log(2)))
60 | / Math.log(2), // c = k / ln(2)
61 | expectedNumberOfElements, (int) Math.ceil(-(Math
62 | .log(falsePositiveProbability) / Math.log(2))),
63 | metric); // k = ceil(-log_2(false prob.))
64 | }
65 | /**
66 | * Constructs an empty Bloom filter. The total length of the Bloom
67 | * filter will be c*n.
68 | *
69 | * @param c
70 | * is the number of bits used per element.
71 | * @param n
72 | * is the expected number of elements the filter will
73 | * contain.
74 | * @param k
75 | * is the number of hash functions used.
76 | */
77 | public BloomFilter(final Hasher hash, final double c, final int n,
78 | final int k, final int metric) {
79 | this.h = hash;
80 | this.expectedNumberOfFilterElements = n;
81 | hash.setNumberOfRandomKeys(k);
82 | this.k = k;
83 | this.bitsPerElement = c;
84 | this.bitSetSize = (int) Math.ceil(c * n);
85 | hash.setMaxValue(bitSetSize);
86 | numberOfAddedElements = 0;
87 | this.bitset = new BitSet(bitSetSize);
88 | // AC: add an ID for every BloomFilter created
89 | lastID++;
90 | this.id = lastID;
91 | // AC: set the metric used
92 | this.metric = metric;
93 | }
94 | // D. Lemire : hack for the unit tests to compile, default on metric 1
95 | public BloomFilter(Hasher hash, int n, int k) {
96 | this(hash, n, k, 1);
97 | }
98 |
99 | /**
100 | * Constructs an empty Bloom filter. The optimal number of hash
101 | * functions (k) is estimated from the total size of the Bloom and the
102 | * number of expected elements.
103 | *
104 | * @param bitSetSize
105 | * defines how many bits should be used in total for the
106 | * filter.
107 | * @param expectedNumberOElements
108 | * defines the maximum number of elements the filter is
109 | * expected to contain.
110 | */
111 | public BloomFilter(final Hasher hash, int bitSetSize,
112 | int expectedNumberOElements, int metric) {
113 | this(
114 | hash,
115 | bitSetSize / (double) expectedNumberOElements,
116 | expectedNumberOElements,
117 | (int) Math
118 | .round((bitSetSize / (double) expectedNumberOElements)
119 | * Math.log(2.0)), metric);
120 | assert bitSetSize == this.bitSetSize;
121 | }
122 |
123 | /**
124 | * Construct a new Bloom filter based on existing Bloom filter data.
125 | *
126 | * @param bitSetSize
127 | * defines how many bits should be used for the filter.
128 | * @param expectedNumberOfFilterElements
129 | * defines the maximum number of elements the filter is
130 | * expected to contain.
131 | * @param actualNumberOfFilterElements
132 | * specifies how many elements have been inserted into
133 | * the filterData BitSet.
134 | * @param filterData
135 | * a BitSet representing an existing Bloom filter.
136 | */
137 | public BloomFilter(final Hasher hash, int bitSetSize,
138 | int expectedNumberOfFilterElements,
139 | int actualNumberOfFilterElements, BitSet filterData, int metric) {
140 | this(hash, bitSetSize, expectedNumberOfFilterElements, metric);
141 | this.bitset = filterData;
142 | this.numberOfAddedElements = actualNumberOfFilterElements;
143 | }
144 | /**
145 | * Adds an object to the Bloom filter. The output from the object's
146 | * toString() method is used as input to the hash functions.
147 | *
148 | * @param element
149 | * is an element to register in the Bloom filter.
150 | */
151 | public void add(E element) {
152 | for (int x = 0; x < k; x++) {
153 | final int hashvalue = h.hash(element, x);
154 | bitset.set(hashvalue);
155 | }
156 | numberOfAddedElements++;
157 | }
158 | /**
159 | * Adds all elements from a Collection to the Bloom filter.
160 | *
161 | * @param c
162 | * Collection of elements.
163 | */
164 | public void addAll(Collection extends E> c) {
165 | for (E element : c)
166 | add(element);
167 | }
168 | /**
169 | * Sets all bits to false in the Bloom filter.
170 | */
171 | public void clear() {
172 | bitset.clear();
173 | numberOfAddedElements = 0;
174 | }
175 | /**
176 | * Compute the distance between this filter and the one received as
177 | * param.
178 | * If similarity metric to be used is 2 use Jaccard, if 3 use cosine, everything
179 | * else Hamming
180 | *
181 | * @param filter
182 | *
183 | * @return
184 | * @author Adina Crainiceanu
185 | */
186 | public double computeDistance(BloomFilter filter) {
187 |
188 | if (this.metric == 2)
189 | return computeJaccardDistance(filter);
190 | else if (this.metric == 3)
191 | return computeCosineDistance(filter);
192 | return computeHammingDistance(filter);
193 |
194 | }
195 | /**
196 | * Returns true if the element could have been inserted into the Bloom
197 | * filter. Use getFalsePositiveProbability() to calculate the
198 | * probability of this being correct.
199 | *
200 | * @param element
201 | * element to check.
202 | * @return true if the element could have been inserted into the Bloom
203 | * filter.
204 | */
205 | public boolean contains(E element) {
206 | // String valString = element.toString();
207 | for (int x = 0; x < k; x++) {
208 | final int hash = h.hash(element, x);
209 | if (!bitset.get(hash))
210 | return false;
211 | }
212 | return true;
213 | }
214 | /**
215 | * Returns true if all the elements of a Collection could have been
216 | * inserted into the Bloom filter. Use getFalsePositiveProbability() to
217 | * calculate the probability of this being correct.
218 | *
219 | * @param c
220 | * elements to check.
221 | * @return true if all the elements in c could have been inserted into
222 | * the Bloom filter.
223 | */
224 | public boolean containsAll(Collection extends E> c) {
225 | for (E element : c)
226 | if (!contains(element))
227 | return false;
228 | return true;
229 | }
230 |
231 | /**
232 | * Returns the number of elements added to the Bloom filter after it was
233 | * constructed or after clear() was called.
234 | *
235 | * @return number of elements added to the Bloom filter.
236 | */
237 | public int count() {
238 | return this.numberOfAddedElements;
239 | }
240 |
241 | /**
242 | * Compares the contents of two instances to see if they are equal.
243 | *
244 | * @param obj
245 | * is the object to compare to.
246 | * @return True if the contents of the objects are equal.
247 | */
248 | @Override
249 | public boolean equals(Object obj) {
250 | if (obj == null) {
251 | return false;
252 | }
253 | if (getClass() != obj.getClass()) {
254 | return false;
255 | }
256 | @SuppressWarnings("unchecked")
257 | final BloomFilter other = (BloomFilter) obj;
258 | if (this.expectedNumberOfFilterElements != other.expectedNumberOfFilterElements) {
259 | return false;
260 | }
261 | if (this.k != other.k) {
262 | return false;
263 | }
264 | if (this.bitSetSize != other.bitSetSize) {
265 | return false;
266 | }
267 | if (this.bitset != other.bitset
268 | && (this.bitset == null || !this.bitset
269 | .equals(other.bitset))) {
270 | return false;
271 | }
272 | return true;
273 | }
274 |
275 | /**
276 | * Calculates the expected probability of false positives based on the
277 | * number of expected filter elements and the size of the Bloom filter.
278 | *
279 | * The value returned by this method is the expected rate of
280 | * false positives, assuming the number of inserted elements equals the
281 | * number of expected elements. If the number of elements in the Bloom
282 | * filter is less than the expected value, the true probability of false
283 | * positives will be lower.
284 | *
285 | * @return expected probability of false positives.
286 | */
287 | public double expectedFalsePositiveProbability() {
288 | return getFalsePositiveProbability(expectedNumberOfFilterElements);
289 | }
290 |
291 | /**
292 | * Find the index of closest element in a list
293 | *
294 | * @param bfList
295 | * @return
296 | */
297 | public int findClosest(List> bfList) {
298 |
299 | // return null if no element to compare with
300 | if (bfList.isEmpty())
301 | return -1;
302 |
303 | // initialize min distance to be distance to first element
304 | double minDistance = this.computeDistance(bfList.get(0));
305 | int minIndex = 0;
306 | double currentDistance;
307 |
308 | // loop through all elements to find the closest
309 | for (int i = 1; i < bfList.size(); i++) {
310 | currentDistance = this.computeDistance(bfList.get(i));
311 | if (currentDistance < minDistance) {
312 | minDistance = currentDistance;
313 | minIndex = i;
314 | }
315 | }
316 |
317 | return minIndex;
318 | }
319 |
320 | /**
321 | * Return the bit set used to store the Bloom filter.
322 | *
323 | * @return bit set representing the Bloom filter.
324 | */
325 | public BitSet getBitSet() {
326 | return bitset;
327 | }
328 |
329 | /**
330 | * Get actual number of bits per element based on the number of elements
331 | * that have currently been inserted and the length of the Bloom filter.
332 | * See also getExpectedBitsPerElement().
333 | *
334 | * @return number of bits per element.
335 | */
336 | public double getBitsPerElement() {
337 | return this.bitSetSize / (double) numberOfAddedElements;
338 | }
339 |
340 | /**
341 | * Get expected number of bits per element when the Bloom filter is
342 | * full. This value is set by the constructor when the Bloom filter is
343 | * created. See also getBitsPerElement().
344 | *
345 | * @return expected number of bits per element.
346 | */
347 | public double getExpectedBitsPerElement() {
348 | return this.bitsPerElement;
349 | }
350 |
351 | /**
352 | * Returns the expected number of elements to be inserted into the
353 | * filter. This value is the same value as the one passed to the
354 | * constructor.
355 | *
356 | * @return expected number of elements.
357 | */
358 | public int getExpectedNumberOfElements() {
359 | return expectedNumberOfFilterElements;
360 | }
361 |
362 | /**
363 | * Get the current probability of a false positive. The probability is
364 | * calculated from the size of the Bloom filter and the current number
365 | * of elements added to it.
366 | *
367 | * @return probability of false positives.
368 | */
369 | public double getFalsePositiveProbability() {
370 | return getFalsePositiveProbability(numberOfAddedElements);
371 | }
372 |
373 | /**
374 | * Calculate the probability of a false positive given the specified
375 | * number of inserted elements.
376 | *
377 | * @param numberOfElements
378 | * number of inserted elements.
379 | * @return probability of a false positive.
380 | */
381 | public double getFalsePositiveProbability(double numberOfElements) {
382 | // (1 - e^(-k * n / m)) ^ k
383 | return Math.pow(
384 | (1 - Math.exp(-k * numberOfElements
385 | / bitSetSize)), k);
386 |
387 | }
388 |
389 | public Hasher getHasher() {
390 | return h;
391 | }
392 |
393 | /**
394 | * Generates a digest based on the contents of a String.
395 | *
396 | * @param val
397 | * specifies the input data.
398 | * @param charset
399 | * specifies the encoding of the input data.
400 | * @return digest as long.
401 | */
402 | // public static long createHash(String val, Charset charset) {
403 | // return createHash(val.getBytes(charset));
404 | // }
405 |
406 | /**
407 | * Generates a digest based on the contents of a String.
408 | *
409 | * @param val
410 | * specifies the input data. The encoding is expected to
411 | * be UTF-8.
412 | * @return digest as long.
413 | */
414 | // public static long createHash(String val) {
415 | // return createHash(val, charset);
416 | // }
417 |
418 | /**
419 | * Generates a digest based on the contents of an array of bytes.
420 | *
421 | * @param data
422 | * specifies input data.
423 | * @return digest as long.
424 | */
425 | /*
426 | * public static long createHash(byte[] data) { long h = 0; byte[] res;
427 | *
428 | * synchronized (digestFunction) { res = digestFunction.digest(data); }
429 | *
430 | * for (int i = 0; i < 4; i++) { h <<= 8; h |= ((int) res[i]) & 0xFF; }
431 | * return h; }
432 | */
433 |
434 | /**
435 | * Get the id
436 | */
437 | public int getID() {
438 | return this.id;
439 | }
440 |
441 | /**
442 | * Returns the value chosen for K.
443 | *
444 | * K is the optimal number of hash functions based on the size of the
445 | * Bloom filter and the expected number of inserted elements.
446 | *
447 | * @return optimal k.
448 | */
449 | public int getK() {
450 | return k;
451 | }
452 |
453 | /**
454 | * Get the metric used when comparing 2 bloom filters
455 | *
456 | * @return
457 | */
458 | public int getMetric() {
459 | return this.metric;
460 | }
461 |
462 | /**
463 | * Calculates a hash code for this class.
464 | *
465 | * @return hash code representing the contents of an instance of this
466 | * class.
467 | */
468 | @Override
469 | public int hashCode() {
470 | int hash = 7;
471 | hash = 61 * hash
472 | + (this.bitset != null ? this.bitset.hashCode() : 0);
473 | hash = 61 * hash + this.expectedNumberOfFilterElements;
474 | hash = 61 * hash + this.bitSetSize;
475 | hash = 61 * hash + this.k;
476 | return hash;
477 | }
478 |
479 | public boolean isFull() {
480 | return bitset.cardinality() == bitSetSize;
481 | }
482 |
483 | /**
484 | * Compute the OR between this Bloom filter and the one received as
485 | * param The bitSet will be the or between the two bitSets, and the
486 | * number of elements added will be the sum of the counts for the two
487 | * bloom filters
488 | *
489 | * @param filter
490 | */
491 | public void orBloomFilter(BloomFilter filter) {
492 | // sanity check: Bloom filters should be of same length
493 | assert bitSetSize == filter.size() : "Different size bitsets in orBloomFIlter: "
494 | + bitSetSize + " and " + filter.size();
495 |
496 | // compute the or
497 | this.bitset.or(filter.getBitSet());
498 | this.numberOfAddedElements += filter.count();
499 |
500 | }
501 |
502 | public static void resetLastID() {
503 | lastID = 0;
504 | }
505 |
506 | /**
507 | * Set a single bit in the Bloom filter.
508 | *
509 | * @param bit
510 | * is the bit to set.
511 | * @param value
512 | * If true, the bit is set. If false, the bit is cleared.
513 | */
514 | public void setBit(int bit, boolean value) {
515 | bitset.set(bit, value);
516 | }
517 |
518 | /**
519 | * Set the id of the Bloom Filter
520 | *
521 | * @param id
522 | */
523 | public void setID(int id) {
524 | this.id = id;
525 | }
526 |
527 | /**
528 | * Returns the number of bits in the Bloom filter. Use count() to
529 | * retrieve the number of inserted elements.
530 | *
531 | * @return the size of the bitset used by the Bloom filter.
532 | */
533 | public int size() {
534 | return this.bitSetSize;
535 | }
536 |
537 | /**
538 | * Return a string representation of the Bloom filter. For now, it just
539 | * returns the bitset. TODO
540 | *
541 | * @return string representation of the Bloom filter
542 | */
543 | @Override
544 | public String toString() {
545 | return "ID:" + id + ":" + bitset.cardinality() + ":"
546 | + bitSetSize; // + ":" + bitset.toString();
547 | }
548 |
549 | /**
550 | * Read a single bit from the Bloom filter.
551 | *
552 | * @param bit
553 | * the bit to read.
554 | * @return true if the bit is set, false if it is not.
555 | */
556 | // public boolean getBit(int bit) {
557 | // return bitset.get(bit);
558 | // }
559 |
560 | /**
561 | * Compute 1- the Cosine similarity to the param filter Cosine
562 | * similarity = ab/norm(a)*norm(b)
563 | *
564 | * @param filter
565 | * @return 1- cosine similarity to the received Bloom filter
566 | * @author Adina Crainiceanu
567 | */
568 | private double computeCosineDistance(BloomFilter filter) {
569 |
570 | assert bitSetSize == filter.size() : "Different size bitsets in computeCosineDistance: "
571 | + bitSetSize + " and " + filter.size();
572 |
573 | double distance = 0;
574 | // find the max index that is not 0
575 | int maxLength = this.bitset.length();
576 | BitSet otherBitSet = filter.getBitSet();
577 | if (otherBitSet.length() > maxLength) {
578 | maxLength = otherBitSet.length();
579 | }
580 | // compute the cardinalities
581 | int countAND = this.bitset.andcardinality(filter.bitset);
582 | int count1 = this.bitset.cardinality();
583 | int count2 = filter.bitset.cardinality();
584 |
585 | // compute distance
586 | if (count1 > 0 || count2 > 0) {
587 | distance = 1.0 - countAND
588 | / (Math.sqrt(count1) * Math.sqrt(count2));
589 | }
590 | return distance;
591 | }
592 |
593 | /**
594 | * Compute the Hamming distance between this filter and the one given as
595 | * param. Hamming distance = number of positions with different value.
596 | * To compute Hamming distance, we XOR the two bitsets and take the sum
597 | * or all 1s
598 | *
599 | * @param filter
600 | * @return Hamming distance between this bloom filter and the received
601 | * Bloom filter
602 | * @author Adina Crainiceanu
603 | */
604 | private int computeHammingDistance(BloomFilter filter) {
605 |
606 | assert bitSetSize == filter.size() : "Different size bitsets in computeHammingDistance: "
607 | + bitSetSize + " and " + filter.size();
608 |
609 | return this.bitset.xorcardinality(filter.getBitSet());
610 | }
611 |
612 | /**
613 | * Compute the Jaccard distance to the param filter Jaccard distance = 1
614 | * - Jaccard similarity = 1 - size of intersection/size of union =
615 | * cardinality(A xor B)/ cardinality (A or B)
616 | *
617 | * @param filter
618 | * @return Jaccard distance to the received Bloom filter
619 | * @author Adina Crainiceanu
620 | */
621 | private double computeJaccardDistance(BloomFilter filter) {
622 |
623 | assert bitSetSize == filter.size() : "Different size bitsets in computeJaccardDistance: "
624 | + bitSetSize + " and " + filter.size();
625 |
626 | double distance = 0;
627 | // find the max index that is not 0
628 | int maxLength = this.bitset.length();
629 | BitSet otherBitSet = filter.getBitSet();
630 | if (otherBitSet.length() > maxLength) {
631 | maxLength = otherBitSet.length();
632 | }
633 | int countAND = this.bitset.andcardinality(filter.bitset);
634 | int countOR = this.bitset.orcardinality(filter.bitset);
635 |
636 | if (countOR > 0) {
637 | distance = 1.0 - (double) countAND / countOR;
638 | }
639 | return distance;
640 | }
641 |
642 | public static int getLastID() {
643 | return lastID;
644 | }
645 |
646 |
647 | public static void incrementLastID() {
648 | lastID++;
649 | }
650 |
651 | private BitSet bitset;
652 |
653 | private int bitSetSize;
654 |
655 | private double bitsPerElement;
656 |
657 | private int expectedNumberOfFilterElements; // expected (maximum) number
658 | // of elements to be added
659 | private int numberOfAddedElements; // number of elements actually added
660 |
661 | public Hasher h;
662 |
663 | private static int lastID = 0;
664 |
665 | private static final long serialVersionUID = 1L;// D. Lemire: this was
666 | // missing
667 |
668 | // Add ID so we can keep track of ID - bloom filter correspondence when
669 | // used for update
670 | private int id = 0;
671 |
672 | // to the Bloom filter
673 | private int k;
674 |
675 | // add metric to be used when comparing 2 Bloom filters
676 | // 1 if Hamming, 2 if Jaccard, 3 if cosine,
677 | // everything else Hamming
678 | private int metric = 1;
679 |
680 |
681 | }
682 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 | Must set src.dir
166 | Must set test.src.dir
167 | Must set build.dir
168 | Must set dist.dir
169 | Must set build.classes.dir
170 | Must set dist.javadoc.dir
171 | Must set build.test.classes.dir
172 | Must set build.test.results.dir
173 | Must set build.classes.excludes
174 | Must set dist.jar
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 | Must set javac.includes
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 | Must select some files in the IDE or set javac.includes
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 | To run this application from the command line without Ant, try:
463 |
464 |
465 |
466 |
467 |
468 |
469 | java -cp "${run.classpath.with.dist.jar}" ${main.class}
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 | To run this application from the command line without Ant, try:
493 |
494 | java -jar "${dist.jar.resolved}"
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 | Must select one file in the IDE or set run.class
560 |
561 |
562 |
563 | Must select one file in the IDE or set run.class
564 |
565 |
566 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 | Must select one file in the IDE or set debug.class
591 |
592 |
593 |
594 |
595 | Must select one file in the IDE or set debug.class
596 |
597 |
598 |
599 |
600 | Must set fix.includes
601 |
602 |
603 |
604 |
605 |
606 |
607 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 | Must select some files in the IDE or set javac.includes
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 | Some tests failed; see details above.
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 | Must select some files in the IDE or set test.includes
695 |
696 |
697 |
698 | Some tests failed; see details above.
699 |
700 |
701 |
706 |
707 | Must select one file in the IDE or set test.class
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
737 |
738 | Must select one file in the IDE or set applet.url
739 |
740 |
741 |
742 |
743 |
744 |
745 |
750 |
751 | Must select one file in the IDE or set applet.url
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
--------------------------------------------------------------------------------