@@ -703,35 +703,37 @@ HistogramVBW::Bin* HistogramVBW::Bin::insertLeft(HistogramVBW::Bin* of, Histogra
703703 return toins;
704704}
705705
706- HistogramVBW::Bin* create_end (){
707- HistogramVBW::Bin* end = new HistogramVBW::Bin (0 ,0 ,0 );
706+ HistogramVBW::Bin* create_end (chunkAllocator<HistogramVBW::Bin> &alloc ){
707+ HistogramVBW::Bin* end = new (alloc. get ()) HistogramVBW::Bin (0 ,0 ,0 );
708708 end->is_end = true ;
709709 return end;
710710}
711711
712712
713- std::pair<HistogramVBW::Bin*,HistogramVBW::Bin*> HistogramVBW::Bin::insertFirst (HistogramVBW::Bin* toins){
713+ std::pair<HistogramVBW::Bin*,HistogramVBW::Bin*> HistogramVBW::Bin::insertFirst (HistogramVBW::Bin* toins, chunkAllocator<Bin> &alloc ){
714714 if (toins == nullptr ) fatal_error (" Nullptr exception" );
715- Bin* end = create_end ();
715+ Bin* end = create_end (alloc );
716716 insertLeft (end, toins);
717717 return {toins,end};
718718}
719719
720720
721721
722- void HistogramVBW::Bin::deleteChain (HistogramVBW::Bin* first){
722+ void HistogramVBW::Bin::deleteChain (HistogramVBW::Bin* first, chunkAllocator<Bin> &alloc ){
723723 if (first == nullptr ) fatal_error (" Nullptr exception" );
724724 if (first->left != nullptr ) fatal_error (" Deleting must start at the beginning of the chain" );
725725
726726 Bin* cur = first;
727727 Bin* next = cur->right ;
728728 while (next != nullptr ){
729- delete cur;
729+ cur->~Bin ();
730+ alloc.free (cur);
730731 cur = next;
731732 next = cur->right ;
732733 }
733734 if (!cur->is_end ) fatal_error (" Chain is broken" );
734- delete cur;
735+ cur->~Bin ();
736+ alloc.free (cur);
735737}
736738
737739HistogramVBW::Bin* HistogramVBW::Bin::getBin (HistogramVBW::Bin* start, double v){
@@ -756,7 +758,7 @@ HistogramVBW::Bin* HistogramVBW::Bin::getBin(HistogramVBW::Bin* start, double v)
756758}
757759
758760
759- std::pair<HistogramVBW::Bin*,HistogramVBW::Bin*> HistogramVBW::Bin::split (HistogramVBW::Bin* bin, double about){
761+ std::pair<HistogramVBW::Bin*,HistogramVBW::Bin*> HistogramVBW::Bin::split (HistogramVBW::Bin* bin, double about, chunkAllocator<Bin> &alloc ){
760762 if (bin == nullptr || bin->is_end ) fatal_error (" Invalid bin" );
761763 if (about <= bin->l || about > bin->u ){
762764 std::ostringstream os;
@@ -777,22 +779,19 @@ std::pair<HistogramVBW::Bin*,HistogramVBW::Bin*> HistogramVBW::Bin::split(Histog
777779 double fracs[2 ] = { (about - bin->l )/bw, 0 };
778780 fracs[1 ] = 1 . - fracs[0 ];
779781 double count = bin->c ;
780-
781- int lrg = 0 ;
782- double debt = count;
783- for (int i=0 ;i<2 ;i++){
784- o[i] = floor (fracs[i] * count + 0.5 );
785- debt -= o[i];
786- if (fracs[i] > fracs[lrg]) lrg = i;
787- }
782+
783+ o[0 ] = floor (fracs[0 ] * count + 0.5 );
784+ o[1 ] = floor (fracs[1 ] * count + 0.5 );
785+ double debt = count - o[0 ] - o[1 ];
786+ int lrg = fracs[1 ] > fracs[0 ] ? 1 : 0 ;
788787
789788 // Assign debt to largest fraction with preference from left
790789 o[lrg] += debt;
791790 double bu_prev = bin->u ;
792791 bin->u = about;
793792 bin->c = o[0 ];
794793
795- insertRight (bin, new Bin (about, bu_prev, o[1 ]));
794+ insertRight (bin, new (alloc. get ()) Bin (about, bu_prev, o[1 ]));
796795
797796 verboseStream << " Split bin into " << *bin << " and " << *bin->right << std::endl;
798797 return {bin, bin->right };
@@ -860,7 +859,7 @@ void HistogramVBW::import(const Histogram &h){
860859 if (h.Nbin () == 0 ) return ;
861860
862861 auto be = h.binEdges (0 );
863- auto fe = Bin::insertFirst (new Bin (be.first , be.second , h.binCount (0 )) );
862+ auto fe = Bin::insertFirst (new (allocator. get ()) Bin (be.first , be.second , h.binCount (0 )), allocator );
864863 first = fe.first ;
865864 end = fe.second ;
866865
@@ -877,15 +876,15 @@ void HistogramVBW::import(const Histogram &h){
877876 fatal_error (of.str ());
878877 }
879878
880- hp = Bin::insertRight (hp, new Bin (prev_upper, be.second , h.binCount (b)) );
879+ hp = Bin::insertRight (hp, new (allocator. get ()) Bin (prev_upper, be.second , h.binCount (b)) );
881880 prev_upper = be.second ;
882881 }
883882 m_min = h.getMin ();
884883 m_max = h.getMax ();
885884}
886885
887886HistogramVBW::~HistogramVBW (){
888- if (first != nullptr ) Bin::deleteChain (first);
887+ if (first != nullptr ) Bin::deleteChain (first,allocator );
889888}
890889
891890double HistogramVBW::totalCount () const {
@@ -927,7 +926,7 @@ double HistogramVBW::extractUniformCountInRangeInt(double l, double u){
927926
928927 if (bl != nullptr ){
929928 verboseStream << " Lower edge " << l << " in bin " << *bl << std::endl;
930- bl = Bin::split (bl,l).second ;
929+ bl = Bin::split (bl,l,allocator ).second ;
931930 if (bl->is_end ){
932931 verboseStream << " Right of split point is end" << std::endl;
933932 // If the split point matches the upper edge of the last bin, the .second pointer is END
@@ -946,7 +945,7 @@ double HistogramVBW::extractUniformCountInRangeInt(double l, double u){
946945
947946 Bin* bu = Bin::getBin (bl, u);
948947 if (bu != nullptr ){
949- bu = Bin::split (bu,u).first ;
948+ bu = Bin::split (bu,u,allocator ).first ;
950949 }else if (u <= first->l ){ // right edge is left of histogram
951950 return 0 ;
952951 }else if (u > last->u ){ // right edge is right of histogram
@@ -1009,7 +1008,7 @@ std::vector<double> HistogramVBW::extractUniformCountInRangesInt(const std::vect
10091008
10101009 if (bl != nullptr ){
10111010 verboseStream << " Lower edge " << l << " in bin " << *bl << std::endl;
1012- bl = Bin::split (bl,l).second ;
1011+ bl = Bin::split (bl,l, allocator ).second ;
10131012 if (bl->is_end ){
10141013 verboseStream << " Right of split point is end" << std::endl;
10151014 // If the split point matches the upper edge of the last bin, the .second pointer is END and the entry is 0
@@ -1029,7 +1028,7 @@ std::vector<double> HistogramVBW::extractUniformCountInRangesInt(const std::vect
10291028
10301029 Bin* bu = Bin::getBin (bl, u);
10311030 if (bu != nullptr ){
1032- bu = Bin::split (bu,u).first ;
1031+ bu = Bin::split (bu,u, allocator ).first ;
10331032 }else if (u <= first->l ){ // right edge is left of histogram
10341033 continue ;
10351034 }else if (u > last->u ){ // right edge is right of histogram
0 commit comments