C++ bindings for cgul_heap
More...
#include <cgul_heap_cxx.h>
This class provides the C++ bindings for C cgul_heap
objects. The main purpose of this class is to convert the C-style function calls and exception handling in cgul_heap
into C++-style function calls and exception handling.
- See also
- cgul_heap_t
§ cgul_heap_cxx() [1/3]
Create a new cgul_heap_cxx
object that maintains heap order using the comparison function cf
. The caller is responsible for freeing the object by calling delete
on the object. If memory cannot be allocated, an exception is thrown.
- Note
cgul_heap_cxx
is by default a max-heap, but it can be used as a min-heap simply by negating the output of the comparison function.
- Parameters
-
[in] | cf | comparison function |
- Returns
- new
cgul_heap_cxx
instance
§ cgul_heap_cxx() [2/3]
Create a new cgul_heap_cxx
object from the vector v
. The new heap maintains heap order using the comparison function cf
. The caller is responsible for freeing the object by calling delete
on the object. This class takes ownership of the underlying cgul_vector
so that deleting the object also deletes the underlying vector. If memory cannot be allocated, an exception is thrown.
- Note
cgul_heap_cxx
is by default a max-heap, but it can be used as a min-heap simply by negating the output of the comparison function.
- Note
- The asymptotic complexity of this method is O(n) which is more efficient than creating an empty heap and inserting n elements which would be O(n log n).
- Parameters
-
[in] | v | vector |
[in] | cf | comparison function |
§ cgul_heap_cxx() [3/3]
Create a new cgul_heap_cxx
object by wrapping an existing cgul_heap
object.
- Parameters
-
§ ~cgul_heap_cxx()
virtual cgul_heap_cxx::~cgul_heap_cxx |
( |
| ) |
|
|
inlinevirtual |
This method frees all internally allocated memory. This method does not free the elements stored in the heap. The caller allocated those elements so the caller is responsible for freeing them. Do not try to access heap
after calling this method.
- See also
- free_values()
References cgul_heap__delete().
§ free_values()
virtual void cgul_heap_cxx::free_values |
( |
| ) |
|
|
inlinevirtual |
This method calls free()
on all the values in the heap heap
. Because this is such a common operation, it is an exception to the rule that cgul containers never free values. This method should only ever be called immediately before calling delete
on the object because it otherwise invalidates the heap.
References cgul_heap__free_values().
§ is_empty()
virtual int cgul_heap_cxx::is_empty |
( |
| ) |
const |
|
inlinevirtual |
§ push()
virtual void cgul_heap_cxx::push |
( |
void * |
value | ) |
|
|
inlinevirtual |
Push the value value
onto the heap maintaining heap order using the some comparison function that was passed into the heap constructor. If an error occurs, an exception is thrown.
- Parameters
-
[in] | value | to push onto the heap |
References cgul_heap__push().
§ pop()
virtual void* cgul_heap_cxx::pop |
( |
| ) |
|
|
inlinevirtual |
Pop the top value from the heap maintaining heap order using the some comparison function that was passed into the heap constructor. If the heap is empty, NULL
is returned.
- Returns
- top value
References cgul_heap__pop().
§ top()
virtual void* cgul_heap_cxx::top |
( |
| ) |
|
|
inlinevirtual |
Return the top value from the heap without removing it from the heap. If the heap is empty, NULL
is returned.
- Returns
- top value
References cgul_heap__top().
§ get_size()
virtual unsigned long int cgul_heap_cxx::get_size |
( |
| ) |
const |
|
inlinevirtual |
Return the size of the heap. This is a count of the total number of elements stored in the heap.
- Returns
- size of the heap
References cgul_heap__get_size().
§ swap()
Swap the underlying data for this object and rhs
. For large heaps, this should be much faster than trying to do the same thing using removes and inserts.
- Parameters
-
References cgul_heap__swap().
§ get_obj()
Get the underlying cgul_heap
object.
- Returns
- underlying object
§ take_obj()
Take the underlying cgul_heap
object. This means the underlying object will not be deleted when the wrapper goes out of scope. Also, because you have taken the underlying object, no other methods should be called on this wrapper's instance. Lastly, after taking the underlying object, it is the caller's responsibility to delete the underlying object by calling cgul_heap__delete()
.
- Returns
- underlying object
§ set_obj()
Set the new underlying object to rhs
. This causes the old underlying object to be deleted which invalidates any outstanding pointers to or iterators for the old underlying object.
This instance takes ownership of rhs
which means rhs
will be automatically deleted when the C++ wrapper is deleted. To prevent automatic deletion of rhs
, call take_obj()
when the C++ wrapper is no longer needed.
- Parameters
-
References cgul_heap__delete(), cgul_heap__new_from_vector(), and cgul_vector_cxx::take_obj().
The documentation for this class was generated from the following file: