Games-EternalLands
view release on metacpan or search on metacpan
src/bheap.c view on Meta::CPAN
* the item to be deleted.
*/
n = --(h->n);
p = h->p[item];
/* Heap needs adjusting if the position of the deleted item was not at the
* end of the heap.
*/
if(p <= n) {
/* We put the item at the end of the heap in the place of the deleted
* item and sift-up or sift-down to relocate it in the correct place in
* the heap.
*/
h->key_comps++;
if(h->a[p].key <= h->a[n + 1].key) {
h->a[p] = h->a[n + 1];
h->p[h->a[p].item] = p;
bh_siftup(h, p, n);
}
else {
/* Use insert to sift-down, temporarily adjusting the size of the
src/bheap.c view on Meta::CPAN
*/
h->n = p - 1;
bh_insert(h, h->a[n + 1].item, h->a[n+1].key);
h->n = n;
}
}
}
/* bh_decrease_key() decreases the value of 'item's key and then performs
* sift-down until 'item' has been relocated to the correct position in the
* binary heap.
*/
void bh_decrease_key(bheap_t *h, int item, long new_key)
{
int n;
n = h->n;
h->n = h->p[item] - 1;
bh_insert(h, item, new_key);
src/bheap.h view on Meta::CPAN
/* bh_insert() inserts an item and its key value into the binary heap pointed
* to by h.
*/
void bh_insert(bheap_t *h, int item, long key);
/* bh_delete() deletes an item from the binary heap pointed to by h.
*/
void bh_delete(bheap_t *h, int item);
/* bh_decrease_key() decreases the value of 'item's key and then performs
* sift-down until 'item' has been relocated to the correct position in the
* binary heap.
*/
void bh_decrease_key(bheap_t *h, int item, long new_key);
void bh_dump(bheap_t *h);
/*** Alternative interface via the universal heap structure type. ***/
extern const heap_info_t BHEAP_info;
#endif
( run in 1.092 second using v1.01-cache-2.11-cpan-5511b514fd6 )