   indices = (parseInt(index, 10) for index, val of arr when isArrayIndex(index))
   if indices.length then Math.max(indices...) + 1 else 0
 
+mark = (collection, item) ->
+  if item?._useDefer
+    item._inCollections or= {}
+    item._inCollections[collection] = collection
+
+unmark = (collection, item) ->
+  delete item._inCollections[collection] if item?._inCollections
+
 class exports.Collection
   extend(@prototype, Events)
   constructor: (list) ->

  find: (fun) ->
    return item for item in @ when fun(item)
  insertAt: (index, value) ->
    @_in(value)
    Array.prototype.splice.call(@, index, 0, value)
    @trigger("insert", index, value)
    @trigger("change", @)
    value
  deleteAt: (index) ->
    value = @[index]
    @_notIn(value)
    Array.prototype.splice.call(@, index, 1)
    @trigger("delete", index, value)
    @trigger("change", @)

  unshift: (item) -> @insertAt(0, item)
  shift: -> @deleteAt(0)
  update: (list) ->
    unmark(@, element) for element in @
    delete @[index] for index, _ of @ when isArrayIndex(index)
    @[index] = val for val, index in list
    mark(@, element) for element in list
    @trigger("update", list)
    @trigger("change", @)
    list
  splice: (start, deleteCount, list...) ->
    mark(@, element) for item in list
    deleted = Array.prototype.splice.apply(@, [start, deleteCount, list...])
    unmark(@, element) for element in deleted
    @trigger("update", list)
    @trigger("change", @)
    new Collection(deleted)
