Github user ankurdave commented on a diff in the pull request:

    https://github.com/apache/spark/pull/497#discussion_r12456652
  
    --- Diff: 
graphx/src/main/scala/org/apache/spark/graphx/impl/RoutingTablePartition.scala 
---
    @@ -0,0 +1,158 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.graphx.impl
    +
    +import scala.reflect.ClassTag
    +
    +import org.apache.spark.Partitioner
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.rdd.ShuffledRDD
    +import org.apache.spark.util.collection.{BitSet, PrimitiveVector}
    +
    +import org.apache.spark.graphx._
    +import org.apache.spark.graphx.util.collection.PrimitiveKeyOpenHashMap
    +
    +/**
    + * A message from the edge partition `pid` to the vertex partition 
containing `vid` specifying that
    + * the edge partition references `vid` in the specified `position` (src, 
dst, or both).
    +*/
    +private[graphx]
    +class RoutingTableMessage(
    +    var vid: VertexId,
    +    var pid: PartitionID,
    +    var position: Byte)
    +  extends Product2[VertexId, (PartitionID, Byte)] with Serializable {
    +  override def _1 = vid
    +  override def _2 = (pid, position)
    +  override def canEqual(that: Any): Boolean = 
that.isInstanceOf[RoutingTableMessage]
    +}
    +
    +private[graphx]
    +class RoutingTableMessageRDDFunctions(self: RDD[RoutingTableMessage]) {
    +  /** Copartition an `RDD[RoutingTableMessage]` with the vertex RDD with 
the given `partitioner`. */
    +  def copartitionWithVertices(partitioner: Partitioner): 
RDD[RoutingTableMessage] = {
    +    new ShuffledRDD[VertexId, (PartitionID, Byte), 
RoutingTableMessage](self, partitioner)
    +      .setSerializer(new RoutingTableMessageSerializer)
    +  }
    +}
    +
    +private[graphx]
    +object RoutingTableMessageRDDFunctions {
    +  import scala.language.implicitConversions
    +
    +  implicit def rdd2RoutingTableMessageRDDFunctions(rdd: 
RDD[RoutingTableMessage]) = {
    +    new RoutingTableMessageRDDFunctions(rdd)
    +  }
    +}
    +
    +private[graphx]
    +object RoutingTablePartition {
    +  val empty: RoutingTablePartition = new RoutingTablePartition(Array.empty)
    +
    +  /** Generate a `RoutingTableMessage` for each vertex referenced in 
`edgePartition`. */
    +  def edgePartitionToMsgs(pid: PartitionID, edgePartition: 
EdgePartition[_, _])
    +    : Iterator[RoutingTableMessage] = {
    +    // Determine which positions each vertex id appears in using a map 
where the low 2 bits
    +    // represent src and dst
    +    val map = new PrimitiveKeyOpenHashMap[VertexId, Byte]
    +    edgePartition.srcIds.iterator.foreach { srcId =>
    +      map.changeValue(srcId, 0x1, (b: Byte) => (b | 0x1).toByte)
    +    }
    +    edgePartition.dstIds.iterator.foreach { dstId =>
    +      map.changeValue(dstId, 0x2, (b: Byte) => (b | 0x2).toByte)
    +    }
    +    map.iterator.map { vidAndPosition =>
    +      new RoutingTableMessage(vidAndPosition._1, pid, vidAndPosition._2)
    +    }
    +  }
    +
    +  /** Build a `RoutingTablePartition` from `RoutingTableMessage`s. */
    +  def fromMsgs(numEdgePartitions: Int, iter: Iterator[RoutingTableMessage])
    +    : RoutingTablePartition = {
    +    val pid2vid = Array.fill(numEdgePartitions)(new 
PrimitiveVector[VertexId])
    +    val srcFlags = Array.fill(numEdgePartitions)(new 
PrimitiveVector[Boolean])
    --- End diff --
    
    Use Scala BitSet, which is auto-resizing, avoiding the copy


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to