Algorithm-Heapify-XS
view release on metacpan or search on metacpan
AV *av
PROTOTYPE: \@
ALIAS:
max_heapify = 0
min_heapify = 1
maxstr_heapify = 2
minstr_heapify = 3
PREINIT:
OP fakeop;
I32 count;
PPCODE:
FORCE_SCALAR(fakeop);
count = av_top_index(av)+1;
if ( count ) {
heapify_with_sift_down(aTHX_ AvARRAY(av),count,ix);
ST(0)= AvARRAY(av)[0];
XSRETURN(1);
}
else {
XSRETURN(0);
}
PROTOTYPE: \@
ALIAS:
max_heap_shift = 0
min_heap_shift = 1
maxstr_heap_shift = 2
minstr_heap_shift = 3
PREINIT:
OP fakeop;
I32 top;
I32 count;
PPCODE:
FORCE_SCALAR(fakeop);
top= av_top_index(av);
count= top+1;
if (count) {
SV *tmp= AvARRAY(av)[0];
AvARRAY(av)[0]= AvARRAY(av)[top];
AvARRAY(av)[top]= tmp;
ST(0)= av_pop(av);
if (count > 2)
sift_down(aTHX_ AvARRAY(av),0,top-1,ix);
PROTOTYPE: \@$
ALIAS:
max_heap_push = 0
min_heap_push = 1
maxstr_heap_push = 2
minstr_heap_push = 3
PREINIT:
OP fakeop;
I32 top;
I32 count;
PPCODE:
FORCE_SCALAR(fakeop);
av_push(av,newSVsv(sv));
top= av_top_index(av);
count= top+1;
sift_up(aTHX_ AvARRAY(av),0,top,ix);
ST(0)= AvARRAY(av)[0];
XSRETURN(1);
void
max_heap_adjust_top(av)
PROTOTYPE: \@
ALIAS:
max_heap_adjust_top = 0
min_heap_adjust_top = 1
maxstr_heap_adjust_top = 2
minstr_heap_adjust_top = 3
PREINIT:
OP fakeop;
I32 top;
I32 count;
PPCODE:
FORCE_SCALAR(fakeop);
top= av_top_index(av);
count= top+1;
if ( count ) {
(void)sift_down(aTHX_ AvARRAY(av),0,top,ix);
ST(0)= AvARRAY(av)[0];
XSRETURN(1);
} else {
XSRETURN(0);
}
PROTOTYPE: \@;$
ALIAS:
max_heap_adjust_item = 0
min_heap_adjust_item = 1
maxstr_heap_adjust_item = 2
minstr_heap_adjust_item = 3
PREINIT:
OP fakeop;
I32 top;
I32 count;
PPCODE:
FORCE_SCALAR(fakeop);
top= av_top_index(av);
count= top+1;
if ( idx < count ) {
if (!idx || !sift_up(aTHX_ AvARRAY(av),0,idx,ix))
(void)sift_down(aTHX_ AvARRAY(av),idx,top,ix);
ST(0)= AvARRAY(av)[0];
XSRETURN(1);
} else {
XSRETURN(0);
( run in 0.591 second using v1.01-cache-2.11-cpan-71847e10f99 )