collection.mutable.ArrayBuffer Scala Examples
The following examples show how to use collection.mutable.ArrayBuffer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: SplitInfo.scala From drizzle-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's don't seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 2
Source File: CompanionSorter.scala From mango with Apache License 2.0 | 5 votes |
package com.kakao.shaded.jackson.module.scala.util import collection.mutable.{ArrayBuffer, ListBuffer} import collection.GenTraversable import collection.generic.GenericCompanion import scala.reflect.ClassTag import scala.language.higherKinds class CompanionSorter[CC[X] <: GenTraversable[X]] { type HKClassManifest[CC2[_]] = ClassTag[CC2[_]] private[this] val companions = new ArrayBuffer[(Class[_], GenericCompanion[CC])]() def add[T[X] <: CC[X] : HKClassManifest](companion: GenericCompanion[T]): CompanionSorter[CC] = { companions += implicitly[HKClassManifest[T]].runtimeClass -> companion this } def toList: List[(Class[_], GenericCompanion[CC])] = { val cs = companions.toArray val output = new ListBuffer[(Class[_], GenericCompanion[CC])]() val remaining = cs.map(_ => 1) val adjMatrix = Array.ofDim[Int](cs.length, cs.length) // Build the adjacency matrix. Only mark the in-edges. for (i <- 0 until cs.length; j <- 0 until cs.length) { val (ic, _) = cs(i) val (jc, _) = cs(j) if (i != j && ic.isAssignableFrom(jc)) { adjMatrix(i)(j) = 1 } } // While we haven't removed every node, remove all nodes with 0 degree in-edges. while (output.length < cs.length) { val startLength = output.length for (i <- 0 until cs.length) { if (remaining(i) == 1 && dotProduct(adjMatrix(i), remaining) == 0) { output += companions(i) remaining(i) = 0 } } // If we couldn't remove any nodes, it means we've found a cycle. Realistically this should never happen. if (output.length == startLength) { throw new IllegalStateException("Companions contain a cycle.") } } output.toList } private[this] def dotProduct(a: Array[Int], b: Array[Int]): Int = { if (a.length != b.length) throw new IllegalArgumentException() (0 until a.length).map(i => a(i) * b(i)).sum } }
Example 3
Source File: SplitInfo.scala From sparkoscope with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's don't seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 4
Source File: exercise10.scala From scala-for-the-Impatient with MIT License | 5 votes |
import collection.mutable.ArrayBuffer import java.io.{ObjectInputStream, FileOutputStream, FileInputStream, ObjectOutputStream} class Person(var name:String) extends Serializable{ val friends = new ArrayBuffer[Person]() def addFriend(friend : Person){ friends += friend } override def toString() = { var str = "My name is " + name + " and my friends name is " friends.foreach(str += _.name + ",") str } } object Test extends App{ val p1 = new Person("Ivan") val p2 = new Person("F2") val p3 = new Person("F3") p1.addFriend(p2) p1.addFriend(p3) println(p1) val out = new ObjectOutputStream(new FileOutputStream("person.obj")) out.writeObject(p1) out.close() val in = new ObjectInputStream(new FileInputStream("person.obj")) val p = in.readObject().asInstanceOf[Person] println(p) }
Example 5
Source File: exercise06.scala From scala-for-the-Impatient with MIT License | 5 votes |
import collection.mutable.ArrayBuffer class ASCIIArt(str:String){ val arr:ArrayBuffer[ArrayBuffer[String]] = new ArrayBuffer[ArrayBuffer[String]]() if (str != null && !str.trim.eq("")){ str.split("[\r\n]+").foreach{ line => val s = new ArrayBuffer[String]() s += line arr += s } } def this(){ this("") } def +(other:ASCIIArt):ASCIIArt={ val art = new ASCIIArt() val length = if (this.arr.length >= other.arr.length) this.arr.length else other.arr.length for(i <- 0 until length){ val s = new ArrayBuffer[String]() val thisArr:ArrayBuffer[String] = if (i < this.arr.length) this.arr(i) else new ArrayBuffer[String]() val otherArr:ArrayBuffer[String] = if (i < other.arr.length) other.arr(i) else new ArrayBuffer[String]() thisArr.foreach(s += _) otherArr.foreach(s += _) art.arr += s } art } def *(other:ASCIIArt):ASCIIArt={ val art = new ASCIIArt() this.arr.foreach(art.arr += _) other.arr.foreach(art.arr += _) art } override def toString()={ var ss:String = "" arr.foreach{ ss += _.mkString(" ") + "\n" } ss } } object Test extends App{ val a = new ASCIIArt(""" /\_/\ |( ' ' ) |( - ) | | | | |(__|__) |""".stripMargin) val b = new ASCIIArt( """ ----- | / Hello \ | < Scala | | \ Coder / | ----- |""".stripMargin) println(a + b * b) println((a + b) * b) println(a * b) }
Example 6
Source File: SplitInfo.scala From SparkCore with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's dont seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => { this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit } case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 7
Source File: LabelSRAMModels.scala From midas with BSD 3-Clause "New" or "Revised" License | 5 votes |
// See LICENSE for license details. package midas.passes.fame import firrtl._ import Mappers._ import ir._ import annotations._ import collection.mutable.ArrayBuffer import midas.targetutils.FirrtlMemModelAnnotation class LabelSRAMModels extends Transform { def inputForm = HighForm def outputForm = HighForm val confwriter = new passes.memlib.ConfWriter("NONE") val memutil = new passes.memlib.ReplaceMemMacros(confwriter) def mem2Module(mem: DefMemory): Module = { val ports = passes.MemPortUtils.memType(mem).fields.map(f => Port(NoInfo, f.name, Input, f.tpe)) val connects = ports.map(p => Connect(NoInfo, WSubField(WRef(mem.name), p.name), WRef(p.name))) Module(mem.info, mem.name, ports, Block(mem +: connects)) } override def execute(state: CircuitState): CircuitState = { val circ = state.circuit val moduleNS = Namespace(circ) val memModelAnnotations = new ArrayBuffer[Annotation] val memModules = new ArrayBuffer[Module] val annotatedMems = state.annotations.collect({ case FirrtlMemModelAnnotation(rt) => rt }).toSet println(s"[MIDAS 2.0] RAM Models To Extract: ${annotatedMems.size}") val transformedModules = circ.modules.map({ case m: Module => val mt = ModuleTarget(circ.main, m.name) def onStmt(stmt: Statement): Statement = stmt.map(onStmt) match { case mem: DefMemory if annotatedMems.contains(mt.ref(mem.name)) => val wrapper = mem2Module(mem).copy(name = moduleNS.newName(mem.name)) val wrapperTarget = ModuleTarget(circ.main, wrapper.name) memModules += wrapper memModelAnnotations += FAMEModelAnnotation(mt.instOf(mem.name, wrapper.name)) memModelAnnotations ++= mem.readers.map(rp => ModelReadPort(wrapperTarget.ref(rp))) memModelAnnotations ++= mem.writers.map(rp => ModelWritePort(wrapperTarget.ref(rp))) memModelAnnotations ++= mem.readwriters.map(rp => ModelReadWritePort(wrapperTarget.ref(rp))) WDefInstance(mem.info, mem.name, wrapper.name, UnknownType) case s => s } m.copy(body = m.body.map(onStmt)) case m => m }) val transformedCircuit = circ.copy(modules = memModules ++ transformedModules) state.copy(circuit = transformedCircuit, annotations = state.annotations ++ memModelAnnotations) } }
Example 8
Source File: FAMEDefaults.scala From midas with BSD 3-Clause "New" or "Revised" License | 5 votes |
// See LICENSE for license details. package midas.passes.fame import firrtl._ import Mappers._ import ir._ import annotations._ import collection.mutable.{ArrayBuffer, LinkedHashSet} // Assumes: AQB form // Run after ExtractModel // Label all unbound top-level ports as wire channels // Label *all* model-to-model connections as wire channels // Label all children of the top model to be FAME1 transformed class FAMEDefaults extends Transform { def inputForm = LowForm def outputForm = LowForm override def execute(state: CircuitState): CircuitState = { val analysis = new FAMEChannelAnalysis(state, FAME1Transform) val topModule = state.circuit.modules.find(_.name == state.circuit.main).get.asInstanceOf[Module] val globalSignals = state.annotations.collect({ case g: FAMEGlobalSignal => g.target.ref }).toSet val channelNames = state.annotations.collect({ case fca: FAMEChannelConnectionAnnotation => fca.globalName }) val channelNS = Namespace(channelNames) def isGlobal(topPort: Port) = globalSignals.contains(topPort.name) def isBound(topPort: Port) = analysis.channelsByPort.contains(analysis.topTarget.ref(topPort.name)) val defaultExtChannelAnnos = topModule.ports.filterNot(isGlobal).filterNot(isBound).flatMap({ case Port(_, _, _, ClockType) => None // FIXME: Reject the clock in RC's debug interface case Port(_, name, Input, _) => Some(FAMEChannelConnectionAnnotation(channelNS.newName(name), WireChannel, None, Some(Seq(analysis.topTarget.ref(name))))) case Port(_, name, Output, _) => Some(FAMEChannelConnectionAnnotation(channelNS.newName(name), WireChannel, Some(Seq(analysis.topTarget.ref(name))), None)) }) val channelModules = new LinkedHashSet[String] // TODO: find modules to absorb into channels, don't label as FAME models val defaultLoopbackAnnos = new ArrayBuffer[FAMEChannelConnectionAnnotation] val defaultModelAnnos = new ArrayBuffer[FAMETransformAnnotation] val topTarget = ModuleTarget(state.circuit.main, topModule.name) def onStmt(stmt: Statement): Statement = stmt.map(onStmt) match { case wi @ WDefInstance(_, iname, mname, _) if (!channelModules.contains(mname)) => defaultModelAnnos += FAMETransformAnnotation(FAME1Transform, topTarget.copy(module = mname)) wi case c @ Connect(_, WSubField(WRef(lhsiname, _, InstanceKind, _), lhspname, _, _), WSubField(WRef(rhsiname, _, InstanceKind, _), rhspname, _, _)) => if (c.loc.tpe != ClockType && c.expr.tpe != ClockType) { defaultLoopbackAnnos += FAMEChannelConnectionAnnotation( channelNS.newName(s"${rhsiname}_${rhspname}__to__${lhsiname}_${lhspname}"), WireChannel, Some(Seq(topTarget.ref(rhsiname).field(rhspname))), Some(Seq(topTarget.ref(lhsiname).field(lhspname)))) } c case s => s } topModule.body.map(onStmt) state.copy(annotations = state.annotations ++ defaultExtChannelAnnos ++ defaultLoopbackAnnos ++ defaultModelAnnos) } }
Example 9
Source File: SplitInfo.scala From multi-tenancy-spark with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's don't seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 10
Source File: SplitInfo.scala From iolap with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's dont seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => { this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit } case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 11
Source File: SplitInfo.scala From Spark-2.3.1 with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's don't seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }
Example 12
Source File: SplitInfo.scala From BigDatalog with Apache License 2.0 | 5 votes |
package org.apache.spark.scheduler import collection.mutable.ArrayBuffer import org.apache.spark.annotation.DeveloperApi // information about a specific split instance : handles both split instances. // So that we do not need to worry about the differences. @DeveloperApi class SplitInfo( val inputFormatClazz: Class[_], val hostLocation: String, val path: String, val length: Long, val underlyingSplit: Any) { override def toString(): String = { "SplitInfo " + super.toString + " .. inputFormatClazz " + inputFormatClazz + ", hostLocation : " + hostLocation + ", path : " + path + ", length : " + length + ", underlyingSplit " + underlyingSplit } override def hashCode(): Int = { var hashCode = inputFormatClazz.hashCode hashCode = hashCode * 31 + hostLocation.hashCode hashCode = hashCode * 31 + path.hashCode // ignore overflow ? It is hashcode anyway ! hashCode = hashCode * 31 + (length & 0x7fffffff).toInt hashCode } // This is practically useless since most of the Split impl's dont seem to implement equals :-( // So unless there is identity equality between underlyingSplits, it will always fail even if it // is pointing to same block. override def equals(other: Any): Boolean = other match { case that: SplitInfo => { this.hostLocation == that.hostLocation && this.inputFormatClazz == that.inputFormatClazz && this.path == that.path && this.length == that.length && // other split specific checks (like start for FileSplit) this.underlyingSplit == that.underlyingSplit } case _ => false } } object SplitInfo { def toSplitInfo(inputFormatClazz: Class[_], path: String, mapredSplit: org.apache.hadoop.mapred.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapredSplit.getLength for (host <- mapredSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapredSplit) } retval } def toSplitInfo(inputFormatClazz: Class[_], path: String, mapreduceSplit: org.apache.hadoop.mapreduce.InputSplit): Seq[SplitInfo] = { val retval = new ArrayBuffer[SplitInfo]() val length = mapreduceSplit.getLength for (host <- mapreduceSplit.getLocations) { retval += new SplitInfo(inputFormatClazz, host, path, length, mapreduceSplit) } retval } }