Created
February 28, 2012 08:53
-
-
Save biboudis/1931336 to your computer and use it in GitHub Desktop.
A quick bloom filter in Rx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IObservable<Tuple<TSource, bool>> Bloom<TSource>(this IObservable<TSource> source, int size) | |
{ | |
BitArray bitmap = new BitArray(size); | |
return source.Select<TSource, Tuple<TSource, bool>>(value => | |
{ | |
var hashCode = value.GetHashCode(); | |
var tuple = new Tuple<TSource, bool>(value, bitmap[hashCode] == true); | |
bitmap[hashCode] = true; | |
return tuple; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment