Java Code Examples for org.apache.rocketmq.filter.util.BloomFilter#calcBitPositions()

The following examples show how to use org.apache.rocketmq.filter.util.BloomFilter#calcBitPositions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 2
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 3
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 4
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 5
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 6
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example 7
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 8
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}
 
Example 9
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 10
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}
 
Example 11
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 12
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}
 
Example 13
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 14
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}
 
Example 15
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 16
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}
 
Example 17
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Test
public void testHashTo() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    BitsArray bits = BitsArray.create(bloomFilter.getM());

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    bloomFilter.hashTo(cid, bits);

    for (int bit : bitPos) {
        assertThat(bits.getBit(bit)).isTrue();
    }
}
 
Example 18
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
@Test
public void testCalcBitPositions() {
    String cid = "CID_abc_efg";

    BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);

    int[] bitPos = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos).isNotNull();
    assertThat(bitPos.length).isEqualTo(bloomFilter.getK());

    int[] bitPos2 = bloomFilter.calcBitPositions(cid);

    assertThat(bitPos2).isNotNull();
    assertThat(bitPos2.length).isEqualTo(bloomFilter.getK());

    assertThat(bitPos).isEqualTo(bitPos2);
}