// File: MITRECND[P]snugglefish/src/nGramIndex.cpp
// Function: snugglefish::nGramIndex::nGramIndex(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
nGramIndex::nGramIndex( uint32_t ngramLength, string indexFileName)
    :nGramBase(ngramLength, indexFileName), bufferMax(MAX_BUFFER_SIZE),
    buffer_memory_usage(0), flush(false), flushing(false) {


    this->maxFileNameLength = DEFAULT_MAX_FILENAME_SIZE;
    
	//allocate output buffer
	this->output_buffer = new buffer_element[maxNgram];
	for(uint64_t i = 0; i < maxNgram; i++){
		this->output_buffer[i].elements_size = 0;
		this->output_buffer[i].elements = new list<ngram_t_fidtype>;
	}

    masterFile = new smFile(baseFileName, ngramLength);

    if (masterFile->exists()){
        masterFile->open('w');
    }else{ //Must create it
        masterFile->create(maxFileNameLength);
    }

    numFilesProcessed = masterFile->getNumFiles();
    numSessionFilesProcessed = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdx, -0x98(%rbp)
movl %esi, %eax
movq -0x98(%rbp), %rsi
movq %rdi, -0x8(%rbp)
movl %eax, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0xe130
movq -0x90(%rbp), %rdi
movl -0x84(%rbp), %esi
movq -0x80(%rbp), %rdx
callq 0x12450
jmp 0x150df
leaq -0x38(%rbp), %rdi
callq 0xe1d0
movq -0x90(%rbp), %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x38(%rdi)
movq $0x0, 0x48(%rdi)
addq $0x50, %rdi
movq %rdi, -0xa8(%rbp)
callq 0x10350
movq -0x90(%rbp), %rax
movb $0x0, 0x68(%rax)
movb $0x0, 0x69(%rax)
movw $0x41, (%rax)
movq 0x30(%rax), %rax
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0xe030
movq %rax, -0xa0(%rbp)
jmp 0x15151
movq -0x90(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, 0x40(%rax)
movq $0x0, -0x50(%rbp)
movq -0x90(%rbp), %rcx
movq -0x50(%rbp), %rax
cmpq 0x30(%rcx), %rax
jae 0x15214
movq -0x90(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rcx
shlq $0x4, %rcx
movq $0x0, (%rax,%rcx)
movl $0x18, %edi
callq 0xe300
movq %rax, -0xb0(%rbp)
jmp 0x151ae
movq -0xb0(%rbp), %rdi
callq 0x13ae0
movq -0x90(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1516b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xe1d0
jmp 0x1535f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x15347
movl $0x58, %edi
callq 0xe300
movq %rax, -0xb8(%rbp)
jmp 0x15227
movq -0x90(%rbp), %rsi
movb $0x1, -0x71(%rbp)
addq $0x8, %rsi
leaq -0x70(%rbp), %rdi
callq 0xe130
jmp 0x15241
movq -0xb8(%rbp), %rdi
movzbl -0xc(%rbp), %edx
leaq -0x70(%rbp), %rsi
callq 0x19250
jmp 0x15257
movq -0x90(%rbp), %rax
movq -0xb8(%rbp), %rcx
movb $0x0, -0x71(%rbp)
movq %rcx, 0x70(%rax)
leaq -0x70(%rbp), %rdi
callq 0xe1d0
movq -0x90(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x18650
movb %al, -0xb9(%rbp)
jmp 0x1528e
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x1529a
jmp 0x152f1
movq -0x90(%rbp), %rax
movq 0x70(%rax), %rdi
movl $0x77, %esi
callq 0x19500
jmp 0x152b1
jmp 0x15308
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x152d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xe1d0
testb $0x1, -0x71(%rbp)
jne 0x152de
jmp 0x152ef
movq -0xb8(%rbp), %rdi
movl $0x58, %esi
callq 0xe310
jmp 0x15347
movq -0x90(%rbp), %rax
movq 0x70(%rax), %rdi
movzwl (%rax), %esi
callq 0x19350
jmp 0x15306
jmp 0x15308
movq -0x90(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x136b0
movl %eax, -0xc0(%rbp)
jmp 0x15320
movq -0x90(%rbp), %rax
movl -0xc0(%rbp), %ecx
movl %ecx, %ecx
movq %rcx, 0x78(%rax)
movq $0x0, 0x80(%rax)
addq $0xc0, %rsp
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x10540
movq -0x90(%rbp), %rdi
callq 0x136d0
movq -0x40(%rbp), %rdi
callq 0xe5d0
nopl (%rax,%rax)