]>
git.proxmox.com Git - libgit2.git/blob - src/pqueue.h
2 * Copyright (C) 2009-2013 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.
7 * This file is based on a modified version of the priority queue found
8 * in the Apache project and libpqueue library.
10 * https://github.com/vy/libpqueue
12 * Original file notice:
14 * Copyright 2010 Volkan Yazici <volkan.yazici@gmail.com>
15 * Copyright 2006-2010 The Apache Software Foundation
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
18 * use this file except in compliance with the License. You may obtain a copy of
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26 * License for the specific language governing permissions and limitations under
30 #ifndef INCLUDE_pqueue_h__
31 #define INCLUDE_pqueue_h__
33 /** callback functions to get/set/compare the priority of an element */
34 typedef int (*git_pqueue_cmp
)(void *a
, void *b
);
36 /** the priority queue handle */
38 size_t size
, avail
, step
;
39 git_pqueue_cmp cmppri
;
45 * initialize the queue
47 * @param n the initial estimate of the number of queue items for which memory
48 * should be preallocated
49 * @param cmppri the callback function to compare two nodes of the queue
51 * @Return the handle or NULL for insufficent memory
53 int git_pqueue_init(git_pqueue
*q
, size_t n
, git_pqueue_cmp cmppri
);
57 * free all memory used by the queue
60 void git_pqueue_free(git_pqueue
*q
);
63 * clear all the elements in the queue
66 void git_pqueue_clear(git_pqueue
*q
);
69 * return the size of the queue.
72 size_t git_pqueue_size(git_pqueue
*q
);
76 * insert an item into the queue.
79 * @return 0 on success
81 int git_pqueue_insert(git_pqueue
*q
, void *d
);
85 * pop the highest-ranking item from the queue.
87 * @param d where to copy the entry to
88 * @return NULL on error, otherwise the entry
90 void *git_pqueue_pop(git_pqueue
*q
);
94 * access highest-ranking item without removing it.
97 * @return NULL on error, otherwise the entry
99 void *git_pqueue_peek(git_pqueue
*q
);
101 #endif /* PQUEUE_H */