/*
* CDDL HEADER START
*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
*/
#include <dtrace.h>
#include <dt_impl.h>
#include <dt_pq.h>
#include <assert.h>
/*
* Create a new priority queue.
*
* size is the maximum number of items that will be stored in the priority
* queue at one time.
*/
dt_pq_t *
{
dt_pq_t *p;
return (NULL);
if (p->dtpq_items == NULL) {
return (NULL);
}
p->dtpq_last = 1;
p->dtpq_value = value_cb;
return (p);
}
void
{
}
static uint64_t
{
}
void
{
uint_t i;
i = p->dtpq_last++;
p->dtpq_items[i] = item;
i /= 2;
}
}
/*
* Return elements from the priority queue. *cookie should be zero when first
* called. Returns NULL when there are no more elements.
*/
void *
{
(*cookie)++;
return (NULL);
return (p->dtpq_items[*cookie]);
}
void *
{
uint_t i = 1;
void *ret;
if (p->dtpq_last == 1)
return (NULL);
p->dtpq_last--;
for (;;) {
uint_t c;
uint64_t v;
void *tmp;
break;
c = lc;
v = dt_pq_getvalue(p, lc);
} else {
c = lc;
v = lv;
} else {
c = rc;
v = rv;
}
}
if (v >= dt_pq_getvalue(p, i))
break;
tmp = p->dtpq_items[i];
p->dtpq_items[i] = p->dtpq_items[c];
p->dtpq_items[c] = tmp;
i = c;
}
return (ret);
}