// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %rax
movb (%rax), %r15b
movq 0x18(%rsi), %rdi
callq 0x1190
movl %eax, 0x8(%rsp)
movq 0x20(%rbx), %rdi
callq 0x1190
movl %eax, 0xc(%rsp)
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x2ae2
movq %rax, %rbp
cmpb $0x59, %r15b
jne 0x31f7
leaq 0x1a8f(%rip), %rdi      # 0x4c5c
xorl %eax, %eax
callq 0x10b0
movq %rbp, %rdi
xorl %esi, %esi
callq 0x29fe
testl %eax, %eax
leaq 0x1b1c(%rip), %rax      # 0x4d03
leaq 0x1af4(%rip), %rdi      # 0x4ce2
cmoveq %rax, %rdi
callq 0x1070
leaq 0x1a7b(%rip), %rdi      # 0x4c79
movl 0x8(%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x10b0
callq 0x1090
movq %rax, 0x10(%rsp)
movslq %ebx, %r15
xorl %ebx, %ebx
cmpq %r15, %rbx
je 0x3262
xorl %eax, %eax
callq 0x26ec
movq %rax, %r12
callq 0x11d0
cltd
idivl 0x8(%rsp)
movslq %edx, %r13
xorl %r14d, %r14d
cmpq $0x64, %r14
je 0x3252
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x26fb
incq %r14
jmp 0x3239
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2986
incq %rbx
jmp 0x321a
callq 0x1090
subq 0x10(%rsp), %rax
cvtsi2ss %rax, %xmm0
divss 0x19df(%rip), %xmm0     # 0x4c58
cvtss2sd %xmm0, %xmm0
leaq 0x1a31(%rip), %rdi      # 0x4cb5
movb $0x1, %al
callq 0x10b0
leaq 0x1a33(%rip), %rdi      # 0x4cc5
movl 0xc(%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x10b0
callq 0x1090
movq %rax, %r15
movslq %ebx, %rbx
pushq $0x64
popq %r14
subq $0x1, %rbx
jb 0x32e7
callq 0x11d0
cltd
idivl 0x8(%rsp)
movslq %edx, %rcx
leaq -0xa(%rcx), %rdx
movq %rbp, %rdi
xorl %esi, %esi
movq %r14, %r8
callq 0x27c4
movq %rax, %r12
movq %rax, %rdi
callq 0x2700
movq %r12, %rdi
callq 0x2732
jmp 0x32ae
callq 0x1090
subq %r15, %rax
cvtsi2ss %rax, %xmm0
divss 0x195c(%rip), %xmm0     # 0x4c58
cvtss2sd %xmm0, %xmm0
leaq 0x19cb(%rip), %rdi      # 0x4cd2
movb $0x1, %al
callq 0x10b0
leaq 0x1a14(%rip), %rdi      # 0x4d29
callq 0x1070
movq %rbp, %rdi
callq 0x2f67
leaq 0x1a19(%rip), %rdi      # 0x4d42
callq 0x1070
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq