// File: dvjdjvu[P]bntree/./src/test.cpp
// Function: main
int main()
{
    uint64_t progress = 0;
    uint64_t percent = 0;
    time_point<system_clock> time;
    nanoseconds total_time(0);
    
    write_sequence write =  get_sequence<write_sequence>("./test/write.txt");
    modify_sequence modify =  get_sequence<modify_sequence>("./test/modify.txt");
    read_sequence read = get_sequence<read_sequence>("./test/read.txt");

    bntree st;
    //cout << "count: " << write.size() << endl;
    
    progress = 0;
    percent = write.size() / 100;
    
    for (const string &item : write)
    {
        time = system_clock::now();
        total_time += system_clock::now() - time;
        
        st.insert(item);
        
        if (++progress % (10 * percent) == 0)
        {
            cout << "time: " << duration_cast<milliseconds>(total_time).count()
                 << "ms progress: " << progress << " / " << write.size() << "\n";
        }
    }
    
    cout << "insert have done" << endl;
    
    cout << "\ncount: " << st.size() << " add end" << endl;
    //st.print();
    //return -1;
    
    progress = 0;
    percent = modify.size() / 100;

    modify_sequence::const_iterator mitr = modify.begin();
    read_sequence::const_iterator ritr = read.begin();
    
    for (int i = 0; mitr != modify.end() && ritr != read.end(); ++mitr, ++ritr, i++)
    {
        time = system_clock::now();

        st.erase(mitr->first);
        st.insert(mitr->second);
        
        data_t *d = st.get(ritr->first);
        
        total_time += system_clock::now() - time;
        if (ritr->second != d->key)
        {
            cout << "test failed " << i << endl;
            return 1;
        }

        if (++progress % (10 * percent) == 0)
        {
            cout << "time: " << duration_cast<milliseconds>(total_time).count()
                 << "ms progress: " << progress << " / " << modify.size() << "\n";
        }
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movl $0x0, -0x4(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4520
movq $0x0, -0x28(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x2270
movq -0x240(%rbp), %rdx
leaq 0x34e0(%rip), %rsi      # 0x7011
leaq -0x60(%rbp), %rdi
callq 0x2200
jmp 0x3b3c
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4550
jmp 0x3b4b
leaq -0x60(%rbp), %rdi
callq 0x2100
leaq -0x61(%rbp), %rdi
callq 0x21a0
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x2270
movq -0x248(%rbp), %rdx
leaq 0x34a4(%rip), %rsi      # 0x7022
leaq -0xb0(%rbp), %rdi
callq 0x2200
jmp 0x3b8c
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4690
jmp 0x3ba1
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xb1(%rbp), %rdi
callq 0x21a0
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x2270
movq -0x250(%rbp), %rdx
leaq 0x345a(%rip), %rsi      # 0x7034
leaq -0xf0(%rbp), %rdi
callq 0x2200
jmp 0x3be8
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x4690
jmp 0x3bfd
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xf1(%rbp), %rdi
callq 0x21a0
leaq -0x100(%rbp), %rdi
callq 0x2420
jmp 0x3c23
movq $0x0, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x47f0
movl $0x64, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x18(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
callq 0x4810
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
callq 0x4840
movq %rax, -0x118(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x4870
testb $0x1, %al
jne 0x3c8f
jmp 0x3fb2
leaq -0x110(%rbp), %rdi
callq 0x48b0
movq %rax, -0x120(%rbp)
callq 0x2050
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x20(%rbp)
callq 0x2050
movq %rax, -0x138(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x48d0
movq %rax, -0x258(%rbp)
jmp 0x3cde
movq -0x258(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x4920
jmp 0x3cfe
movq -0x120(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x20b0
jmp 0x3d13
leaq -0x179(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x2270
movq -0x260(%rbp), %rdx
leaq 0x32d3(%rip), %rsi      # 0x7007
leaq -0x178(%rbp), %rdi
callq 0x2200
jmp 0x3d42
leaq -0x100(%rbp), %rdi
leaq -0x158(%rbp), %rsi
leaq -0x178(%rbp), %rdx
callq 0x2730
jmp 0x3d5e
leaq -0x178(%rbp), %rdi
callq 0x2100
leaq -0x179(%rbp), %rdi
callq 0x21a0
leaq -0x158(%rbp), %rdi
callq 0x2100
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
imulq $0xa, -0x18(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x3f9f
movq 0x622f(%rip), %rdi      # 0x9fd8
leaq 0x3294(%rip), %rsi      # 0x7044
callq 0x2170
movq %rax, -0x268(%rbp)
jmp 0x3dbe
leaq -0x28(%rbp), %rdi
callq 0x4960
movq %rax, -0x270(%rbp)
jmp 0x3dd0
movq -0x270(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4990
movq %rax, -0x278(%rbp)
jmp 0x3df3
movq -0x278(%rbp), %rsi
movq -0x268(%rbp), %rdi
callq 0x2280
movq %rax, -0x280(%rbp)
jmp 0x3e0f
movq -0x280(%rbp), %rdi
leaq 0x322e(%rip), %rsi      # 0x704b
callq 0x2170
movq %rax, -0x288(%rbp)
jmp 0x3e2b
movq -0x288(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2060
movq %rax, -0x290(%rbp)
jmp 0x3e44
movq -0x290(%rbp), %rdi
leaq 0x3207(%rip), %rsi      # 0x7059
callq 0x2170
movq %rax, -0x298(%rbp)
jmp 0x3e60
leaq -0x40(%rbp), %rdi
callq 0x47f0
movq -0x298(%rbp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, -0x2a0(%rbp)
jmp 0x3e81
movq -0x2a0(%rbp), %rdi
leaq 0x3177(%rip), %rsi      # 0x7006
callq 0x2170
jmp 0x3e96
jmp 0x3f9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3ebe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2100
leaq -0x61(%rbp), %rdi
callq 0x21a0
jmp 0x4511
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3ef2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xb1(%rbp), %rdi
callq 0x21a0
jmp 0x4508
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3f29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xf1(%rbp), %rdi
callq 0x21a0
jmp 0x44fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x44e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3f82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2100
leaq -0x179(%rbp), %rdi
callq 0x21a0
leaq -0x158(%rbp), %rdi
callq 0x2100
jmp 0x44e4
jmp 0x3fa1
leaq -0x110(%rbp), %rdi
callq 0x49b0
jmp 0x3c73
movq 0x601f(%rip), %rdi      # 0x9fd8
leaq 0x309d(%rip), %rsi      # 0x705d
callq 0x2170
movq %rax, -0x2a8(%rbp)
jmp 0x3fce
movq -0x2a8(%rbp), %rdi
movq 0x5fec(%rip), %rsi      # 0x9fc8
callq 0x2190
jmp 0x3fe3
movq 0x5fee(%rip), %rdi      # 0x9fd8
leaq 0x307d(%rip), %rsi      # 0x706e
callq 0x2170
movq %rax, -0x2b0(%rbp)
jmp 0x3fff
leaq -0x100(%rbp), %rdi
callq 0x30c0
movq %rax, -0x2b8(%rbp)
jmp 0x4014
movq -0x2b8(%rbp), %rsi
movq -0x2b0(%rbp), %rdi
callq 0x2060
movq %rax, -0x2c0(%rbp)
jmp 0x4030
movq -0x2c0(%rbp), %rdi
leaq 0x3039(%rip), %rsi      # 0x7077
callq 0x2170
movq %rax, -0x2c8(%rbp)
jmp 0x404c
movq -0x2c8(%rbp), %rdi
movq 0x5f6e(%rip), %rsi      # 0x9fc8
callq 0x2190
jmp 0x4061
movq $0x0, -0x10(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x49d0
movl $0x64, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x18(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4a00
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x4a30
leaq -0xd0(%rbp), %rdi
callq 0x4a00
movq %rax, -0x1a8(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x4a30
movl $0x0, -0x1ac(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4ab0
movq %rax, -0x1b8(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x4a70
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x2c9(%rbp)
jne 0x4110
jmp 0x413c
leaq -0xd0(%rbp), %rdi
callq 0x4ab0
movq %rax, -0x1c0(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x4a70
movb %al, -0x2c9(%rbp)
movb -0x2c9(%rbp), %al
testb $0x1, %al
jne 0x414b
jmp 0x449a
callq 0x2050
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x4ae0
movq (%rax), %rsi
leaq -0x100(%rbp), %rdi
callq 0x2e80
jmp 0x417f
leaq -0x190(%rbp), %rdi
callq 0x4ae0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x1e8(%rbp), %rdi
callq 0x20b0
jmp 0x41a0
leaq -0x209(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x2270
movq -0x2d8(%rbp), %rdx
leaq 0x2e46(%rip), %rsi      # 0x7007
leaq -0x208(%rbp), %rdi
callq 0x2200
jmp 0x41cf
leaq -0x100(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
leaq -0x208(%rbp), %rdx
callq 0x2730
jmp 0x41eb
leaq -0x208(%rbp), %rdi
callq 0x2100
leaq -0x209(%rbp), %rdi
callq 0x21a0
leaq -0x1e8(%rbp), %rdi
callq 0x2100
leaq -0x1a0(%rbp), %rdi
callq 0x4ae0
movq (%rax), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3320
movq %rax, -0x2e0(%rbp)
jmp 0x4233
movq -0x2e0(%rbp), %rax
movq %rax, -0x218(%rbp)
callq 0x2050
movq %rax, -0x228(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x48d0
movq %rax, -0x2e8(%rbp)
jmp 0x4266
movq -0x2e8(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x4920
jmp 0x4286
leaq -0x1a0(%rbp), %rdi
callq 0x4ae0
movq %rax, %rdi
addq $0x8, %rdi
movq -0x218(%rbp), %rsi
callq 0x4b00
testb $0x1, %al
jne 0x42ae
jmp 0x4353
movq 0x5d23(%rip), %rdi      # 0x9fd8
leaq 0x2dc4(%rip), %rsi      # 0x7080
callq 0x2170
movq %rax, -0x2f0(%rbp)
jmp 0x42ca
movq -0x2f0(%rbp), %rdi
movl -0x1ac(%rbp), %esi
callq 0x2250
movq %rax, -0x2f8(%rbp)
jmp 0x42e5
movq -0x2f8(%rbp), %rdi
movq 0x5cd5(%rip), %rsi      # 0x9fc8
callq 0x2190
jmp 0x42fa
movl $0x1, -0x4(%rbp)
movl $0x1, -0x22c(%rbp)
jmp 0x44ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4336
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x2100
leaq -0x209(%rbp), %rdi
callq 0x21a0
leaq -0x1e8(%rbp), %rdi
callq 0x2100
jmp 0x44e4
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
imulq $0xa, -0x18(%rbp), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x446c
movq 0x5c5e(%rip), %rdi      # 0x9fd8
leaq 0x2cc3(%rip), %rsi      # 0x7044
callq 0x2170
movq %rax, -0x300(%rbp)
jmp 0x438f
leaq -0x28(%rbp), %rdi
callq 0x4960
movq %rax, -0x308(%rbp)
jmp 0x43a1
movq -0x308(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x4990
movq %rax, -0x310(%rbp)
jmp 0x43c4
movq -0x310(%rbp), %rsi
movq -0x300(%rbp), %rdi
callq 0x2280
movq %rax, -0x318(%rbp)
jmp 0x43e0
movq -0x318(%rbp), %rdi
leaq 0x2c5d(%rip), %rsi      # 0x704b
callq 0x2170
movq %rax, -0x320(%rbp)
jmp 0x43fc
movq -0x320(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2060
movq %rax, -0x328(%rbp)
jmp 0x4415
movq -0x328(%rbp), %rdi
leaq 0x2c36(%rip), %rsi      # 0x7059
callq 0x2170
movq %rax, -0x330(%rbp)
jmp 0x4431
leaq -0x90(%rbp), %rdi
callq 0x49d0
movq -0x330(%rbp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, -0x338(%rbp)
jmp 0x4455
movq -0x338(%rbp), %rdi
leaq 0x2ba3(%rip), %rsi      # 0x7006
callq 0x2170
jmp 0x446a
jmp 0x446c
jmp 0x446e
leaq -0x190(%rbp), %rdi
callq 0x4b30
leaq -0x1a0(%rbp), %rdi
callq 0x4b30
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x40d9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x22c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x2470
leaq -0xd0(%rbp), %rdi
callq 0x4b50
leaq -0x90(%rbp), %rdi
callq 0x4b50
leaq -0x40(%rbp), %rdi
callq 0x4bb0
movl -0x4(%rbp), %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x100(%rbp), %rdi
callq 0x2470
leaq -0xd0(%rbp), %rdi
callq 0x4b50
leaq -0x90(%rbp), %rdi
callq 0x4b50
leaq -0x40(%rbp), %rdi
callq 0x4bb0
movq -0x70(%rbp), %rdi
callq 0x2260
nopw (%rax,%rax)