本文整理汇总了Scala中org.apache.spark.util.collection.BitSet类的典型用法代码示例。如果您正苦于以下问题:Scala BitSet类的具体用法?Scala BitSet怎么用?Scala BitSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitSet类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MyShippableVertexPartition
//设置package包名称以及导入依赖的类
package org.apache.spark.graphx
import org.apache.spark.graphx.impl.VertexIdToIndexMap
import org.apache.spark.graphx.util.collection.GraphXPrimitiveKeyOpenHashMap
import org.apache.spark.internal.Logging
import org.apache.spark.util.collection.BitSet
import scala.reflect.ClassTag
class MyShippableVertexPartition[VD]( val index: GraphXPrimitiveKeyOpenHashMap[VertexId, Int],
val local2global: Array[VertexId],
val values: Array[VD],
val mask: BitSet) extends Serializable with Logging{
// val capacity: Int = index.size
def size: Int = mask.capacity
def iterator: Iterator[(VertexId, VD)] =
mask.iterator.map(ind => (local2global(ind), values(ind)))
//
def aggregateUsingIndex[VD2: ClassTag](
iter: Iterator[Product2[VertexId, VD2]],
reduceFunc: (VD2, VD2) => VD2): MyShippableVertexPartition[VD2] = {
val newMask = new BitSet(size)
val newValues = new Array[VD2](size)
iter.foreach { product =>
val vid = product._1
val vdata = product._2
val pos = index.getOrElse(vid,-1)
if (pos >= 0) {
if (newMask.get(pos)) {
newValues(pos) = reduceFunc(newValues(pos), vdata)
} else { // otherwise just store the new value
newMask.set(pos)
newValues(pos) = vdata
}
// println("debug")
}
}
new MyShippableVertexPartition(index, local2global, newValues, newMask)
}
}