// File: /workspace/github_c_makefile_star2_O0/CkTD[P]btree/table_test3.c
// Function: main
int main(int argc, char* argv [])
{
    TableOpenFlag   flag;
    Table          *table;
    TableRows      *rows;
    TableRow       *row;
    uint64_t        i,j,n, count;
    (void)count; 
    clock_t time;
    const char* dir = argv[1];
    int index = *argv[2] == 'Y' ? 1: 0;
    int insert  = atoi(argv[3]);
    int search = atoi(argv[4]);

    flag.dir = dir;
    flag.create_if_missing = 1;
    flag.error_if_exist = 0;

    table = table_open(flag);
    
    if(index)
    {
        printf("在第0列上建立索引...");
        if( table_create_index(table, 0) == 0)
        {
            printf("create index on column 0 successfully\n");
        }
        else
        {
            printf("index on column 0 already exist!\n");
        }
    }


    printf("插入 %d 行随机数据，每一行所有属性相同...\n", insert);
    time = clock();
    for(i = 0; i < insert; i++)
    {
        row = table_row_new();
        n = rand() % insert;
        for(j=0;j<100;j++)
            table_row_set_property(row, j, n );
        table_append(table, row);
    }
    printf("插入用时 %f", (float)(clock()- time)/ CLOCKS_PER_SEC);

    printf("查表%d此\n", search);
    time = clock();
    for(i=0;i<search;i++)
    {
    n = rand() % insert;
    rows = table_search_range(table, 0, n-10 , n, 100);
    count = table_rows_get_counts(rows);
    //printf(".");
    table_rows_destory(rows);
    }
    printf("查找用时 %f", (float)(clock()- time)/ CLOCKS_PER_SEC);

    printf("关闭表(刷磁盘)....\n");
    table_close(table);
    printf("done\n");
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x59, %edx
cmovel %ecx, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1160
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1160
movl %eax, -0x74(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x1, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4620
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x52ed
leaq 0x19e4(%rip), %rdi      # 0x6c98
movb $0x0, %al
callq 0x1090
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4470
cmpl $0x0, %eax
jne 0x52dd
leaq 0x19e1(%rip), %rdi      # 0x6cb5
movb $0x0, %al
callq 0x1090
jmp 0x52eb
leaq 0x19f8(%rip), %rdi      # 0x6cdc
movb $0x0, %al
callq 0x1090
jmp 0x52ed
movl -0x70(%rbp), %esi
leaq 0x1a07(%rip), %rdi      # 0x6cfe
movb $0x0, %al
callq 0x1090
callq 0x1070
movq %rax, -0x60(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq -0x70(%rbp), %rcx
cmpq %rcx, %rax
jae 0x5380
movb $0x0, %al
callq 0x3e10
movq %rax, -0x38(%rbp)
callq 0x11a0
cltd
idivl -0x70(%rbp)
movslq %edx, %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
cmpq $0x64, -0x48(%rbp)
jae 0x5365
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x3e50
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x533f
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4360
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x530f
callq 0x1070
subq -0x60(%rbp), %rax
cvtsi2ss %rax, %xmm0
movss 0x18fe(%rip), %xmm1     # 0x6c94
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1995(%rip), %rdi      # 0x6d3a
movb $0x1, %al
callq 0x1090
movl -0x74(%rbp), %esi
leaq 0x1994(%rip), %rdi      # 0x6d4a
movb $0x0, %al
callq 0x1090
callq 0x1070
movq %rax, -0x60(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq -0x74(%rbp), %rcx
cmpq %rcx, %rax
jae 0x5432
callq 0x11a0
cltd
idivl -0x70(%rbp)
movslq %edx, %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rdx
subq $0xa, %rdx
movq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
movl $0x64, %r8d
callq 0x4000
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3e80
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3f00
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x53ce
callq 0x1070
subq -0x60(%rbp), %rax
cvtsi2ss %rax, %xmm0
movss 0x184c(%rip), %xmm1     # 0x6c94
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1900(%rip), %rdi      # 0x6d57
movb $0x1, %al
callq 0x1090
leaq 0x1902(%rip), %rdi      # 0x6d67
movb $0x0, %al
callq 0x1090
movq -0x28(%rbp), %rdi
callq 0x4b00
leaq 0x1905(%rip), %rdi      # 0x6d81
movb $0x0, %al
callq 0x1090
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq