// File: /workspace/github_c_makefile_star2_O1/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 0x1180
movl %eax, %ebp
movq 0x20(%rbx), %rdi
callq 0x1180
movl %eax, 0xc(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x2c67
movq %rax, %r13
cmpb $0x59, %r15b
jne 0x33f3
leaq 0x1893(%rip), %rdi      # 0x4c5c
xorl %eax, %eax
callq 0x10b0
movq %r13, %rdi
xorl %esi, %esi
callq 0x2b59
testl %eax, %eax
leaq 0x1920(%rip), %rax      # 0x4d03
leaq 0x18f8(%rip), %rdi      # 0x4ce2
cmoveq %rax, %rdi
callq 0x1070
leaq 0x187f(%rip), %rdi      # 0x4c79
movl %ebp, %esi
xorl %eax, %eax
callq 0x10b0
callq 0x1090
movq %rax, 0x10(%rsp)
movl %ebp, 0x8(%rsp)
testl %ebp, %ebp
je 0x3466
movslq 0x8(%rsp), %r15
xorl %ebx, %ebx
movq %r13, %rbp
xorl %eax, %eax
callq 0x27a4
movq %rax, %r12
callq 0x11c0
cltd
idivl 0x8(%rsp)
movslq %edx, %r13
xorl %r14d, %r14d
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x27b3
incq %r14
cmpq $0x64, %r14
jne 0x3439
movq %rbp, %r13
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2ac7
incq %rbx
cmpq %r15, %rbx
jne 0x341c
callq 0x1090
subq 0x10(%rsp), %rax
cvtsi2ss %rax, %xmm0
divss 0x17db(%rip), %xmm0     # 0x4c58
cvtss2sd %xmm0, %xmm0
leaq 0x182d(%rip), %rdi      # 0x4cb5
movb $0x1, %al
callq 0x10b0
leaq 0x182f(%rip), %rdi      # 0x4cc5
movl 0xc(%rsp), %ebx
movl %ebx, %esi
xorl %eax, %eax
callq 0x10b0
callq 0x1090
movq %rax, %r15
testl %ebx, %ebx
movl 0x8(%rsp), %ebp
je 0x34ed
movslq %ebx, %rbx
callq 0x11c0
cltd
idivl %ebp
movslq %edx, %rcx
leaq -0xa(%rcx), %rdx
movl $0x64, %r8d
movq %r13, %rdi
xorl %esi, %esi
callq 0x2851
movq %rax, %r14
movq %rax, %rdi
callq 0x27b8
movq %r14, %rdi
callq 0x27ea
decq %rbx
jne 0x34b6
callq 0x1090
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
divss 0x1753(%rip), %xmm0     # 0x4c58
cvtss2sd %xmm0, %xmm0
leaq 0x17c2(%rip), %rdi      # 0x4cd2
movb $0x1, %al
callq 0x10b0
leaq 0x180b(%rip), %rdi      # 0x4d29
callq 0x1070
movq %r13, %rdi
callq 0x3172
leaq 0x1810(%rip), %rdi      # 0x4d42
callq 0x1070
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq