Skip to content

Mark BFSparse lazy val BFInstance as @transient #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ case class BFSparse(hashes : BFHash, bits : CBitSet, width : Int) extends BF {

lazy val numHashes: Int = hashes.size

lazy val dense : BFInstance = BFInstance(hashes, bits.toBitSet(width), width)
@transient lazy val dense : BFInstance = BFInstance(hashes, bits.toBitSet(width), width)

def ++ (other: BF): BF = {
require(this.width == other.width)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Properties
import org.scalacheck.Gen.choose
import java.io.{ObjectOutputStream, ByteArrayOutputStream}

object BloomFilterLaws extends Properties("BloomFilter") {
import BaseProperties._
Expand Down Expand Up @@ -99,5 +100,24 @@ class BloomFilterTest extends Specification {
}
}
}

"not serialize BFInstance" in {
def serialize(bf: BF) = {
val stream = new ByteArrayOutputStream()
val out = new ObjectOutputStream(stream)
out.writeObject(bf)
out.close()
stream.close()
stream.toByteArray
}

val items = (1 until 10).map { _.toString }
val bf = BloomFilter(10, 0.1, SEED).create(items: _*)
val bytesBeforeSizeCalled = new String(serialize(bf))
bf.size
bf.contains("1").isTrue must be_==(true)
val bytesAfterSizeCalled = new String(serialize(bf))
bytesBeforeSizeCalled mustEqual bytesAfterSizeCalled
}
}
}