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位字的正整数。

Syntax:

句法:

    var bitset : Bitset = Bitset(elements...)

In the Scala programming language, BitSet can be mutable as well as immutable.

在Scala编程语言中, 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:创建一个新的BitSet

import scala.collection.immutable.BitSet
object 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中对BitSet进行搜索操作非常容易,并且可以在BitSet中传递要搜索的元素,并且根据搜索结果将返回true或false。

import scala.collection.immutable.BitSet
object 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? false

Example 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.

您可以在ScalaBitSet中添加一个或多个元素。 运算符+和++用于在Scala的BitSet中添加单个和多个元素。 该操作将需要新的BitSet来保存更新的BitSet。

import scala.collection.immutable.BitSet
object 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中删除元素。 运算符-用于从BitSet中删除元素。 该操作将需要新的BitSet来保存更新的BitSet。

import scala.collection.immutable.BitSet
object 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中创建空的BitSet

An empty set can also be created in Scala. The empty keyword is used to create an empty BitSet in Scala.

也可以在Scala中创建一个空集。 empty关键字用于在Scala中创建一个空的BitSet。

import scala.collection.immutable.BitSet
object MyClass {def main(args: Array[String]) {val bitSet: BitSet = BitSet.empty
println("Elements of new BitSet are " + bitSet)
}
}

Output

输出量

Elements of new BitSet are BitSet()

翻译自: https://www.includehelp.com/scala/bitset.aspx

scala bitset

scala bitset_Scala中的BitSet相关推荐

  1. scala 函数中嵌套函数_Scala合成函数

    scala 函数中嵌套函数 Scala中的合成功能 (Composition function in Scala) Scala composition function is a way in whi ...

  2. scala方法中的变量_Scala中的变量

    scala方法中的变量 Scala变量 (Scala variables) A variable is named a reference to a memory location. The loca ...

  3. scala集合中添加元素_如何在Scala中获得列表的第一个元素?

    scala集合中添加元素 清单 (List) A list is a linear data structure. It is a collection of elements of the same ...

  4. scala 类中的对象是类_Scala中的类和对象

    scala 类中的对象是类 Scala中的课程 (Classes in Scala) A class is a blueprint for objects. It contains the defin ...

  5. scala集合中添加元素_如何在Scala中将元素添加到列表中?

    scala集合中添加元素 In Scala, lists are immutable data structures in which adding new elements is not allow ...

  6. scala中map添加值_如何在Scala Map中反转键和值

    scala中map添加值 A Map is a data structure that stores data as key: value pair. 映射是一种将数据存储为键:值对的数据结构. Sy ...

  7. scala 函数中嵌套函数_Scala中的嵌套函数 用法和示例

    scala 函数中嵌套函数 Scala中的嵌套函数 (Nested functions in Scala) A nested function is defined as a function whi ...

  8. scala 函数中嵌套函数_如何在Scala中将函数转换为部分函数?

    scala 函数中嵌套函数 First, let's see what is a function and a partial function, and then we will see their ...

  9. scala 函数中嵌套函数_Scala中的VarArgs函数和@varargs批注

    scala 函数中嵌套函数 In this post, we are going to discuss about Functions with Var-Args (Variable Number O ...

最新文章

  1. influxdb tsm文件_利用InfluxDB+Grafana搭建Flink on YARN作业监控大屏
  2. Java:定时启动线程
  3. java中,字符串和集合判断是否为空
  4. Python3--自动化办公
  5. Django model 中的 class Meta 详解
  6. php默认访问的文件,PHP 网站修改默认访问文件的nginx配置
  7. 全国计算机一级msoffice考试内容,2015年全国计算机一级MSOffice考试大纲
  8. bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级【分层图+spfa】
  9. 卷积的定义,知乎上有个很有名的段子:
  10. 鸿蒙 悟空遥控,利用悟空遥控推送软件,成功实现高德地图等三方APP装
  11. OIBH杯第三次普及组模拟赛T1 立体井字棋
  12. Unity 镜子反射特效
  13. draw.io箭头设置虚线
  14. Java网课基础笔记(9)19-07-21
  15. 企业邮箱搭建模式优劣分析
  16. Inspection info: This inspection analyzes method control and data flow to report possible conditions
  17. Oracle中SQL查询字段值为空时,指定默认值
  18. python spss,有没有一个Python模块打开SPSS文件?
  19. 达梦数据库DCA培训笔记(基于dm8)
  20. vs配置ffmpeg

热门文章

  1. yum删除mysql数据库_MySQL数据库之Centos中彻底删除Mysql(rpm、yum安装的情况)
  2. cups支持的打印机列表_Win10“Microsoft Print to PDF”虚拟打印机不见了,如何找回?...
  3. Yapi Mock 远程代码执行漏洞
  4. 实验报告:抽象数据类型的表现和实现
  5. 单片机复位后为什么要对sp重新赋值_51单片机系列之2点亮第一个led小灯
  6. 怎么判断一个字符串的最长回文子串是否在头尾_LeetCode 第 131 号问题:分割回文串...
  7. redis内存淘汰和持久化_redis 持久化
  8. python wheel使用_【转载】Python,使用Wheel打包
  9. Java并发篇_volatile
  10. UVA401 ​​​​​​​Palindromes【字符串】