The GSMinHeap class provides a container for objects
which are pushed into it, from which objects can be
popped out such that the popped object is the lowest
in the sort order provided by the comparator function.
Popping the lowest object removes it, but you
can also peek to see the lowest object without removing
it. This class is fast, but not thread-safe.
NB. objects with the same value may be popped
in any order. You must not assume that they will be popped
in the same order in which they were pushed.
Initialises a heap with the specified capacity
and comparator. If cap is zero the
initial capacity is one item. If
cmp is NULL the
-compare:
method is used as a comparator. If there is
insufficient memory, the method returns
nil.
Adds obj to the heap and returns
YES on success. May return
NO on failure (if obj was
nil or if there is insufficient memory
for the heap to grow). The heap takes ownership of
(retains) obj on success, but not on
failure. It is possible to push the same object ot
the heap more than once.
Adds obj to the heap if (and only if) it is
not already present. Returns YES on
success (the object was present or was added). May
return NO on failure (if obj
was nil or if there is insufficient memory
for the heap to grow). The heap takes ownership of
(retains) obj on success if it was
added.
If obj (as determined by pointer equality) is
present in the heap, removes duplicates and
are-establishes obj at its
correct location on the heap. Use this if
obj is mutable and has changed its value
in the comparator ordering. Returns
obj if it was present, nil
otherwise.
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.