scala bitset_Scala中的BitSet
scala bitset
Scala BitSet (Scala BitSet)
Set is a collection of unique elements.
集合是唯一元素的集合。
Bitset is a set of positive integers represented as a 64-bit word.
位集是一組表示為64位字的正整數(shù)。
Syntax:
句法:
var bitset : Bitset = Bitset(elements...)In the Scala programming language, BitSet can be mutable as well as immutable.
在Scala編程語(yǔ)言中, BitSet可以是可變的而且是不變的。
In mutable BitSet, bits can be changed in the program. Using scala.collection.mutable.BitSet
在可變的BitSet中 ,可以在程序中更改位。 使用scala.collection.mutable.BitSet
In immutable BitSet, bits cannot be changed in the program. Using scala.collection.immutable.BitSet
在不可變的BitSet中 ,不能在程序中更改位。 使用scala.collection.immutable.BitSet
Example 1: Creation of a new BitSet
示例1:創(chuàng)建一個(gè)新的BitSet
import scala.collection.immutable.BitSetobject MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet(0, 1, 2, 3) println("Elements of new BitSet are " + bitSet) } }Output
輸出量
Elements of new BitSet are BitSet(0, 1, 2, 3)Example 2: Search for an element in BitSet
示例2:在BitSet中搜索元素
Search operation on BitSet in Scala is quite easy and passing the elements to be searched in BitSet, and it will return true or false based on the search.
在Scala中對(duì)BitSet進(jìn)行搜索操作非常容易,并且可以在BitSet中傳遞要搜索的元素,并且根據(jù)搜索結(jié)果將返回true或false。
import scala.collection.immutable.BitSetobject MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet(0, 13, 25, 39, 50) println("Elements of new BitSet are " + bitSet) println("Element 25 is in the BitSet? " + bitSet(25))println("Element 34 is in the BitSet? " + bitSet(34))} }Output
輸出量
Elements of new BitSet are BitSet(0, 13, 25, 39, 50) Element 25 is in the BitSet? true Element 34 is in the BitSet? falseExample 3: Adding elements to the BitSet
示例3:將元素添加到BitSet
You can add one or multiple elements in a BitSet in Scala. The operators + and ++ are used to add single and multiple elements in BitSet in Scala. The operation will require new BitSet to hold the updated BitSet.
您可以在Scala的BitSet中添加一個(gè)或多個(gè)元素。 運(yùn)算符+和++用于在Scala的BitSet中添加單個(gè)和多個(gè)元素。 該操作將需要新的BitSet來(lái)保存更新的BitSet。
import scala.collection.immutable.BitSetobject MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet(0, 13, 25, 39, 50) println("Elements of new BitSet are " + bitSet) println("Adding new elements to BitSet : ")val bitSet2 : BitSet = bitSet + 45 println("Elements of new BitSet are " + bitSet2) println("Adding new elements to BitSet : ")val bitSet3 : BitSet = bitSet2 ++ BitSet(34 , 54)println("Elements of new BitSet are " + bitSet3) } }Output
輸出量
Elements of new BitSet are BitSet(0, 13, 25, 39, 50) Adding new elements to BitSet : Elements of new BitSet are BitSet(0, 13, 25, 39, 45, 50) Adding new elements to BitSet : Elements of new BitSet are BitSet(0, 13, 25, 34, 39, 45, 50, 54)Example 4: Deleting Elements from BitSet in Scala
示例4:從Scala的BitSet中刪除元素
You can delete elements from BitSet in Scala. The operator - is used to delete an element from BitSet. The operations will require new BitSet to hold the updated BitSet.
您可以從Scala的BitSet中刪除元素。 運(yùn)算符-用于從BitSet中刪除元素。 該操作將需要新的BitSet來(lái)保存更新的BitSet。
import scala.collection.immutable.BitSetobject MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet(0, 13, 25, 39, 50) println("Elements of new BitSet are " + bitSet) println("Deleting element from BitSet : ")val bitSet2 : BitSet = bitSet - 25 println("Elements of new BitSet are " + bitSet2)} }Output
輸出量
Elements of new BitSet are BitSet(0, 13, 25, 39, 50) Deleting element from BitSet : Elements of new BitSet are BitSet(0, 13, 39, 50)Example 5: Creating Empty BitSet in Scala
示例5:在Scala中創(chuàng)建空的BitSet
An empty set can also be created in Scala. The empty keyword is used to create an empty BitSet in Scala.
也可以在Scala中創(chuàng)建一個(gè)空集。 empty關(guān)鍵字用于在Scala中創(chuàng)建一個(gè)空的BitSet。
import scala.collection.immutable.BitSetobject MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet.emptyprintln("Elements of new BitSet are " + bitSet) } }Output
輸出量
Elements of new BitSet are BitSet()翻譯自: https://www.includehelp.com/scala/bitset.aspx
scala bitset
總結(jié)
以上是生活随笔為你收集整理的scala bitset_Scala中的BitSet的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java 数字字母进位_使用带有进位的8
- 下一篇: 大数据数据可视化设计原则_数据可视化设计