1,258
社区成员
发帖
与我相关
我的任务
分享
package test
trait PartitionStrategy extends Serializable {
/** Returns the partition number for a given edge. */
def getPartition(key: Int): Int
}
case object MetisPartition extends PartitionStrategy {
val metisMap =new scala.collection.mutable.HashMap[Int,Int]
def this(xc:Int) {
this(xc,0) //这里为什么编译报错?
println("Constructor! ")
mockLoadFile()
}
def mockLoadFile() {
try {
var id = 1 ;
while(id < 10000)
{
var partition = 5 ;
metisMap.put(id, partition)
id = id +1
}
println("size: " + metisMap.size)
} catch {
case ex: Exception => { // Handle missing file
ex.printStackTrace()
}
}
}
override def getPartition(src: Int): Int = {
var s = metisMap.get(src.hashCode())
if(!s.isEmpty)
return s.getOrElse(0)
else
throw new IllegalArgumentException("Metis can't find partition!")
}
def main(args :Array[String]){
try {
val partitionStrategy = new PartitionStrategy ////这里应该如何定义? 编译不过去
println(partitionStrategy.getPartition(110))
} catch {
case ex: Exception => {
ex.printStackTrace()
}
}
}
}
class MetisPartition(x1:Int,x2:Int) extends PartitionStrategy {
val metisMap =new scala.collection.mutable.HashMap[Int,Int]
def this(x1:Int) {
this(x1,0) //这里为什么编译报错?
println("Constructor! ")
mockLoadFile()
}
def mockLoadFile() {
try {
var id = 1 ;
while(id < 10000)
{
var partition = 5 ;
metisMap.put(id, partition)
id = id +1
}
println("size: " + metisMap.size)
} catch {
case ex: Exception => { // Handle missing file
ex.printStackTrace()
}
}
}
override def getPartition(src: Int): Int = {
var s = metisMap.get(src.hashCode())
if(!s.isEmpty)
return s.getOrElse(0)
else
throw new IllegalArgumentException("Metis can't find partition!")
}
def main(args :Array[String]){
try {
val partitionStrategy = new MetisPartition(1) ////这里应该如何定义? 编译不过去
println(partitionStrategy.getPartition(110))
} catch {
case ex: Exception => {
ex.printStackTrace()
}
}
}
}