34 #include "asterisk/heap.h"
64 return h->
heap[i - 1];
94 for (i = 1; i <= (h->
cur_len / 2); i++) {
98 if (l <= h->cur_len) {
104 if (r <= h->cur_len) {
116 ssize_t
index_offset,
const char *file,
int lineno,
const char *func)
119 ssize_t index_offset)
180 ,
const char *file,
int lineno,
const char *func
185 size_t new_len = h->avail_len * 2 + 1;
188 new_heap =
__ast_realloc(h->heap, new_len *
sizeof(
void *), file, lineno, func);
190 new_heap =
ast_realloc(h->heap, new_len *
sizeof(
void *));
196 h->avail_len = new_len;
248 int _ast_heap_push(
struct ast_heap *h,
void *elm,
const char *file,
int lineno,
const char *func)
272 if (!index || index > h->
cur_len) {
static int grow_heap(struct ast_heap *h)
Add a row of additional storage for the heap.
static ssize_t get_index(struct ast_heap *h, void *elm)
static void max_heapify(struct ast_heap *h, int i)
Asterisk main include file. File version handling, generic pbx functions.
static void * _ast_heap_remove(struct ast_heap *h, unsigned int index)
#define ast_rwlock_destroy(rwlock)
static void * heap_get(struct ast_heap *h, int i)
int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line)
Write-Lock a heap.
int ast_heap_push(struct ast_heap *h, void *elm)
Push an element on to a heap.
int __ast_rwlock_rdlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
int __ast_rwlock_unlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
void * ast_heap_pop(struct ast_heap *h)
Pop the max element off of the heap.
int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line)
Unlock a heap.
int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line)
Read-Lock a heap.
int(* ast_heap_cmp_fn)(void *elm1, void *elm2)
Function type for comparing nodes in a heap.
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
static int parent_node(int i)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
void * __ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
int __ast_rwlock_wrlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
static int right_node(int i)
static void heap_swap(struct ast_heap *h, int i, int j)
static int bubble_up(struct ast_heap *h, int i)
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
Structure for rwlock and tracking information.
Standard Command Line Interface.
size_t ast_heap_size(struct ast_heap *h)
Get the current size of a heap.
struct ast_heap * ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset)
Create a max heap.
#define ast_realloc(a, b)
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
int ast_heap_verify(struct ast_heap *h)
Verify that a heap has been properly constructed.
static int left_node(int i)
static void heap_set(struct ast_heap *h, int i, void *elm)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.