SimGrid: Heap: generic heap data structure

SimGrid 3.10 Versatile Simulation of Distributed Systems

- Home page
- Online documentation
- Dev's Corner

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions
Heap: generic heap data structure
Usual data structures

This section describes the API to generic heap with O(log(n)) access. More...

## Functions
xbt_heap_t | xbt_heap_new (int init_size, void_f_pvoid_t const free_func)
| Creates a new heap.
void | xbt_heap_free (xbt_heap_t H)
| kilkil a heap and its content
int | xbt_heap_size (xbt_heap_t H)
| returns the number of elements in the heap
void | xbt_heap_push (xbt_heap_t H, void *content, double key)
| Add an element into the heap.
void * | xbt_heap_pop (xbt_heap_t H)
| Extracts from the heap and returns the element with the smallest key.
double | xbt_heap_maxkey (xbt_heap_t H)
| returns the smallest key in the heap (heap unchanged)
void * | xbt_heap_maxcontent (xbt_heap_t H)
| returns the value associated to the smallest key in the heap (heap unchanged)
void | xbt_heap_set_update_callback (xbt_heap_t H, void(*update_callback)(void *, int))
| Set the update callback function.
void * | xbt_heap_remove (xbt_heap_t H, int i)
| Extracts from the heap and returns the element at position i.

## Detailed Description

This section describes the API to generic heap with O(log(n)) access.

## Function Documentation

xbt_heap_t xbt_heap_new | ( | int | init_size,
|  | void_f_pvoid_t const | free_func
| ) |  |

Creates a new heap.

Parameters

  init_size | initial size of the heap
  free_func | function to call on each element when you want to free the whole heap (or NULL if nothing to do).

Creates a new heap.

void xbt_heap_free | ( | xbt_heap_t | H | ) |

kilkil a heap and its content

Parameters

  H | poor victim

int xbt_heap_size | ( | xbt_heap_t | H | ) |

returns the number of elements in the heap

Parameters

  H | the heap we're working on

Returns
  the number of elements in the heap

void xbt_heap_push | ( | xbt_heap_t | H,
|  | void * | content,
|  | double | key
| ) |  |

Add an element into the heap.

Parameters

  H | the heap we're working on
  content | the object you want to add to the heap
  key | the key associated to this object

The element with the smallest key is automatically moved at the top of the heap.

void* xbt_heap_pop | ( | xbt_heap_t | H | ) |

Extracts from the heap and returns the element with the smallest key.

Parameters

  H | the heap we're working on

Returns
  the element with the smallest key

Extracts from the heap and returns the element with the smallest key. The element with the next smallest key is automatically moved at the top of the heap.

double xbt_heap_maxkey | ( | xbt_heap_t | H | ) |

returns the smallest key in the heap (heap unchanged)

Parameters

  H | the heap we're working on

Returns
  the smallest key in the heap without modifying the heap.

void* xbt_heap_maxcontent | ( | xbt_heap_t | H | ) |

returns the value associated to the smallest key in the heap (heap unchanged)

Parameters

  H | the heap we're working on

Returns
  the value associated to the smallest key in the heap without modifying the heap.

void xbt_heap_set_update_callback | ( | xbt_heap_t | H,
|  | void(*)(void *, int) | update_callback
| ) |  |

Set the update callback function.

Parameters

  H | the heap we're working on
  update_callback | function to call on each element to update its index when needed.

void* xbt_heap_remove | ( | xbt_heap_t | H,
|  | int | i
| ) |  |

Extracts from the heap and returns the element at position i.

Parameters

  H | the heap we're working on
  i | element position

Returns
  the element at position i if ok, NULL otherwise

Extracts from the heap and returns the element at position i. The heap is automatically reorded.