// File: ashlall[P]StreamStats/ChiSquareExperiments/./../SourceCode/ChiSquare/../Quantiles/Q-Digest.cpp
// Function: QDigest::offer(long)
void QDigest::offer(long value)
{
  if (value < 0 || value == MAX_VALUE)
  {
    try 
    {
      throw value;
    }
    catch (long value)
    {
      cout << "Can only accept values in the range 0.. " <<  MAX_VALUE - 1 << endl;
    }  
  }
	
  // Rebuild if the value is too large for the current tree height
  if (value >= capacity)
    rebuildToCapacity(highestOneBit(value) << 1);   
		
 long leaf = value2leaf(value);
 if (node2count.find(leaf) == node2count.end())
   node2count.insert(std::make_pair (leaf, get(leaf)+1));
 else
   node2count[leaf] += 1;   
 size++;

 //Always compress at the inserted node, and recompress fully
 //if the tree becomes too large.
 compressUpward(leaf);
 if (node2count.size() > 3 * compression_factor) 
   compressFully();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x10(%rbp)
jl 0x3900
cmpq $0x3b9aca00, -0x10(%rbp) # imm = 0x3B9ACA00
jne 0x39b1
movl $0x8, %edi
callq 0x20c0
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq %rax, (%rdi)
movq 0x166c5(%rip), %rsi     # 0x19fe0
xorl %eax, %eax
movl %eax, %edx
callq 0x22f0
jmp 0x3b11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3b08
movq -0x18(%rbp), %rdi
callq 0x20b0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq 0x16674(%rip), %rdi     # 0x19fd0
leaq 0xe85a(%rip), %rsi      # 0x121bd
callq 0x21b0
movq %rax, -0x78(%rbp)
jmp 0x396e
movq -0x78(%rbp), %rdi
movl $0x3b9ac9ff, %esi       # imm = 0x3B9AC9FF
callq 0x2300
movq %rax, -0x80(%rbp)
jmp 0x3982
movq -0x80(%rbp), %rdi
movq 0x16633(%rip), %rsi     # 0x19fc0
callq 0x21d0
jmp 0x3994
callq 0x22c0
jmp 0x39b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x22c0
jmp 0x3b08
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
cmpq 0x48(%rcx), %rax
jl 0x39da
movq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4290
movq -0x70(%rbp), %rdi
shll %eax
movslq %eax, %rsi
callq 0x3f50
movq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x8bd0
movq -0x70(%rbp), %rdi
movq %rax, -0x30(%rbp)
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x8c20
movq -0x70(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x8, %rdi
callq 0x8c50
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8bf0
testb $0x1, %al
jne 0x3a24
jmp 0x3a75
movq -0x70(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rsi
callq 0x42e0
addq $0x1, %rax
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x8cc0
movq -0x88(%rbp), %rdi
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x8c80
movq %rax, -0x68(%rbp)
movb %dl, -0x60(%rbp)
jmp 0x3a90
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x8cf0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rdi
movq 0x40(%rdi), %rax
incq %rax
movq %rax, 0x40(%rdi)
movq -0x30(%rbp), %rsi
callq 0x4360
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x8d20
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, %xmm0
movaps 0xe6a8(%rip), %xmm1     # 0x12170
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xe6ac(%rip), %xmm1     # 0x12180
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0xe525(%rip), %xmm1     # 0x12010
mulsd 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3aff
movq -0x70(%rbp), %rdi
callq 0x4590
addq $0x90, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x2320
nopw %cs:(%rax,%rax)