Created
November 25, 2009 10:33
-
-
Save MrJaba/242623 to your computer and use it in GitHub Desktop.
This file contains 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
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