// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/sasamples.cpp
// Function: CSA::SASamples::SASamples(std::pair<unsigned int, unsigned int>*, CSA::DeltaVector*, unsigned int, unsigned int, unsigned int)
SASamples::SASamples(short_pair* sa, DeltaVector* end_points, usint data_size, usint sample_rate, usint threads) :
  weighted(false),
  rate(sample_rate),
  items(0)
{
  usint sequences = end_points->getNumberOfItems();

  DeltaVector::Iterator iter(*(end_points));

  // Determine the samples, insert them into a vector, and sort them.
  usint start = 0, end = iter.select(0);  // Closed range in padded collection.
  usint seq_start = 0, seq_end = end;     // Closed range in inverse SA.
  std::vector<pair_type>* vec = new std::vector<pair_type>();
  for(usint i = 0; i < sequences; i++)
  {
    for(usint j = seq_start; j <= seq_end; j += this->rate)
    {
      vec->push_back(pair_type(sa[j].second - sequences, this->items));
      this->items++;
    }
    start = nextMultipleOf(this->rate, end);
    end = iter.selectNext();
    seq_start = seq_end + 2;
    seq_end = seq_start + end - start;
  }
  #ifdef MULTITHREAD_SUPPORT
  omp_set_num_threads(threads);
  #endif
  parallelSort(vec->begin(), vec->end());

  // Compress the samples.
  this->size = end + 1;
  WriteBuffer sample_buffer(this->items, length(this->items - 1));
  SAVector::Encoder encoder(INDEX_BLOCK_SIZE);
  for(usint i = 0; i < this->items; i++)
  {
    pair_type sample = (*vec)[i];
    encoder.setBit(sample.first);
    sample_buffer.writeItem(sample.second);
  }
  delete vec;

  this->indexes = new SAVector(encoder, this->size);
  this->samples = sample_buffer.getReadBuffer();
  this->buildInverseSamples();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, %rbx
movb $0x0, (%rdi)
movl %r8d, 0x4(%rdi)
movl $0x0, 0xc(%rdi)
movl 0x4(%rdx), %ebp
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x12744
movq %r14, %rdi
xorl %esi, %esi
callq 0x128f8
movl %eax, %r14d
movl $0x18, %edi
callq 0x3260
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, %r13
movq $0x0, 0x10(%rax)
testl %ebp, %ebp
je 0xb5d5
xorl %ecx, %ecx
xorl %r12d, %r12d
movl %r14d, (%rsp)
movl %ecx, 0x4(%rsp)
cmpl %r14d, %r12d
ja 0xb594
movl %r12d, %eax
movl 0x4(%r15,%rax,8), %eax
subl %ebp, %eax
movl %eax, 0x30(%rsp)
movl 0xc(%rbx), %eax
movl %eax, 0x34(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0xc6a6
incl 0xc(%rbx)
addl 0x4(%rbx), %r12d
jmp 0xb564
movl 0x4(%rbx), %r12d
leaq 0xa0(%rsp), %rdi
callq 0x12a58
movl 0x4(%rsp), %ecx
movl %eax, %esi
movl (%rsp), %eax
xorl %edx, %edx
divl %r12d
notl %eax
imull %r12d, %eax
movl %r14d, %r12d
addl $0x2, %r12d
addl %esi, %r14d
addl $0x2, %r14d
addl %eax, %r14d
incl %ecx
movl %esi, (%rsp)
cmpl %ebp, %ecx
jne 0xb560
jmp 0xb5d8
movl %r14d, %esi
movq %rsi, %r15
movq (%r13), %rdi
movq 0x8(%r13), %rsi
callq 0xc629
incl %r15d
movl %r15d, 0x8(%rbx)
movl 0xc(%rbx), %esi
leal -0x1(%rsi), %eax
bsrl %eax, %edx
xorl $-0x20, %edx
addl $0x21, %edx
testl %eax, %eax
cmovel %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x11092
leaq 0x30(%rsp), %rdi
movl $0x10, %esi
movl $0x100000, %edx         # imm = 0x100000
callq 0x13026
cmpl $0x0, 0xc(%rbx)
je 0xb6b1
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movq (%r13), %rax
movl (%rax,%r12,8), %esi
movl 0x4(%rax,%r12,8), %ebp
movq %r15, %rdi
callq 0x13036
movl 0x14(%rsp), %ecx
movl 0x24(%rsp), %edx
movl %ecx, %eax
subl %edx, %eax
jb 0xb67e
movl %ebp, %esi
movl %eax, %ecx
shrl %cl, %esi
negb %dl
movl %edx, %ecx
shll %cl, %esi
shrl %cl, %esi
movq 0x8(%rsp), %rcx
movl 0x20(%rsp), %edx
orl %esi, (%rcx,%rdx,4)
incl 0x20(%rsp)
movl $0x20, 0x24(%rsp)
movl %eax, %ecx
testl %ecx, %ecx
je 0xb6a2
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
negb %cl
shll %cl, %ebp
shrl %cl, %ebp
movl %eax, %ecx
shll %cl, %ebp
movq 0x8(%rsp), %rax
movl 0x20(%rsp), %ecx
orl %ebp, (%rax,%rcx,4)
incl 0x28(%rsp)
incq %r12
movl 0xc(%rbx), %eax
cmpq %rax, %r12
jb 0xb633
movq (%r13), %rdi
testq %rdi, %rdi
je 0xb6c6
movq 0x10(%r13), %rsi
subq %rdi, %rsi
callq 0x3270
movl $0x18, %esi
movq %r13, %rdi
callq 0x3270
movl $0x48, %edi
callq 0x3260
movq %rax, %r14
movl 0x8(%rbx), %edx
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x1272c
movq %r14, 0x10(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x11156
movq %rax, 0x18(%rbx)
movq %rbx, %rdi
callq 0xb206
leaq 0x30(%rsp), %rdi
callq 0x13030
leaq 0x8(%rsp), %rdi
callq 0x11142
leaq 0xa0(%rsp), %rdi
callq 0x1274a
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x48, %esi
movq %r14, %rdi
callq 0x3270
jmp 0xb761
movq %rax, %rbx
jmp 0xb76b
jmp 0xb777
jmp 0xb777
jmp 0xb777
jmp 0xb75e
jmp 0xb777
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x13030
leaq 0x8(%rsp), %rdi
callq 0x11142
jmp 0xb77a
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x1274a
movq %rbx, %rdi
callq 0x3460
nop