     }
     
     public var startIndex: Index {
-        // TODO: We should cache this result
-        
         // If this winds up being NSNotFound, that's ok because then endIndex is also NSNotFound, and empty collections have startIndex == endIndex
-        return Index(firstIn: self)
+        let extent = _range(at: 0)
+        return Index(value: extent.lowerBound, extent: extent, rangeIndex: 0, rangeCount: _rangeCount)
     }
 
     public var endIndex: Index {
-        // TODO: We should cache this result
-        
-        return Index(lastIn: self)
+        let rangeCount = _rangeCount
+        let rangeIndex = rangeCount - 1
+        let extent : Range<Int>
+        let value : Int
+        if rangeCount > 0 {
+            extent = _range(at: rangeCount - 1)
+            value = extent.upperBound // "1 past the end" position is the last range, 1 + the end of that range's extent
+        } else {
+            extent = 0..<0
+            value = 0
+        }
+        
+        return Index(value: value, extent: extent, rangeIndex: rangeIndex, rangeCount: rangeCount)
     }
     
     public subscript(index : Index) -> Element {

    // Indexable
    
    public func index(after i: Index) -> Index {
        return i.successor()
    }
    
    public func formIndex(after i: inout Index) {
        i._successorInPlace()
    }
    
    public func index(before i: Index) -> Index {
        return i.predecessor()
    }
    
    public func formIndex(before i: inout Index) {
        i._predecessorInPlace()
    }
    
    // MARK: -

        
    }
    
    /// The mechanism for accessing the integers stored in an IndexSet.
    public struct Index : CustomStringConvertible, Comparable {
        private var value : IndexSet.Element
        private var extent : Range<IndexSet.Element>
        private var rangeIndex : Int
        private let rangeCount : Int
        
        private init(value: Int, extent: Range<Int>, rangeIndex: Int, rangeCount: Int) {
            self.value = value
            self.extent = extent
            self.rangeCount = rangeCount
            self.rangeIndex = rangeIndex
        }
        
        public var description: String {
            return "index \(value) in a range of \(extent) [range #\(rangeIndex + 1)/\(rangeCount)]"
        }
    }

