   }
   public func flatMap<T>(@noescape transform: [Element] -> Trie<T>) -> Trie<T> {
     var ret = Trie<T>()
-    for trie in contents.map(transform) { ret.merge(trie) }
+    for trie in contents.map(transform) { ret.unionInPlace(trie) }
     return ret
   }
 }

// MARK: Definition

public struct Trie<Element : Hashable> {
  private var children: [Element:Trie<Element>]

}

extension Trie {
  public mutating func unionInPlace(with: Trie<Element>) {
    for (head, child) in with.children {
      children[head]?.unionInPlace(child) ?? {children[head] = child}()
    }
  }
}

extension Trie {
  public mutating func exclusiveOrInPlace<
    S : SequenceType where
    S.Generator.Element : SequenceType,
    S.Generator.Element.Generator.Element == Element
    >(sequence: S) {
      for toRemove in sequence { remove(toRemove) }
  }
}

extension Trie {
  public func intersect<
    S : SequenceType where
    S.Generator.Element : SequenceType,
    S.Generator.Element.Generator.Element == Element
    >(sequence: S) -> Trie<Element> {
      var ret = Trie()
      for element in sequence where contains(element) { ret.insert(element) }
      return ret
  }
}

extension Trie {
  public func isDisjointWith<
    S : SequenceType where
    S.Generator.Element : SequenceType,
    S.Generator.Element.Generator.Element == Element
    >(sequence: S) -> Bool { return !sequence.contains(self.contains) }
}

extension Trie {
