     }
 }
 
+
+//MARK: Color management
+
+extension RedBlackTree {
+    /// Only non-nil nodes may be red.
+    private func isRed(handle: Handle?) -> Bool {
+        guard let handle = handle else { return false }
+        return self[handle].color == .Red
+    }
+    /// Nil nodes are considered black.
+    private func isBlack(handle: Handle?) -> Bool {
+        guard let handle = handle else { return true }
+        return self[handle].color == .Black
+    }
+    /// Only non-nil nodes may be set red.
+    private mutating func setRed(handle: Handle) {
+        self[handle].color = .Red
+    }
+    /// You can set a nil node black, but it's a noop.
+    private mutating func setBlack(handle: Handle?) {
+        guard let handle = handle else { return }
+        self[handle].color = .Black
+    }
+}
+
 //MARK: Rotation
 
 extension RedBlackTree {


        rebalanceAfterInsertion(handle)
        return handle
    }
}


        }
    }
}
