X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fprioq.c;h=d2ec516d297ccaca972cb8d9d85bb36e600c8716;hb=2ed028df72f5995acfbeca89db3f056d0e83cac1;hp=b89888be0e8d5460313ffc3e9712856f214ce5d2;hpb=3b22396a4b2767a98172f6915929c47738cb0a1e;p=elogind.git diff --git a/src/basic/prioq.c b/src/basic/prioq.c index b89888be0..d2ec516d2 100644 --- a/src/basic/prioq.c +++ b/src/basic/prioq.c @@ -1,5 +1,3 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - /*** This file is part of systemd. @@ -19,7 +17,21 @@ along with systemd; If not, see . ***/ -#include "util.h" +/* + * Priority Queue + * The prioq object implements a priority queue. That is, it orders objects by + * their priority and allows O(1) access to the object with the highest + * priority. Insertion and removal are Θ(log n). Optionally, the caller can + * provide a pointer to an index which will be kept up-to-date by the prioq. + * + * The underlying algorithm used in this implementation is a Heap. + */ + +#include +#include + +#include "alloc-util.h" +#include "hashmap.h" #include "prioq.h" struct prioq_item { @@ -101,7 +113,7 @@ static unsigned shuffle_up(Prioq *q, unsigned idx) { k = (idx-1)/2; - if (q->compare_func(q->items[k].data, q->items[idx].data) < 0) + if (q->compare_func(q->items[k].data, q->items[idx].data) <= 0) break; swap(q, idx, k);