如何在GraphX中映射compactBuffer

时间:2022-04-28 20:52:43

I have a compactBuffer like this :

我有这样一个压缩缓冲区:

CompactBuffer(((8,1.2),((1,1.3),1)), ((8,1.2),((4,1.1),1)), ((8,1.2),((7,2.1),1)), ((8,1.2),((8,1.2),1)), ((8,1.2),((10,1.1),1)))
CompactBuffer(((12,7.2),((3,5.2),1)), ((12,7.2),((12,7.2),1)))
CompactBuffer(((5,3.1),((2,2.7),1)), ((5,3.1),((5,3.1),1)), ((5,3.1),((6,3.2),1)), ((5,3.1),((9,2.2),1)), ((5,3.1),((11,2.8),1)), ((5,3.1),((13,5.1),1)))

How can I map that compactBuffer and pass a function (that I code it) into that map ? Thanks in advance !

如何映射compactBuffer并将一个函数(我编码它)传递到该映射中?提前谢谢!

2 个解决方案

#1


2  

CompactBuffer is an optimized mutable collection for holding few items. It implements the Seq[T] trait, so all your well-known Seq operations can be applied to CompactBuffer.

CompactBuffer是一个优化的可变集合,用于保存少量项。它实现了Seq[T]特性,因此所有著名的Seq操作都可以应用到CompactBuffer。

So, to transform the contents of the CompactBuffer, a map operation should do the trick:

因此,要转换CompactBuffer的内容,映射操作应该具有以下功能:

val v = CompactBuffer(((12,7.2),((3,5.2),1)), ((12,7.2),((12,7.2),1)))
val transf = v.map(tuple => ... )

All other collection operations will also work: flatMap, filter, take, drop, ...

所有其他的收集操作也将工作:平面映射、筛选、获取、删除……

#2


0  

If you mean without knowledge of the CompactBuffer class, how about this:

如果你的意思是不了解CompactBuffer类,那这个呢?

compactBuffer match {
  case CompactBuffer(data) => yourFunction(data)
}

#1


2  

CompactBuffer is an optimized mutable collection for holding few items. It implements the Seq[T] trait, so all your well-known Seq operations can be applied to CompactBuffer.

CompactBuffer是一个优化的可变集合,用于保存少量项。它实现了Seq[T]特性,因此所有著名的Seq操作都可以应用到CompactBuffer。

So, to transform the contents of the CompactBuffer, a map operation should do the trick:

因此,要转换CompactBuffer的内容,映射操作应该具有以下功能:

val v = CompactBuffer(((12,7.2),((3,5.2),1)), ((12,7.2),((12,7.2),1)))
val transf = v.map(tuple => ... )

All other collection operations will also work: flatMap, filter, take, drop, ...

所有其他的收集操作也将工作:平面映射、筛选、获取、删除……

#2


0  

If you mean without knowledge of the CompactBuffer class, how about this:

如果你的意思是不了解CompactBuffer类,那这个呢?

compactBuffer match {
  case CompactBuffer(data) => yourFunction(data)
}