Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtschump committed Nov 3, 2023
2 parents 870c61e + 332cb81 commit 57d6ef5
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions CImg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24610,7 +24610,10 @@ namespace cimg_library {
const int siz1 = siz - 1;
if (is_pop_heap) { // Heapify
if (dim==1) cimg::swap(img[0],img[siz1]);
else cimg_forC(img,c) cimg::swap(img(0,0,0,c),img(0,siz1,0,c));
else {
T *ptr0 = img.data(), *ptr1 = img.data(0,siz1);
cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }
}
int index = 0;
while (true) {
const int child_left = 2*index + 1, child_right = child_left + 1;
Expand All @@ -24619,18 +24622,24 @@ namespace cimg_library {
if (child_right<siz1 && img[child_right]<img[smallest]) smallest = child_right;
if (smallest!=index) {
if (dim==1) cimg::swap(img[index],img[smallest]);
else cimg_forC(img,c) cimg::swap(img(0,index,0,c),img(0,smallest,0,c));
else {
T *ptr0 = img.data(0,index), *ptr1 = img.data(0,smallest);
cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }
}
index = smallest;
} else break;
}
}

double ret = cimg::type<double>::nan();
if (dim==1) ret = img[siz1]; // Scalar element
else cimg_forC(img,c) ptrd[c] = img(0,siz1,0,c); // Vector element
else {
const T *ptrs = img.data(0,siz1);
cimg_forC(img,c) { ptrd[c] = *ptrs; ptrs+=img._height; } // Vector element
}
if (is_pop) { // Remove element from array
--siz;
if (img.height()>32 && siz<img.height()/6) // Reduce size of dynamic array
if (img.height()>32 && siz<img.height()/8) // Reduce size of dynamic array
img.resize(1,std::max(2*siz + 1,32),1,-100,0);
img[img._height - 1] = (T)cimg::uint2float(siz);
}
Expand Down Expand Up @@ -24704,12 +24713,14 @@ namespace cimg_library {
else // vectorN() elements, with N>1
for (unsigned int k = 0; k<nb_elts; ++k) {
int index = pos + k;
double *ptrs = &_mp_arg(6 + k) + 1;
cimg_forC(img,c) img(0,index,0,c) = ptrs[c];
const double *const ptrs = &_mp_arg(6 + k) + 1;
T *ptrd = img.data(0,index);
cimg_forC(img,c) { *ptrd = ptrs[c]; ptrd+=img._height; }
if (is_push_heap) while (index>0) { // Heapify
const int index_parent = (index - 1)/2;
if (img[index]<img[index_parent]) {
cimg_forC(img,c) cimg::swap(img(0,index,0,c),img(0,index_parent,0,c));
T *ptr0 = img.data(0,index), *ptr1 = img.data(0,index_parent);
cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }
index = index_parent;
}
else break;
Expand Down Expand Up @@ -24747,7 +24758,7 @@ namespace cimg_library {
if (end<siz - 1) // Move remaining data in dynamic array
cimg_forC(img,c) std::memmove(img.data(0,start,0,c),img.data(0,end + 1,0,c),(siz - 1 - end)*sizeof(T));
siz-=end - start + 1;
if (img.height()>32 && siz<img.height()/6) // Reduce size of dynamic array
if (img.height()>32 && siz<img.height()/8) // Reduce size of dynamic array
img.resize(1,std::max(2*siz + 1,32),1,-100,0);
img[img._height - 1] = (T)cimg::uint2float(siz);
return cimg::type<double>::nan();
Expand Down

0 comments on commit 57d6ef5

Please sign in to comment.