Skip to content

Instantly share code, notes, and snippets.

@biboudis
Created February 28, 2012 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biboudis/1931336 to your computer and use it in GitHub Desktop.
Save biboudis/1931336 to your computer and use it in GitHub Desktop.
A quick bloom filter in Rx
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