// File: /workspace/github_c_makefile_star2_O2/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 0x1aea(%rip), %rdi      # 0x4c58
pushq $0x1
popq %rsi
callq 0x2ac2
movq %rax, %rbx
leaq 0x1ae3(%rip), %rdi      # 0x4c63
xorl %eax, %eax
callq 0x10a0
movq %rbx, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x29de
testl %eax, %eax
leaq 0x1b49(%rip), %rax      # 0x4ce7
leaq 0x1b21(%rip), %rdi      # 0x4cc6
cmoveq %rax, %rdi
callq 0x1070
leaq 0x1b58(%rip), %rdi      # 0x4d0d
callq 0x1070
movl $0xf4240, %r13d         # imm = 0xF4240
xorl %r14d, %r14d
cmpq $0xf4240, %r14          # imm = 0xF4240
je 0x322d
xorl %eax, %eax
callq 0x26cc
movq %rax, %rbx
callq 0x11b0
cltd
idivl %r13d
movl %edx, %ebp
movslq %edx, %r15
xorl %r12d, %r12d
cmpq $0x64, %r12
je 0x3200
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x26db
incq %r12
jmp 0x31e7
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2966
addl $0xfffffc18, %ebp       # imm = 0xFFFFFC18
cmpl $0xa, %ebp
ja 0x3228
leaq 0x1a62(%rip), %rdi      # 0x4c80
movq %r15, %rsi
xorl %eax, %eax
callq 0x10a0
incq %r14
jmp 0x31c3
leaq 0x1b19(%rip), %rdi      # 0x4d4d
callq 0x1070
pushq $0x64
popq %r8
movl $0x3e8, %edx            # imm = 0x3E8
movl $0x3f2, %ecx            # imm = 0x3F2
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x27a4
movq %rax, %r14
movq %rax, %rdi
callq 0x26e0
movq %rax, %r15
leaq 0x1050(%rip), %r13      # 0x42b7
xorl %ebx, %ebx
cmpq %r15, %rbx
je 0x32bf
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26e4
movq %rax, %r12
leaq 0x1a23(%rip), %rdi      # 0x4ca6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
xorl %ebp, %ebp
cmpq $0xa, %rbp
je 0x32b2
movq %r12, %rdi
movq %rbp, %rsi
callq 0x26d6
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x10a0
incq %rbp
jmp 0x328f
pushq $0xa
popq %rdi
callq 0x1040
incq %rbx
jmp 0x3269
movq %r14, %rdi
callq 0x2712
leaq 0x1ac5(%rip), %rdi      # 0x4d93
callq 0x1070
movq (%rsp), %rdi
callq 0x2f47
leaq 0x1ac9(%rip), %rdi      # 0x4dac
callq 0x1070
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq