Scala BitSet &~(GenSet[]) method with example
Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The &~(GenSet[]) method is utilised compute the difference of this bitset and another bitset by performing a bitwise “and-not”.
Method Definition: def &~(GenSet[])
Return Type: It returns a new bitset consisting of all elements that are not contained in given bitset.
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 41 , 12 , 23 , 43 , 1 , 72 )
val b 2 = Set( 1 , 100 , 55 , 32 , 23 )
val bs 1 = b 1 &~ (b 2 )
println(bs 1 )
}
}
|
Output:
BitSet(12, 41, 43, 72)
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 41 , 12 , 23 , 43 , 1 , 72 )
val bs 1 = b 1 &~ Set( 1 , 100 , 55 , 32 , 23 )
println(bs 1 )
}
}
|
Output:
BitSet(12, 41, 43, 72)
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...