When trying to compile, I get the following error:
Btree.scala: 9: error: could not find an implicit value for ordering parameters: Order [K] abstract class Node [K, V] extends TreeMap [K, V]
TreeMap should accept the implicit Ordering [A] val that I provide. Perhaps the implicit parameter should be in the test object where the Btree (TreeMap) instance is being created? I would prefer to keep the implicit declaration inside the Btree class, because I would like Ordering to be of type K, which implements Comparable [K]. Make sense?
package disttree {
import scala.collection.immutable.TreeMap
class Btree[K <: Comparable[K],V](fanout:Int) {
implicit object DefaultOrder extends Ordering[K] {
def compare(k1: K, k2: K) = k1 compareTo k2
}
abstract class Node[K,V] extends TreeMap[K,V]
class InnerNode[K,V] extends Node[K,V]
class LeafNode[K,V] extends Node[K,V]
val root = new InnerNode[K,V]()
def search(n: Node[K,V], key: K): Option[(K,V)] = {
return n.find(_ == key)
}
def insert(key: K, value: V) { }
def delete(key: K) { }
}
}
import disttree._;
object Tester {
def main(args: List[String]) = {
var t = new Btree[Int, Any](2)
t.insert(1, "goodbye")
Console.println(t)
}
}
source
share