Exemple #1
0
 public static FilterLoadPayload Create(BloomFilter filter)
 {
     byte[] buffer = new byte[filter.M / 8];
     filter.GetBits(buffer);
     return(new FilterLoadPayload
     {
         Filter = buffer,
         K = (byte)filter.K,
         Tweak = filter.Tweak
     });
 }
        public void TestGetBits()
        {
            int  m = 7, n = 10;
            uint nTweak = 123456;

            byte[]      elements = { 0, 1, 2, 3, 4 };
            BloomFilter filter   = new BloomFilter(m, n, nTweak);

            byte[] result = new byte[m];
            filter.GetBits(result);
            foreach (byte value in result)
            {
                value.Should().Be(0);
            }
        }
Exemple #3
0
        public void Add()
        {
            // Arrange
            var bloomfilter = new BloomFilter(256, 2, 1);

            byte[] element = { 0x01, 0x01, 0x01, 0x01 };
            var    result  = new byte[32];

            // Act
            bloomfilter.Add(element);
            bloomfilter.GetBits(result);
            var K = bloomfilter.K;
            var M = bloomfilter.M;

            // Assert
            Assert.AreEqual(0x08, result[8]);
            Assert.AreEqual(2, K);
            Assert.AreEqual(256, M);
        }
Exemple #4
0
        public void GetBits()
        {
            // Arrange
            var bloomfilter = new BloomFilter(32, 3, 2);

            byte[] element1 = { 0x01, 0x02, 0x03, 0x04 };
            byte[] element2 = { 0xDE, 0xAD, 0xBE, 0xEF };
            byte[] element3 = { 0x22, 0x22, 0x22, 0x22 };
            byte[] expect   = { 0x0a, 0x04, 0x44, 0xca };
            var    result   = new byte[4];

            // Act
            bloomfilter.Add(element1);
            bloomfilter.Add(element2);
            bloomfilter.Add(element3);
            bloomfilter.GetBits(result);

            // Assert
            Assert.AreEqual(result.ToHexString(false), "0a0444ca");
        }