]>
git.proxmox.com Git - libgit2.git/blob - src/pqueue.h
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
8 #ifndef INCLUDE_pqueue_h__
9 #define INCLUDE_pqueue_h__
11 /** callback functions to get/set/compare the priority of an element */
12 typedef int (*git_pqueue_cmp
)(void *a
, void *b
);
14 /** the priority queue handle */
16 size_t size
, avail
, step
;
17 git_pqueue_cmp cmppri
;
23 * initialize the queue
25 * @param n the initial estimate of the number of queue items for which memory
26 * should be preallocated
27 * @param cmppri the callback function to compare two nodes of the queue
29 * @Return the handle or NULL for insufficent memory
31 int git_pqueue_init(git_pqueue
*q
, size_t n
, git_pqueue_cmp cmppri
);
35 * free all memory used by the queue
38 void git_pqueue_free(git_pqueue
*q
);
41 * clear all the elements in the queue
44 void git_pqueue_clear(git_pqueue
*q
);
47 * return the size of the queue.
50 size_t git_pqueue_size(git_pqueue
*q
);
54 * insert an item into the queue.
57 * @return 0 on success
59 int git_pqueue_insert(git_pqueue
*q
, void *d
);
63 * pop the highest-ranking item from the queue.
65 * @param d where to copy the entry to
66 * @return NULL on error, otherwise the entry
68 void *git_pqueue_pop(git_pqueue
*q
);
72 * access highest-ranking item without removing it.
75 * @return NULL on error, otherwise the entry
77 void *git_pqueue_peek(git_pqueue
*q
);