// File: /workspace/github_c_makefile_star2_O3/CkTD[P]btree/table_test2.c
// Function: main
int main()
{
    TableOpenFlag   flag;
    Table          *table;
    TableRows      *rows;
    TableRow       *row;
    uint64_t        i,j,n,count;
    

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

    table = table_open(flag);
    
    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("插入 1000000 行随机数据，每一行所有属性相同...\n");
    for(i = 0; i < 1000000; i++)
    {
        row = table_row_new();
        n = rand() % 1000000;
        for(j=0;j<100;j++)
            table_row_set_property(row, j, n );
        table_append(table, row);
        if (n<=1010 && n >=1000)
            printf("\t插入一个属性都为 %ld 的行\n", n);
    }

    printf("查找 第0个属性的范围在 1000 到 10010 的行，limit = 100.\n");
    rows = table_search_range(table, 0, 1000, 1010, 100);
    count = table_rows_get_counts(rows);
    for(i = 0; i < count; i++)
    {
        row = table_rows_get_row(rows, i);
        printf("\tROW %lu, first 10 properties: ", i);
        for(j = 0; j < 10; j++)
        {
            printf("%lu ", table_row_get_property(row, j));
        }
        printf("\n");
    }
    table_rows_destory(rows);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x186e(%rip), %rdi      # 0x4c58
movl $0x1, %esi
callq 0x2cb1
movq %rax, %rbx
leaq 0x1865(%rip), %rdi      # 0x4c63
xorl %eax, %eax
callq 0x10a0
movq %rbx, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2ba3
testl %eax, %eax
leaq 0x18cb(%rip), %rax      # 0x4ce7
leaq 0x18a3(%rip), %rdi      # 0x4cc6
cmoveq %rax, %rdi
callq 0x1070
leaq 0x18da(%rip), %rdi      # 0x4d0d
callq 0x1070
leaq 0x1841(%rip), %r14      # 0x4c80
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x27d0
movq %rax, %r15
callq 0x11b0
movslq %eax, %rbp
imulq $0x431bde83, %rbp, %rax # imm = 0x431BDE83
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x32, %rax
addl %ecx, %eax
imull $0xf4240, %eax, %eax    # imm = 0xF4240
subl %eax, %ebp
movslq %ebp, %r12
xorl %ebx, %ebx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x27df
incq %rbx
cmpq $0x64, %rbx
jne 0x3475
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2b11
addl $0xfffffc18, %ebp       # imm = 0xFFFFFC18
cmpl $0xa, %ebp
ja 0x34b0
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x10a0
incq %r13
cmpq $0xf4240, %r13          # imm = 0xF4240
jne 0x3442
leaq 0x188a(%rip), %rdi      # 0x4d4d
callq 0x1070
movl $0x3e8, %edx            # imm = 0x3E8
movl $0x3f2, %ecx            # imm = 0x3F2
movl $0x64, %r8d
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x287d
movq %rax, %r14
movq %rax, %rdi
callq 0x27e4
testq %rax, %rax
je 0x3553
movq %rax, %r15
leaq 0xdba(%rip), %r13       # 0x42b7
xorl %ebp, %ebp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x27e8
movq %rax, %r12
leaq 0x1792(%rip), %rdi      # 0x4ca6
movq %rbp, %rsi
xorl %eax, %eax
callq 0x10a0
xorl %ebx, %ebx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x27da
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x10a0
incq %rbx
cmpq $0xa, %rbx
jne 0x3520
movl $0xa, %edi
callq 0x1040
incq %rbp
cmpq %r15, %rbp
jne 0x34ff
movq %r14, %rdi
callq 0x2816
leaq 0x1831(%rip), %rdi      # 0x4d93
callq 0x1070
movq (%rsp), %rdi
callq 0x31df
leaq 0x1835(%rip), %rdi      # 0x4dac
callq 0x1070
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq