/// <summary> /// Initializes a new instance of <see cref="FilterLoadPayload"/> with the given parameters. /// </summary> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentOutOfRangeException"/> /// <param name="filter">Filter to use</param> /// <param name="hashCount">Number of hash functions to use</param> /// <param name="tweak">The tweak</param> /// <param name="flags">Bloom filter flags</param> public FilterLoadPayload(byte[] filter, uint hashCount, uint tweak, BloomFlags flags) { Filter = filter; HashFuncCount = hashCount; Tweak = tweak; Flags = flags; }
public BloomFilter CreateBloomFilter(double fp, BloomFlags flags = BloomFlags.UPDATE_ALL) { var toTrack = GetDataToTrack().ToArray(); var scriptCount = _TrackedScripts.Count(s => !s.Value.IsInternal); var filter = new BloomFilter(scriptCount == 0 ? 1 : scriptCount, fp, _Tweak, flags); foreach (var data in toTrack) { filter.Insert(data); } return(filter); }
public BloomFilter(int nElements, double nFPRate, uint nTweakIn, BloomFlags nFlagsIn = BloomFlags.UPDATE_ALL) { // The ideal size for a bloom filter with a given number of elements and false positive rate is: // - nElements * log(fp rate) / ln(2)^2 // We ignore filter parameters which will create a bloom filter larger than the protocol limits vData = new byte[Math.Min((uint)(-1 / LN2SQUARED * nElements * (decimal)Math.Log(nFPRate)), MAX_BLOOM_FILTER_SIZE) / 8]; //vData(min((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8), // The ideal number of hash functions is filter size * ln(2) / number of elements // Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits // See http://en.wikipedia.org/wiki/Bloom_filter for an explanation of these formulas this.nHashFuncs = Math.Min((uint)(vData.Length * 8 / nElements * LN2), MAX_HASH_FUNCS); this.nTweak = nTweakIn; this.nFlags = (byte)nFlagsIn; }
public BloomFilter(uint nElements, double nFPRate, uint nTweakIn, BloomFlags nFlagsIn = BloomFlags.UPDATE_ALL) { // The ideal size for a bloom filter with a given number of elements and false positive rate is: // - nElements * log(fp rate) / ln(2)^2 // We ignore filter parameters which will create a bloom filter larger than the protocol limits vData = new byte[Math.Min((uint)(-1 / LN2SQUARED * nElements * (decimal)Math.Log(nFPRate)), MAX_BLOOM_FILTER_SIZE) / 8]; //vData(min((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8), // The ideal number of hash functions is filter size * ln(2) / number of elements // Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits // See http://en.wikipedia.org/wiki/Bloom_filter for an explanation of these formulas this.nHashFuncs = Math.Min((uint)(vData.Length * 8 / nElements * LN2), MAX_HASH_FUNCS); this.nTweak = nTweakIn; this.nFlags = (byte)nFlagsIn; }
public BloomFilter(int nElements, double nFPRate, BloomFlags nFlagsIn = BloomFlags.UPDATE_ALL) : this(nElements, nFPRate, RandomUtils.GetUInt32(), nFlagsIn) { }
public BloomFilter CreateBloomFilter(double fp, BloomFlags flags = BloomFlags.UPDATE_ALL) { var toTrack = GetDataToTrack().ToArray(); var scriptCount = _TrackedScripts.Count(s => !s.Value.IsInternal); var filter = new BloomFilter(scriptCount, fp, _Tweak, flags); foreach(var data in toTrack) filter.Insert(data); return filter; }