/**
 * @module core/utils/sorted_set
 * @flow
 */

/** Custom SortedSet implementation
 *
 * We want to be able to reduce a collection while still have the ability to
 * easily delete an element from the collection (i.e. without looking for
 * the element's index first).
 *
 * However:
 * - Sets cannot be reduced
 * - Arrays do not offer the ability to delete an element directly
 *
 * The SortedSet data structure uses both an Array and a Set to make
 * those 2 actions possible transparently.
 */
class SortedSet /* ::<A> */ {
  /*::
  _set: Set<A>
  _values: A[]
  */

  constructor() {
    this._set = new Set()
    this._values = []
  }

  has(value /*: A */) {
    return this._set.has(value)
  }

  add(value /*: A */) {
    this._set.add(value)
    this._values.push(value)
    return this
  }

  delete(value /*: A */) {
    if (this._set.delete(value)) {
      const index = this._values.indexOf(value)
      this._values.splice(index, 1)
      return true
    }
    return false
  }

  reduceRight /* ::<B> */(
    callback /*: (B, A) => B */,
    initialValue /*: B */
  ) /*: B */ {
    return this._values.reduceRight(callback, initialValue)
  }
}

module.exports = SortedSet

@@ -638,16 +638,62 @@
 %5B%5D%0A  %7D%0A%0A
+  get size() %7B%0A    return this._set.size%0A  %7D%0A%0A
   has(va
@@ -777,29 +777,94 @@
     
-this._set.add(value)%0A
+const prevSize = this.size%0A    this._set.add(value)%0A    if (this.size %3E prevSize) %7B%0A  
     
@@ -884,24 +884,30 @@
 push(value)%0A
+    %7D%0A
     return t

Fix add method