         }
     }
     
+    /// Merge two sets of keys.
+    ///
+    /// - parameters:
+    ///   - key1: The first key to merge
+    ///   - key2: The second key to merge
+    ///   - combine: A block to combine the two values into a single value
     mutating func merge(_ key1: Key, _ key2: Key, combine: (Value?, Value?) throws -> Value?) rethrows {
         let node1 = values[key1]
         let node2 = values[key2]

//  Copyright © 2016 Matt Diephouse. All rights reserved.
//

private class Node<Key: Hashable, Value> {
    var keys: Set<Key>
    var value: Value?
    
    init(keys: Set<Key>, value: Value?) {
        self.keys = keys
        self.value = value
    }
}

internal struct Context<Key: Hashable, Value> {
    private var values: [Key: Node<Key, Value>] = [:]
    
    subscript(_ key: Key) -> Value? {
        get {
            return values[key]?.value

        }
    }
    
    /// Remove a key from the context.
    ///
    /// - note: This will clear this key's association with any linked keys, but
    ///         will not remove the linked keys themselves.
    mutating func removeValue(forKey key: Key) {
        values.removeValue(forKey: key)
    }
    
    /// Upbate the value of a key.
    ///
    /// - parameters:
    ///   - newValue: The new value to give the linked keys
    ///   - key: Any key
    ///
    /// - returns: The previous value of `key`, if any.
    @discardableResult
    mutating func updateValue(_ newValue: Value?, forKey key: Key) -> Value? {
        return updateValue(forKey: key) { _ in newValue }
    }
    
    /// Upbate the value of a key.
    ///
    /// - parameters:
    ///   - newValue: The new value to give the linked keys
    ///   - transform: A block that takes the current value and returns a new
    ///                one.
    ///
    /// - returns: The previous value of `key`, if any.    @discardableResult
    mutating func updateValue(forKey key: Key, transform: (Value?) throws -> Value?) rethrows -> Value? {
        let node = values[key]
        let oldValue = node?.value
