Skip to content

Instantly share code, notes, and snippets.

@MrJaba
Created November 25, 2009 10:33
Show Gist options
  • Save MrJaba/242623 to your computer and use it in GitHub Desktop.
Save MrJaba/242623 to your computer and use it in GitHub Desktop.
import scala.io.Source;
import scala.collection.mutable;
class Bloom( file : String ){
private val words = mutable.Map.empty[Int, Int];
def initialize() : Unit = {
populateBitmap();
}
def populateBitmap() : Unit = {
for( line <- Source.fromFile(file).getLines )
words(line.trim().toLowerCase().hashCode()) = 1;
}
def testWord(word:String) : Boolean = {
return words.contains(word.toLowerCase().hashCode());
}
}
val b = new Bloom("/usr/share/dict/words");
b.initialize();
println( b.testWord("hello") );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment