             case .removeAt(_):
                 break
             case .replaceAt(let index, with: _):
-                result.add(index - delta)
+                result.insert(index - delta)
                 break
             case .replaceRange(let indices, with: let elements):
                 let commonCount = min(elements.count, indices.count)
                 if commonCount > 0 {
-                    result.add(in: NSRange(indices.lowerBound - delta ..< indices.lowerBound + commonCount - delta))
+                    result.insert(integersIn: indices.lowerBound - delta ..< indices.lowerBound + commonCount - delta)
                 }
                 if commonCount < indices.count {
                     delta += modification.deltaCount

    /// Return the set of indices at which elements will be replaced in the array when this change is applied.
    /// The returned indices assume deletions were already done, but not insertions.
    /// This is intended to be given to a `UITableView` inside a `beginUpdates` block.
    public var reloadedIndices: NSIndexSet {
        let result = NSMutableIndexSet()
        var delta = 0
        for modification in modifications {
            switch modification {


    /// Return the set of indices at which elements will be deleted from the array when this change is applied.
    /// This is intended to be given to a `UITableView` inside a `beginUpdates` block.
    public var deletedIndices: IndexSet {
        var result = IndexSet()
        var delta = 0
        for modification in modifications {
            switch modification {
            case .insert(_, at: _):
                break
            case .removeAt(let index):
                result.insert(index - delta)
            case .replaceAt(_, with: _):
                break
            case .replaceRange(let indices, with: let elements):
                if elements.count < indices.count {
                    result.insert(integersIn: indices.lowerBound + elements.count - delta ..< indices.upperBound - delta)
                }
            }
            delta += modification.deltaCount
