Exemple #1
0
        /// <summary>
        /// Determine whether some input is possibly contained within the filter.
        /// </summary>
        /// <param name="test">The byte array to test.</param>
        /// <returns>Whether this data could be contained within the filter.</returns>
        public bool Test(byte[] test)
        {
            var compare = new Bloom();

            compare.Add(test);
            return(this.Test(compare));
        }
Exemple #2
0
 /// <summary>
 /// Given this and another bloom, bitwise-OR all the data to get a bloom filter representing a range of data.
 /// </summary>
 public void Or(Bloom bloom)
 {
     for (int i = 0; i < this.data.Length; ++i)
     {
         this.data[i] |= bloom.data[i];
     }
 }
Exemple #3
0
        /// <summary>
        /// Determine whether a second bloom is possibly contained within the filter.
        /// </summary>
        /// <param name="bloom">The second bloom to test.</param>
        /// <returns>Whether this data could be contained within the filter.</returns>
        public bool Test(Bloom bloom)
        {
            var copy = new Bloom(bloom.ToBytes());

            copy.Or(this);
            return(this.Equals(copy));
        }
        /// <summary>
        /// Tests if the address AND all of the topics are matched by the filter.
        /// </summary>
        /// <param name="bloom">The filter to match.</param>
        /// <param name="addresses">The addresses to match against the filter.</param>
        /// <param name="topics">The topics to match against the filter.</param>
        /// <returns>True if all of the filter parameters match.</returns>
        public static bool Test(this Bloom bloom, IEnumerable <uint160> addresses, IEnumerable <byte[]> topics)
        {
            var filterBloom = new Bloom();

            if (addresses != null)
            {
                foreach (uint160 address in addresses)
                {
                    if (address != null)
                    {
                        filterBloom.Add(address.ToBytes());
                    }
                }
            }

            if (topics != null)
            {
                foreach (byte[] topic in topics)
                {
                    if (topic != null)
                    {
                        filterBloom.Add(topic);
                    }
                }
            }

            return(bloom.Test(filterBloom));
        }
Exemple #5
0
        public bool Equals(Bloom obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                return(false);
            }

            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            return(obj == this);
        }
 public static bool Test(this Bloom bloom, IEnumerable <uint160> addresses) => Test(bloom, addresses, null);
 public static bool Test(this Bloom bloom, uint160 address) => Test(bloom, new [] { address }, null);
 public static bool Test(this Bloom bloom, uint160 address, IEnumerable <byte[]> topics) => Test(bloom, new[] { address }, topics);
 public static bool Test(this Bloom bloom, IEnumerable <byte[]> topics) => Test(bloom, (IEnumerable <uint160>)null, topics);