private static BloomExtract GetExtract(byte[] sequence) { int GetIndex(Span <byte> bytes, int index1, int index2) { return(2047 - ((bytes[index1] << 8) + bytes[index2]) % 2048); } var keccakBytes = ValueKeccak.Compute(sequence).BytesAsSpan; var indexes = new BloomExtract(GetIndex(keccakBytes, 0, 1), GetIndex(keccakBytes, 2, 3), GetIndex(keccakBytes, 4, 5)); return(indexes); }
private void Set(byte[] sequence, Bloom masterBloom) { if (ReferenceEquals(this, Empty)) { throw new InvalidOperationException("An attempt was made to update Bloom.Empty constant"); } BloomExtract indexes = GetExtract(sequence); Set(indexes.Index1); Set(indexes.Index2); Set(indexes.Index3); if (masterBloom != null) { masterBloom.Set(indexes.Index1); masterBloom.Set(indexes.Index2); masterBloom.Set(indexes.Index3); } }
public bool Matches(byte[] sequence) { BloomExtract indexes = GetExtract(sequence); return(Matches(ref indexes)); }
public bool Matches(BloomExtract extract) => Matches(ref extract);
public bool Matches(ref BloomExtract extract) => Get(extract.Index1) && Get(extract.Index2) && Get(extract.Index3);
public bool Matches(ref BloomExtract extract) => _bits[extract.Index1] && _bits[extract.Index2] && _bits[extract.Index3];