// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, 0x8(%rsp)
movq 0x38(%rdi), %r13
movq 0x18(%r13), %rbp
leaq 0x98(%rsp), %r15
leaq 0x78(%rsp), %rbx
leaq 0x12(%rsp), %r14
addq $0x8, %r13
cmpq %r13, %rbp
je 0x490c
movl 0x24(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x24(%rbp)
cmpl $0x9, %eax
jge 0x47c6
movq %rbp, %rdi
callq 0x31a0
movq %rax, %rbp
jmp 0x47a2
movl 0x20(%rbp), %esi
leaq 0x38(%rsp), %r13
movq %r13, %rdi
callq 0x4a9a
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
leaq 0xe4cc(%rip), %rdx      # 0x12cb1
callq 0x4a7b
movq %r15, %r13
movq %r15, %rdi
xorl %esi, %esi
callq 0x4a9a
leaq 0x18(%rsp), %rdi
leaq 0x58(%rsp), %r12
movq %r12, %rsi
movq %r13, %rdx
callq 0x4a14
movq %r13, %rdi
callq 0x3110
movq %r12, %rdi
callq 0x3110
leaq 0x38(%rsp), %rdi
callq 0x3110
movq %rbx, %r13
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3340
movq %r12, %rdi
movq %r13, %rsi
callq 0x4af4
movq %r12, %rsi
movq %r14, %r12
movq %r14, %rdi
callq 0x9f22
movq %rbx, %rdi
callq 0x3110
movq 0x8(%rsp), %r13
movq 0x10(%r13), %rdi
movq 0x20(%r13), %rsi
addq $0x8, %rsi
movq %r12, %rdx
callq 0x9772
movq 0x20(%r13), %rax
movq 0x28(%rax), %rcx
movq %rcx, 0x40(%rax)
movq 0x20(%r13), %rdi
movq 0x40(%rdi), %rax
cmpq 0x30(%rdi), %rax
je 0x48ae
movq %rax, %rdi
callq 0x9f90
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rdi
cmpl 0x20(%rbp), %eax
je 0x48cb
movq 0x40(%rdi), %rax
addq $0x18, %rax
movq %rax, 0x40(%rdi)
jmp 0x4884
movq 0x16713(%rip), %rdi     # 0x1afc8
leaq 0xd75d(%rip), %rsi      # 0x12019
callq 0x3240
movq %rax, %rdi
callq 0x3130
jmp 0x48e5
movq 0x40(%rdi), %rsi
addq $0x28, %rdi
callq 0x4bbc
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %rax, 0x40(%rcx)
movq 0x8(%rsp), %r13
movq 0x38(%r13), %rdi
movq %rbp, %rsi
callq 0x52d8
movq %rax, %rbp
leaq 0x18(%rsp), %rdi
callq 0x3110
movq 0x38(%r13), %r13
jmp 0x479e
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4962
jmp 0x4962
jmp 0x4962
jmp 0x4962
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3110
jmp 0x493b
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x3110
jmp 0x494a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x496a
jmp 0x4962
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3110
jmp 0x4965
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3420
nop