 //  Copyright (c) 2014 Rob Rix. All rights reserved.
 
 /// A set of unique elements.
-public struct Set<Element: Hashable>: CollectionType, SequenceType {
+public struct Set<Element: Hashable>: CollectionType, ExtensibleCollectionType, SequenceType {
 	// MARK: Constructors
 
 	/// Constructs a `Set` with the elements of `sequence`.


	// MARK: CollectionType

	public typealias IndexType = DictionaryIndex<Element, Unit>
	public var startIndex: IndexType { return values.startIndex }
	public var endIndex: IndexType { return values.endIndex }

	public subscript(v: ()) -> Element {
		get { return values[values.startIndex].0 }
		set { insert(newValue) }
	}

	public subscript(index: IndexType) -> Element {
		return values[index].0
	}


	// MARK: Private

	/// The underlying dictionary.
	private var values: [Element: Unit]
}


/// ExtensibleCollectionType conformance.
extension Set: ExtensibleCollectionType {
	/// In theory, reserve capacity for `n` elements. However, Dictionary does not implement reserveCapacity(), so we just silently ignore it.
	public func reserveCapacity(n: IndexType.Distance) {}

	/// Inserts each element of `sequence` into the receiver.
	public mutating func extend<S: SequenceType where S.Generator.Element == Element>(sequence: S) {

	public mutating func append(element: Element) {
		insert(element)
	}


	// MARK: Private

	/// The underlying dictionary.
	private var values: [Element: Unit]
}


