// File: tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::updateRing()
void MP2Node::updateRing() {
    vector<Node> curMemList;
    bool change = false;

	/*
	 *  Step 1. Get the current membership list from Membership Protocol / MP1
	 */
	curMemList = getMembershipList();

	/*
	 * Step 2: Construct the ring
	 */
	// Sort the list based on the hashCode
	sort(curMemList.begin(), curMemList.end());

	// Check if the ring has changes
	if (curMemList.size() != ring.size()) {
        // if the current membership ring and my ring doesn't have the same size, then it must have changed
	    change = true;
	} else {
	    // go through each node in the two rings and check if they the same hash
        for (int i = 0; i < ring.size(); i++) {
            if (ring.at(i).getHashCode() != curMemList.at(i).getHashCode()) {
                change = true;
            }
        }
	}

	ring = curMemList;
	/*
	 * Step 3: Run the stabilization protocol IF REQUIRED
	 */
	// Run stabilization protocol if the hash table size is greater than zero and if there has been a changed in the ring
	if (change) {
        stabilizationProtocol();
	}

	// Also update the transaction map to see if any has been successful or failed
	updateTransactionMap();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x15010
movq -0x70(%rbp), %rsi
movb $0x0, -0x21(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1dfd0
jmp 0x1de33
leaq -0x20(%rbp), %rdi
movq %rdi, -0x78(%rbp)
leaq -0x40(%rbp), %rsi
movq %rsi, -0x80(%rbp)
callq 0x15050
movq -0x80(%rbp), %rdi
callq 0x15080
movq -0x78(%rbp), %rdi
callq 0x21a80
movq -0x78(%rbp), %rdi
movq %rax, -0x58(%rbp)
callq 0x21ab0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x21a40
jmp 0x1de7a
leaq -0x20(%rbp), %rdi
callq 0x150e0
movq -0x70(%rbp), %rdi
movq %rax, -0x88(%rbp)
addq $0x30, %rdi
callq 0x150e0
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
je 0x1dec9
movb $0x1, -0x21(%rbp)
jmp 0x1df7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x15080
jmp 0x1dfc1
movl $0x0, -0x64(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x64(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x30, %rdi
callq 0x150e0
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x1df7c
movq -0x70(%rbp), %rdi
addq $0x30, %rdi
movslq -0x64(%rbp), %rsi
callq 0x15100
movq %rax, -0x98(%rbp)
jmp 0x1df15
movq -0x98(%rbp), %rdi
callq 0x26310
movq %rax, -0xa0(%rbp)
jmp 0x1df2a
movslq -0x64(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x15100
movq %rax, -0xa8(%rbp)
jmp 0x1df40
movq -0xa8(%rbp), %rdi
callq 0x26310
movq %rax, -0xb0(%rbp)
jmp 0x1df55
movq -0xa0(%rbp), %rax
movq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
je 0x1df6c
movb $0x1, -0x21(%rbp)
jmp 0x1df6e
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1ded0
jmp 0x1df7e
movq -0x70(%rbp), %rdi
addq $0x30, %rdi
leaq -0x20(%rbp), %rsi
callq 0x21ae0
jmp 0x1df91
testb $0x1, -0x21(%rbp)
je 0x1dfa4
movq -0x70(%rbp), %rdi
callq 0x1e160
jmp 0x1dfa2
jmp 0x1dfa4
movq -0x70(%rbp), %rdi
callq 0x1e4d0
jmp 0x1dfaf
leaq -0x20(%rbp), %rdi
callq 0x15080
addq $0xb0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x45b0
nopw (%rax,%rax)