// File: adamnovak[P]rlcsa/bits/bitvector.cpp
// Function: CSA::VectorEncoder::VectorEncoder(unsigned int, unsigned int, bool)
VectorEncoder::VectorEncoder(usint block_bytes, usint superblock_size, bool _use_small_blocks) :
  size(0), items(0), blocks(0),
  block_size(BYTES_TO_WORDS(block_bytes)),
  superblock_bytes(superblock_size),
  use_small_blocks(_use_small_blocks),
  blocks_in_superblock(1), current_blocks(0),
  samples(0), samples_in_superblock(0), current_samples(0)
{
  this->array = new usint[this->superblock_bytes / sizeof(usint)];
  memset(this->array, 0, this->superblock_bytes);
  if(use_small_blocks)
  {
    this->blocks_in_superblock = this->superblock_bytes / (sizeof(usint) * this->block_size);
    this->buffer = new WriteBuffer(this->array, this->block_size);
    this->samples = new usint[this->superblock_bytes / sizeof(usint)];
    this->samples_in_superblock = this->superblock_bytes / (2 * sizeof(usint));
  }
  else
  {
    this->buffer = new WriteBuffer(this->array, BYTES_TO_WORDS(this->superblock_bytes));
    this->blocks = this->current_blocks = 1;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movl $0x0, (%rdi)
movl $0x0, 0x4(%rdi)
movl $0x0, 0x8(%rdi)
movl -0xc(%rbp), %eax
addq $0x3, %rax
shrq $0x2, %rax
movl %eax, 0xc(%rdi)
movl -0x10(%rbp), %eax
movl %eax, 0x10(%rdi)
movb -0x11(%rbp), %al
andb $0x1, %al
movb %al, 0x14(%rdi)
addq $0x20, %rdi
movq %rdi, -0x48(%rbp)
callq 0x1d6f0
movq -0x38(%rbp), %rdi
movl $0x1, 0x40(%rdi)
movl $0x0, 0x44(%rdi)
addq $0x48, %rdi
movq %rdi, -0x40(%rbp)
callq 0x1d6f0
movq -0x38(%rbp), %rax
movq $0x0, 0x60(%rax)
movl $0x0, 0x68(%rax)
movl $0x0, 0x6c(%rax)
movl 0x10(%rax), %eax
andl $-0x4, %eax
movl %eax, %edi
callq 0x3030
movq %rax, -0x30(%rbp)
jmp 0x1fa3a
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq 0x38(%rax), %rdi
movl 0x10(%rax), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x3190
movq -0x38(%rbp), %rax
testb $0x1, 0x14(%rax)
je 0x1fb0e
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
movl 0x10(%rax), %eax
shlq $0x2, %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x38(%rbp), %rax
movl %ecx, 0x40(%rax)
movl $0x28, %edi
callq 0x32c0
movq %rax, -0x50(%rbp)
jmp 0x1fa91
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rsi
movl 0xc(%rax), %edx
callq 0x1e4c0
jmp 0x1faa7
movq -0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, 0x18(%rax)
movl 0x10(%rax), %eax
andl $-0x4, %eax
movl %eax, %edi
callq 0x3030
movq %rax, -0x58(%rbp)
jmp 0x1fac6
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x60(%rax)
movl 0x10(%rax), %ecx
shrq $0x3, %rcx
movl %ecx, 0x68(%rax)
jmp 0x1fb76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1fb7c
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x32d0
jmp 0x1fb7c
movl $0x28, %edi
callq 0x32c0
movq %rax, -0x60(%rbp)
jmp 0x1fb1e
movq -0x60(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rsi
movl 0x10(%rax), %eax
addq $0x3, %rax
shrq $0x2, %rax
movl %eax, %edx
callq 0x1e4c0
jmp 0x1fb3e
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, 0x18(%rax)
movl $0x1, 0x44(%rax)
movl $0x1, 0x8(%rax)
jmp 0x1fb76
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x32d0
jmp 0x1fb7c
addq $0x60, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x1d710
movq -0x48(%rbp), %rdi
callq 0x1d710
movq -0x20(%rbp), %rdi
callq 0x3530
nopw (%rax,%rax)