// File: zkl94[P]distributed-key-value-store/MP1Node.cpp
// Function: MP1Node::updateToBeDeletedMap()
void MP1Node::updateToBeDeletedMap() {

    std::map<int, int>::iterator it = this->tobedeleted->begin();
    
    while(it != this->tobedeleted->end()) {
        it->second = it->second + 1;
        if (it->second >= TREMOVE) {
            // log the removal
            Address address;
            string _address = to_string(it->first) + ":" + to_string(0);
            address = Address(_address);
            log->logNodeRemove(&memberNode->addr, &address);

            // remove from member list
            bool found = false;
            memberNode->myPos = memberNode->memberList.begin();
            while (memberNode->myPos != memberNode->memberList.end()) {
                if ((*memberNode->myPos).getid() == it->first) {
                    // found it
                    found = true;
                    memberNode->myPos = memberNode->memberList.erase(memberNode->myPos);
                    break;
                }
                ++memberNode->myPos;
            }
            if (!found) {
                cout << "the should-be-deleted entry is not found in member list; sth goes wrong" << endl;
            }

            // remove from to-be-deleted map; can be re-added by membership protocol now
            it = this->tobedeleted->erase(it);
        } else {
            ++it;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq 0x38(%rax), %rdi
callq 0x7390
movq %rax, -0x10(%rbp)
movq -0x118(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x73f0
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x73c0
testb $0x1, %al
jne 0x68b1
jmp 0x6c57
leaq -0x10(%rbp), %rdi
callq 0x7420
movl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x7420
movl -0x11c(%rbp), %ecx
movl %ecx, 0x4(%rax)
leaq -0x10(%rbp), %rdi
callq 0x7420
cmpl $0xa, 0x4(%rax)
jl 0x6c49
leaq -0x1e(%rbp), %rdi
callq 0x6d90
leaq -0x10(%rbp), %rdi
callq 0x7420
movl (%rax), %esi
leaq -0x80(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x6f90
movq -0x128(%rbp), %rsi
leaq 0x2138c(%rip), %rdx     # 0x27ca9
leaq -0x60(%rbp), %rdi
callq 0x6f40
jmp 0x6928
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x6f90
jmp 0x6938
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x6e70
jmp 0x694e
leaq -0xb0(%rbp), %rdi
callq 0x41e0
leaq -0x60(%rbp), %rdi
callq 0x41e0
leaq -0x80(%rbp), %rdi
callq 0x41e0
leaq -0xd8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4150
jmp 0x697e
leaq -0xb6(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x70b0
jmp 0x6993
leaq -0x1e(%rbp), %rdi
leaq -0xb6(%rbp), %rsi
callq 0x150a0
jmp 0x69a5
leaq -0xd8(%rbp), %rdi
callq 0x41e0
movq -0x118(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rax), %rsi
addq $0x8, %rsi
leaq -0x1e(%rbp), %rdx
callq 0x143e0
jmp 0x69cf
movq -0x118(%rbp), %rax
movb $0x0, -0xd9(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x7250
movq %rax, %rcx
movq -0x118(%rbp), %rax
movq %rcx, -0xe8(%rbp)
movq 0x20(%rax), %rax
movq -0xe8(%rbp), %rcx
movq %rcx, 0x40(%rax)
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x40, %rcx
movq %rcx, -0x130(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x7280
movq -0x130(%rbp), %rdi
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x72b0
testb $0x1, %al
jne 0x6a50
jmp 0x6bb3
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rdi
addq $0x40, %rdi
callq 0x72f0
movq %rax, %rdi
callq 0x15240
movl %eax, -0x134(%rbp)
jmp 0x6a74
leaq -0x10(%rbp), %rdi
callq 0x7420
movq %rax, %rcx
movl -0x134(%rbp), %eax
cmpl (%rcx), %eax
jne 0x6b9a
movq -0x118(%rbp), %rax
movb $0x1, -0xd9(%rbp)
movq 0x20(%rax), %rsi
movq %rsi, %rax
addq $0x28, %rax
movq %rax, -0x148(%rbp)
addq $0x40, %rsi
leaq -0x100(%rbp), %rdi
callq 0x7550
movq -0x148(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x74e0
movq %rax, -0x140(%rbp)
jmp 0x6ada
movq -0x118(%rbp), %rax
movq -0x140(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movq 0x20(%rax), %rax
movq -0xf8(%rbp), %rcx
movq %rcx, 0x40(%rax)
jmp 0x6bb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6b52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6b49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x41e0
leaq -0x60(%rbp), %rdi
callq 0x41e0
leaq -0x80(%rbp), %rdi
callq 0x41e0
jmp 0x6c60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x6c3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x41e0
jmp 0x6c3e
movq -0x118(%rbp), %rax
movq 0x20(%rax), %rdi
addq $0x40, %rdi
callq 0x7370
jmp 0x6a0a
testb $0x1, -0xd9(%rbp)
jne 0x6bef
movq 0x2f405(%rip), %rdi     # 0x35fc8
leaq 0x2044f(%rip), %rsi     # 0x27019
callq 0x42f0
movq %rax, -0x150(%rbp)
jmp 0x6bd8
movq -0x150(%rbp), %rdi
movq 0x2f3d2(%rip), %rsi     # 0x35fb8
callq 0x4350
jmp 0x6bed
jmp 0x6bef
movq -0x118(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rsi
callq 0x7450
movq %rax, -0x158(%rbp)
jmp 0x6c1a
movq -0x158(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x41e0
jmp 0x6c52
leaq -0x40(%rbp), %rdi
callq 0x41e0
jmp 0x6c60
leaq -0x10(%rbp), %rdi
callq 0x7490
jmp 0x6887
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x4550
nopl (%rax)