alexandrnikitin / bloom-filter-scala

Bloom filter for Scala, the fastest for JVM
https://alexandrnikitin.github.io/blog/bloom-filter-for-scala/
MIT License
376 stars 57 forks source link

Add Serialization support #14

Closed alexandrnikitin closed 8 years ago

alexandrnikitin commented 8 years ago

How to serialize/deserialize:

val bf = BloomFilter[Long](size, 0.01)

val file = File.createTempFile("bloomFilterSerialized", ".tmp")
val out = new BufferedOutputStream(new FileOutputStream(file), 10 * 1000 * 1000)
bf.writeTo(out)
out.close()

val in = new BufferedInputStream(new FileInputStream(file), 10 * 1000 * 1000)
val newbf = BloomFilter.readFrom[Long](in)
in.close()

file.delete()
bf.dispose()
newbf.dispose()