// File: helayzhang[P]sorted_set/example.cc
// Function: main
int main()
{
    unsigned long rank;
    double score;
    SortedSet<int> sortedSet;
    sortedSet.zadd(300001, 300);
    sortedSet.zadd(300002, 299.9);
    sortedSet.zadd(300003, 100000);

    std::vector< std::pair<int, double> > result;

    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    sortedSet.zadd(300004, 40);
    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    sortedSet.zadd(300005, 40);
    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    std::cout << sortedSet.zcount(40, 300, true, true) << std::endl;
    std::cout << std::endl;

    sortedSet.zrem(300005);
    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    sortedSet.zincrby(300004, 500);
    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    if (sortedSet.zscore(300003, score))
        std::cout << score << std::endl;
    else 
        std::cout << "nil" << std::endl;
    std::cout << std::endl;

    if (sortedSet.zrank(300002, rank)) 
        std::cout << rank << std::endl;
    else 
        std::cout << "nil" << std::endl;
    if (sortedSet.zrevrank(300002, rank)) 
        std::cout << rank << std::endl;
    else 
        std::cout << "nil" << std::endl;
    std::cout << std::endl;

    sortedSet.zrevrange_withscores(0, 1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    sortedSet.zrangebyscore_withscores(300, 1000, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    sortedSet.zremrangebyrank(1, 2);
    sortedSet.zrange_withscores(0, -1, result);
    std::for_each(result.begin(), result.end(), echo_ranking);
    std::cout << std::endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl $0x0, -0x4(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x1ab0
movq -0x118(%rbp), %rdi
movl $0x493e1, %esi          # imm = 0x493E1
movsd 0x5c92(%rip), %xmm0     # 0x7008
callq 0x1ba0
jmp 0x137d
leaq -0x68(%rbp), %rdi
movl $0x493e2, %esi          # imm = 0x493E2
movsd 0x5c82(%rip), %xmm0     # 0x7010
callq 0x1ba0
jmp 0x1395
leaq -0x68(%rbp), %rdi
movl $0x493e3, %esi          # imm = 0x493E3
movsd 0x5c72(%rip), %xmm0     # 0x7018
callq 0x1ba0
jmp 0x13ad
leaq -0x90(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x1bd0
movq -0x120(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
callq 0x1bf0
jmp 0x13dd
leaq -0x90(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x1c90
movq -0x128(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x1cc0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
leaq -0x14f(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x1426
movq 0x9ba3(%rip), %rdi      # 0xafd0
movq 0x9b8c(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x143b
leaq -0x68(%rbp), %rdi
movl $0x493e4, %esi          # imm = 0x493E4
movsd 0x5bd4(%rip), %xmm0     # 0x7020
callq 0x1ba0
jmp 0x1453
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
leaq -0x90(%rbp), %rcx
callq 0x1bf0
jmp 0x1470
leaq -0x90(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x1c90
movq -0x130(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x1cc0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
leaq -0x1e2(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x14b9
movq 0x9b10(%rip), %rdi      # 0xafd0
movq 0x9af9(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x14ce
leaq -0x68(%rbp), %rdi
movl $0x493e5, %esi          # imm = 0x493E5
movsd 0x5b41(%rip), %xmm0     # 0x7020
callq 0x1ba0
jmp 0x14e6
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
leaq -0x90(%rbp), %rcx
callq 0x1bf0
jmp 0x1503
leaq -0x90(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x1c90
movq -0x138(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x1cc0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
leaq -0x275(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x154c
movq 0x9a7d(%rip), %rdi      # 0xafd0
movq 0x9a66(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x1561
leaq -0x68(%rbp), %rdi
movsd 0x5ab3(%rip), %xmm0     # 0x7020
movsd 0x5a93(%rip), %xmm1     # 0x7008
movl $0x1, %edx
movl %edx, %esi
callq 0x1cf0
movq %rax, -0x140(%rbp)
jmp 0x158a
movq -0x140(%rbp), %rsi
movq 0x9a38(%rip), %rdi      # 0xafd0
callq 0x1050
movq %rax, -0x148(%rbp)
jmp 0x15a6
movq -0x148(%rbp), %rdi
movq 0x9a0c(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x15bb
movq 0x9a0e(%rip), %rdi      # 0xafd0
movq 0x99f7(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x15d0
leaq -0x68(%rbp), %rdi
movl $0x493e5, %esi          # imm = 0x493E5
callq 0x1e00
jmp 0x15e0
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
leaq -0x90(%rbp), %rcx
callq 0x1bf0
jmp 0x15fd
leaq -0x90(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x1c90
movq -0x150(%rbp), %rdi
movq %rax, -0xc8(%rbp)
callq 0x1cc0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
leaq -0x36f(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x1646
movq 0x9983(%rip), %rdi      # 0xafd0
movq 0x996c(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x165b
leaq -0x68(%rbp), %rdi
movl $0x493e4, %esi          # imm = 0x493E4
movsd 0x59bc(%rip), %xmm0     # 0x7028
callq 0x1eb0
jmp 0x1673
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
leaq -0x90(%rbp), %rcx
callq 0x1bf0
jmp 0x1690
leaq -0x90(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x1c90
movq -0x158(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0x1cc0
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq -0x402(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x16d9
movq 0x98f0(%rip), %rdi      # 0xafd0
movq 0x98d9(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x16ee
leaq -0x68(%rbp), %rdi
movl $0x493e3, %esi          # imm = 0x493E3
leaq -0x18(%rbp), %rdx
callq 0x1ee0
movb %al, -0x159(%rbp)
jmp 0x1708
movb -0x159(%rbp), %al
testb $0x1, %al
jne 0x1714
jmp 0x1773
movsd -0x18(%rbp), %xmm0
movq 0x98b0(%rip), %rdi      # 0xafd0
callq 0x1180
movq %rax, -0x168(%rbp)
jmp 0x172e
movq -0x168(%rbp), %rdi
movq 0x9884(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x1743
jmp 0x17a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2120
jmp 0x1a97
movq 0x9856(%rip), %rdi      # 0xafd0
leaq 0x58dd(%rip), %rsi      # 0x705e
callq 0x10f0
movq %rax, -0x170(%rbp)
jmp 0x178f
movq -0x170(%rbp), %rdi
movq 0x9823(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x17a4
jmp 0x17a6
movq 0x9823(%rip), %rdi      # 0xafd0
movq 0x980c(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x17bb
leaq -0x68(%rbp), %rdi
movl $0x493e2, %esi          # imm = 0x493E2
leaq -0x10(%rbp), %rdx
callq 0x1f70
movb %al, -0x171(%rbp)
jmp 0x17d5
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x17e1
jmp 0x1811
movq -0x10(%rbp), %rsi
movq 0x97e4(%rip), %rdi      # 0xafd0
callq 0x1050
movq %rax, -0x180(%rbp)
jmp 0x17fa
movq -0x180(%rbp), %rdi
movq 0x97b8(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x180f
jmp 0x1844
movq 0x97b8(%rip), %rdi      # 0xafd0
leaq 0x583f(%rip), %rsi      # 0x705e
callq 0x10f0
movq %rax, -0x188(%rbp)
jmp 0x182d
movq -0x188(%rbp), %rdi
movq 0x9785(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x1842
jmp 0x1844
leaq -0x68(%rbp), %rdi
movl $0x493e2, %esi          # imm = 0x493E2
leaq -0x10(%rbp), %rdx
callq 0x1fa0
movb %al, -0x189(%rbp)
jmp 0x185e
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x186a
jmp 0x189a
movq -0x10(%rbp), %rsi
movq 0x975b(%rip), %rdi      # 0xafd0
callq 0x1050
movq %rax, -0x198(%rbp)
jmp 0x1883
movq -0x198(%rbp), %rdi
movq 0x972f(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x1898
jmp 0x18cd
movq 0x972f(%rip), %rdi      # 0xafd0
leaq 0x57b6(%rip), %rsi      # 0x705e
callq 0x10f0
movq %rax, -0x1a0(%rbp)
jmp 0x18b6
movq -0x1a0(%rbp), %rdi
movq 0x96fc(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x18cb
jmp 0x18cd
movq 0x96fc(%rip), %rdi      # 0xafd0
movq 0x96e5(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x18e2
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movl $0x1, %edx
leaq -0x90(%rbp), %rcx
callq 0x1fd0
jmp 0x18fd
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x1c90
movq -0x1a8(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x1cc0
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
leaq -0x66f(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x1946
movq 0x9683(%rip), %rdi      # 0xafd0
movq 0x966c(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x195b
leaq -0x68(%rbp), %rdi
movsd 0x56a1(%rip), %xmm0     # 0x7008
movsd 0x56c1(%rip), %xmm1     # 0x7030
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x2010
jmp 0x1981
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x1c90
movq -0x1b0(%rbp), %rdi
movq %rax, -0xf8(%rbp)
callq 0x1cc0
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
leaq -0x6f3(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x19ca
movq 0x95ff(%rip), %rdi      # 0xafd0
movq 0x95e8(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x19df
leaq -0x68(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x2070
jmp 0x19f4
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
movq $-0x1, %rdx
leaq -0x90(%rbp), %rcx
callq 0x1bf0
jmp 0x1a11
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x1c90
movq -0x1b8(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0x1cc0
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
leaq -0x783(%rip), %rdx      # 0x12d0
callq 0x1c30
jmp 0x1a5a
movq 0x956f(%rip), %rdi      # 0xafd0
movq 0x9558(%rip), %rsi      # 0xafc0
callq 0x1110
jmp 0x1a6f
movl $0x0, -0x4(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2120
leaq -0x68(%rbp), %rdi
callq 0x2180
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x2180
movq -0x70(%rbp), %rdi
callq 0x1170
nopl (%rax)