// File: /workspace/github_cpp_makefile_star2_O3/ashlall[P]StreamStats/ChiSquareExperiments/./../SourceCode/ChiSquare/../Quantiles/Q-Digest.cpp
// Function: QDigest::rebuildToCapacity(long)
void QDigest::rebuildToCapacity(long newCapacity) 
{
  std::unordered_map<long, long> newNode2count;
  long scaleR = newCapacity / capacity - 1;  
  long scaleL = 1;
  std::vector<long> keys;
  keys.reserve(node2count.size());
	
  for (std::unordered_map<long, long>::const_iterator i = node2count.begin(); i != node2count.end(); i++)
    keys.push_back(i->first);
	
  std::sort(keys.begin(), keys.end());
    
  // adjusts and adds the values from the old tree into the new tree
  for (std::vector<long>::const_iterator i = keys.begin(); i != keys.end(); i++)
  {
    while (scaleL <= *i / 2)
      scaleL <<= 1;
    newNode2count.insert(std::make_pair (*i + scaleL * scaleR, get(*i))); 
   }
  node2count = newNode2count;
  capacity = newCapacity;
  compressFully();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r12
leaq -0x70(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq %rsi, -0x50(%rbp)
movq %rsi, %rax
cqto
idivq 0x48(%rdi)
movq %rax, %r15
leaq -0x40(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x20(%r12), %rsi
callq 0x6800
movq 0x18(%r12), %r14
testq %r14, %r14
je 0x3629
leaq -0x40(%rbp), %rbx
leaq 0x8(%r14), %rdx
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x3619
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x3621
movq %rbx, %rdi
callq 0x770c
movq (%r14), %r14
testq %r14, %r14
jne 0x35fb
movq %r12, -0x48(%rbp)
addq $0x8, %r12
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r14
cmpq %r14, %rbx
je 0x36ea
movq %r14, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7828
movq %rbx, %rdi
movq %r14, %rsi
callq 0x790c
movq -0x40(%rbp), %r13
cmpq -0x38(%rbp), %r13
je 0x36ea
decq %r15
movl $0x1, %r14d
movq (%r13), %rbx
movq %rbx, %rax
shrq $0x3f, %rax
addq %rbx, %rax
sarq %rax
movq %r14, %rcx
movq %rcx, %r14
addq %rcx, %rcx
cmpq %rax, %r14
jle 0x3696
movq %rbx, -0x58(%rbp)
movq %r12, %rdi
leaq -0x58(%rbp), %rsi
callq 0x7330
testq %rax, %rax
je 0x36bc
movq 0x10(%rax), %rax
jmp 0x36be
xorl %eax, %eax
movq %r14, %rcx
imulq %r15, %rcx
addq %rcx, %rbx
movq %rbx, -0x68(%rbp)
movq %rax, -0x60(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7392
addq $0x8, %r13
cmpq -0x38(%rbp), %r13
jne 0x3682
leaq -0xa0(%rbp), %rax
cmpq %r12, %rax
movq -0x48(%rbp), %rbx
je 0x3709
leaq -0xa0(%rbp), %rsi
movq %r12, %rdi
callq 0x693e
movq -0x50(%rbp), %rax
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x3956
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3727
callq 0x21f0
leaq -0xa0(%rbp), %rdi
callq 0x68ba
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3746
jmp 0x3746
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3757
callq 0x21f0
leaq -0xa0(%rbp), %rdi
callq 0x68ba
movq %rbx, %rdi
callq 0x2360
nop