// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, %rbx
movq %rdi, %rcx
leaq -0x78(%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, %rax
cqto
idivq 0x48(%rdi)
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rcx, -0x30(%rbp)
movq 0x20(%rcx), %rsi
callq 0x69a4
movq -0x30(%rbp), %rax
movq 0x18(%rax), %r14
testq %r14, %r14
je 0x3708
leaq -0x50(%rbp), %r12
leaq 0x8(%r14), %rdx
movq -0x48(%rbp), %rsi
cmpq -0x40(%rbp), %rsi
je 0x36f8
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, -0x48(%rbp)
jmp 0x3700
movq %r12, %rdi
callq 0x788c
movq (%r14), %r14
testq %r14, %r14
jne 0x36da
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %r13
cmpq %r13, %r12
je 0x3742
movq %r13, %rax
subq %r12, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x79a8
movq %r12, %rdi
movq %r13, %rsi
callq 0x7a8c
movq %rbx, -0x60(%rbp)
movq -0x50(%rbp), %r14
cmpq -0x48(%rbp), %r14
je 0x37b7
decq -0x58(%rbp)
movl $0x1, %r15d
leaq -0xa8(%rbp), %r12
leaq -0x70(%rbp), %r13
movq (%r14), %rcx
movq %rcx, %rax
shrq $0x3f, %rax
addq %rcx, %rax
sarq %rax
movq %r15, %rcx
movq %rcx, %r15
addq %rcx, %rcx
cmpq %rax, %r15
jle 0x3778
movq (%r14), %rsi
movq %r15, %rbx
imulq -0x58(%rbp), %rbx
addq %rsi, %rbx
movq -0x30(%rbp), %rdi
callq 0x3864
movq %rbx, -0x70(%rbp)
movq %rax, -0x68(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x7522
addq $0x8, %r14
cmpq -0x48(%rbp), %r14
jne 0x3765
movq -0x30(%rbp), %rax
leaq 0x8(%rax), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rdi, %rax
movq -0x60(%rbp), %rbx
je 0x37db
leaq -0xa8(%rbp), %rsi
callq 0x6ade
movq -0x30(%rbp), %rdi
movq %rbx, 0x48(%rdi)
callq 0x3ad2
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x37f6
callq 0x21f0
leaq -0xa8(%rbp), %rdi
callq 0x6a5a
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3818
jmp 0x3818
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x3829
callq 0x21f0
leaq -0xa8(%rbp), %rdi
callq 0x6a5a
movq %rbx, %rdi
callq 0x2360
nop