]> git.proxmox.com Git - libgit2.git/blob - src/pqueue.h
Merge remote-tracking branch 'source/development' into update-test
[libgit2.git] / src / pqueue.h
1 /*
2 * Copyright (C) 2009-2012 the libgit2 contributors
3 *
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.
6 */
7
8 #ifndef INCLUDE_pqueue_h__
9 #define INCLUDE_pqueue_h__
10
11 /** callback functions to get/set/compare the priority of an element */
12 typedef int (*git_pqueue_cmp)(void *a, void *b);
13
14 /** the priority queue handle */
15 typedef struct {
16 size_t size, avail, step;
17 git_pqueue_cmp cmppri;
18 void **d;
19 } git_pqueue;
20
21
22 /**
23 * initialize the queue
24 *
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
28 *
29 * @Return the handle or NULL for insufficent memory
30 */
31 int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri);
32
33
34 /**
35 * free all memory used by the queue
36 * @param q the queue
37 */
38 void git_pqueue_free(git_pqueue *q);
39
40 /**
41 * clear all the elements in the queue
42 * @param q the queue
43 */
44 void git_pqueue_clear(git_pqueue *q);
45
46 /**
47 * return the size of the queue.
48 * @param q the queue
49 */
50 size_t git_pqueue_size(git_pqueue *q);
51
52
53 /**
54 * insert an item into the queue.
55 * @param q the queue
56 * @param d the item
57 * @return 0 on success
58 */
59 int git_pqueue_insert(git_pqueue *q, void *d);
60
61
62 /**
63 * pop the highest-ranking item from the queue.
64 * @param p the queue
65 * @param d where to copy the entry to
66 * @return NULL on error, otherwise the entry
67 */
68 void *git_pqueue_pop(git_pqueue *q);
69
70
71 /**
72 * access highest-ranking item without removing it.
73 * @param q the queue
74 * @param d the entry
75 * @return NULL on error, otherwise the entry
76 */
77 void *git_pqueue_peek(git_pqueue *q);
78
79 #endif /* PQUEUE_H */
80 /** @} */
81