Branch: Tag:

2017-06-13

2017-06-13 09:32:55 by Henrik Grubbström (Grubba) <grubba@grubba.org>

ADT.Heap: Survive the same Element being pushed multiple times.

Calling push() with an Element already present on the heap is
now equivalent to calling adjust() with the same element.

Previously the heap got corrupted in the above case.

99:   //! Returns an element handle, which can be used with   //! @[adjust()] and @[remove()].   //! + //! @note + //! If @[value] is a @[Heap.Element] and already present on the heap + //! this is equivalent to calling @[adjust()]. + //!   //! @seealso   //! @[pop()], @[remove()]   Element push(mixed value)
106:    Element ret;    if (objectp(value) && value->is_adt_heap_element) {    ret = value; +  +  if (ret->pos >= 0) { +  // Element already on the Heap. +  // FIXME: Verify that the element is on *this* heap? +  return adjust(ret); +  }    } else {    ret = Element(value);    }