Coin  4.0.10
Coin3D core library
Loading...
Searching...
No Matches
SbHeap Class Reference

The SbHeap class is a generic heap class. More...

#include <Inventor/SbHeap.h>

Public Member Functions

 SbHeap (const SbHeap &heap)
 
 SbHeap (const SbHeapFuncs &SbHeapFuncs, const int initsize=1024)
 
 ~SbHeap ()
 
int add (void *obj)
 
SbBool buildHeap (SbBool(*progresscb)(float percentage, void *data)=NULL, void *data=NULL)
 
void emptyHeap (void)
 
void * extractMin ()
 
void * getMin ()
 
void newWeight (void *obj, int hpos=-1)
 
SbHeap & operator= (const SbHeap &heap)
 
void * operator[] (const int idx)
 
void remove (const int pos)
 
void remove (void *obj)
 
int size (void) const
 
SbBool traverseHeap (SbBool(*func)(void *, void *), void *userdata) const
 

Detailed Description

The SbHeap class is a generic heap class.

FIXME: write doc

Note: SbHeap is an extension versus the Open Inventor API.

Constructor & Destructor Documentation

◆ SbHeap() [1/2]

SbHeap::SbHeap ( const SbHeapFuncs & hFuncs,
const int initsize = 1024 )

Constructor. hFuncs specifies the functions for modifying and returning information about the heap object, initsize specifies the initial number of allocated elements. This array will automatically grow when necessary, but if you know approximately how many elements the heap will contain, you should supply this to avoid some reallocs.

hFuncs must provide an evaluation function. An index getter requires an index setter, while a setter may be supplied without a getter. A heap using an index getter must have exclusive use of each object's stored heap index.

◆ ~SbHeap()

SbHeap::~SbHeap ( void )

Destructor. Objects with index callbacks must outlive their heap so their stored indices can be invalidated here.

◆ SbHeap() [2/2]

SbHeap::SbHeap ( const SbHeap & other)

Copy constructor. The element pointers and heap ordering are copied, but index callbacks are intentionally detached. An element can store the index for only one heap, so sharing index callbacks between two heaps would make one of them stale as soon as either heap changed.

Member Function Documentation

◆ add()

int SbHeap::add ( void * obj)

Adds a non-NULL element to the heap. Returns the element's heap position. The same pointer may occur more than once only when index callbacks are not used. Indexed elements must not simultaneously belong to another heap.

◆ buildHeap()

SbBool SbHeap::buildHeap ( SbBool(*)(float percentage, void *data) progresscb = NULL,
void * data = NULL )

Builds heap out of randomly ordered data-structure.

◆ emptyHeap()

void SbHeap::emptyHeap ( void )

Removes all the elements from the heap. If an index setter is supplied, every removed element is assigned index -1.

◆ extractMin()

void * SbHeap::extractMin ( void )

Returns and removes the first element in the heap, or NULL if heap is empty.

◆ getMin()

void * SbHeap::getMin ( void )

Returns the first element in the heap, or NULL if heap is empty.

◆ newWeight()

void SbHeap::newWeight ( void * obj,
int hpos = -1 )

Fixes heap if necessary when the element at hpos has changed weight. If you know the element's heap position you can supply it in hpos. The object must currently occupy that position. If no position is supplied, the object must currently belong to this heap.

◆ operator=()

SbHeap & SbHeap::operator= ( const SbHeap & other)

Assignment operator. Like the copy constructor, the assigned heap is a non-indexed snapshot. The destination's former indices are invalidated after replacement, except for shared elements whose source still owns an index callback.

◆ operator[]()

void * SbHeap::operator[] ( const int idx)

Returns the heap element at index idx in the heap. The index must be between 1 and size(), inclusive.

◆ remove() [1/2]

void SbHeap::remove ( const int idx)

Removes an element from the heap. idx must be between 1 and size(), inclusive.

◆ remove() [2/2]

void SbHeap::remove ( void * obj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

obj must be a non-NULL element currently stored in this heap. If index callbacks are used, its stored index must refer to this heap.

◆ size()

int SbHeap::size ( void ) const

Returns the number of elements in the heap.

◆ traverseHeap()

SbBool SbHeap::traverseHeap ( SbBool(*)(void *, void *) func,
void * userdata ) const

Traverses each heap elements, and calls func for each element. func must not be NULL and must not modify this heap while traversing it.


The documentation for this class was generated from the following files: