     // Methods
 
     public func generate() -> Generator {
-        return Generator(tree: tree)
+        return Generator(tree.generate())
+    }
+
+    public func _copyToNativeArrayBuffer() -> _ContiguousArrayBuffer<Element> {
+        // The comment in BTree._copyToNativeArrayBuffer explains what this is.
+        return tree._copyToNativeArrayBuffer()
     }
 
     public func indexForKey(key: Key) -> Index? {
-        guard let handle = tree.find(TreeKey(key)) else { return nil }
-        return Index(tree: tree, handle: handle)
+        guard let i = tree.indexOf(key) else { return nil }
+        return Index(i)
     }
 
     // Mutators
 
-    public mutating func reserveCapacity(minimumCapacity: Int) {
-        tree.reserveCapacity(minimumCapacity)
-    }
-
     public mutating func updateValue(value: Value, forKey key: Key) -> Value? {
-        return tree.setPayloadOf(TreeKey(key), to: value).1
+        return tree.set(key, to: value)
     }
 
     public mutating func removeAtIndex(index: Index) -> (Key, Value) {
-        let handle = index.handle!
-        let key = tree.headAt(handle)
-        let value = tree.remove(handle)
-        return (key, value)
+        return tree.removeAt(index)
     }
 
     public mutating func removeValueForKey(key: Key) -> Value? {
-        guard let handle = tree.find(TreeKey(key)) else { return nil }
-        return tree.remove(handle)
+        return tree.remove(key)
     }
 
     public mutating func removeAll() {


public struct Map<Key: Comparable, Value>: SortedAssociativeCollectionType {
    // Typealiases

    internal typealias Summary = EmptySummary<Key>
    internal typealias TreeKey = StoredKey<Summary>
    internal typealias Tree = RedBlackTree<TreeKey, Value>
    internal typealias Handle = Tree.Handle

    public typealias Index = MapIndex<Key, Value>
    public typealias Generator = MapGenerator<Key, Value>
    public typealias Element = (Key, Value)


    }
}

public struct MapGenerator<Key: Comparable, Value>: GeneratorType {
    public typealias Element = (Key, Value)

    private var generator: BTreeGenerator<Key, Value>

    private init(_ generator: BTreeGenerator<Key, Value>) {
        self.generator = generator
    }

    public mutating func next() -> Element? {
        return generator.next()
    }
}

