Skip to content
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

Mutable BitSet does not provide efficient logical operations #5513

Closed
scabug opened this issue Feb 22, 2012 · 9 comments
Closed

Mutable BitSet does not provide efficient logical operations #5513

scabug opened this issue Feb 22, 2012 · 9 comments

Comments

@scabug
Copy link

scabug commented Feb 22, 2012

The mutable BitSet does not expose mutating efficient logical operations like or, and, xor, and so on taking another BitSet.

I think those methods are an essential part of using mutable BitSets.

@scabug
Copy link
Author

scabug commented Feb 22, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5513?orig=1
Reporter: ziggystar
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented Feb 29, 2012

Christopher Sahnwaldt (jcsahnwaldt) said:
I agree. Please have a good look at java.util.BitSet and add methods like set(from: Int, to: Int) and so on, which are necessary for efficient 'batch' operations. Thanks!

@scabug
Copy link
Author

scabug commented Mar 27, 2012

@adriaanm said:
We're happy to take pull requests for this! Unfortunately we do not have the resources to do this ourselves.

@scabug
Copy link
Author

scabug commented Mar 27, 2012

Igor Petruk (igor-petruk) said:
I've looked at BitSetLike. I does copying of all bits, plus it does so two times on each operation. I can play with trying to implement it with Vector instead of Array and see what loss/win we have

@scabug
Copy link
Author

scabug commented Mar 20, 2013

@JamesIry said:
scala/scala#2235

@scabug
Copy link
Author

scabug commented Dec 8, 2013

Denis Petrov (denis) said (edited on Dec 8, 2013 8:20:42 PM UTC):
In the current implementation mutable BitSet is required on the right hand side of those logical operations.
In code like set1 |= set2 both sets have to be mutable, although set2 does not have to be mutable to perform the operation.

@plokhotnyuk
Copy link

plokhotnyuk commented Jul 29, 2019

It works as expected in Scala 2.13.0 and implemented more less efficiently by direct accessing to underlying arrays of bit words:

$ scala
Welcome to Scala 2.13.0 (OpenJDK 64-Bit GraalVM CE 19.1.1, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.

scala> import scala.collection.mutable
import scala.collection.mutable

scala> import scala.collection.immutable
import scala.collection.immutable

scala> val m = mutable.BitSet(1, 2, 3, 7)
m: scala.collection.mutable.BitSet = BitSet(1, 2, 3, 7)

scala> val i = immutable.BitSet(2, 3, 6)
i: scala.collection.immutable.BitSet = BitSet(2, 3, 6)

scala> m |= i
res0: m.type = BitSet(1, 2, 3, 6, 7)

scala> m ^= i
res1: m.type = BitSet(1, 7)

scala> m &= i
res2: m.type = BitSet()

It affects only Scala 2.12 or less:

$ /opt/scala-2.12.8/bin/scala
Welcome to Scala 2.12.8 (OpenJDK 64-Bit GraalVM CE 19.1.1, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.

scala> import scala.collection.mutable
import scala.collection.mutable

scala> import scala.collection.immutable
import scala.collection.immutable

scala> val m = mutable.BitSet(1, 2, 3, 7)
m: scala.collection.mutable.BitSet = BitSet(1, 2, 3, 7)

scala> val i = immutable.BitSet(2, 3, 6)
i: scala.collection.immutable.BitSet = BitSet(2, 3, 6)

scala> m |= i
<console>:16: error: type mismatch;
 found   : BitSet (in scala.collection.immutable)
 required: BitSet (in scala.collection.mutable)
       m |= i
            ^

Shouldn't the issue be closed as fixed?

@SethTisue SethTisue added this to the 2.13.0 milestone Jul 29, 2019
@SethTisue
Copy link
Member

@joshlemer agree?

@joshlemer
Copy link
Member

@SethTisue agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants