// File: deepaktabraham[P]BPlus-Tree/src/tree.cpp
// Function: BPlusTree::Search(float)
void BPlusTree :: Search(float key)
{
	// check if tree is empty
	if(NULL == root)
	{
		outputFile<<"Null"<<endl;
	}

	// if it is a vaild search
	else
	{
		int i = 0;	
		
		// obtain the search path from root to leaf node and push it on to a stack
		stack<Node*>* path = new stack<Node*>;
		Search_Path(root, key, path);
		
		// search for the key in the leaf node, which is at the top of the stack
		vector<float> keys = path->top()->Get_Keys();
		vector< vector <string> > values = path->top()->Get_Values(); 
		vector<float>::iterator index = lower_bound(keys.begin(), keys.end(), key);

		// check if key is found
		if(key == keys[index - keys.begin()])
		{
			// display the values
			for(i = 0; i < values[index - keys.begin()].size() - 1; i++)
			{
				outputFile<<values[index - keys.begin()][i]<<",";
			}
			outputFile<<values[index - keys.begin()][i]<<endl;
		}

		// if key is not found
		else
		{
			outputFile<<"Null"<<endl;
		}

		delete(path);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x98(%rbp)
xorl %eax, %eax
cmpq 0x8(%rcx), %rax
jne 0x35a2
movq -0x98(%rbp), %rdi
addq $0x10, %rdi
leaq 0xcb15(%rip), %rsi      # 0x1009e
callq 0x2190
movq %rax, %rdi
movq 0x14a28(%rip), %rsi     # 0x17fc0
callq 0x21c0
jmp 0x38dc
movl $0x0, -0x10(%rbp)
movl $0x50, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
callq 0x4430
jmp 0x35c7
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0x8(%rdi), %rsi
movss -0xc(%rbp), %xmm0
movq -0x18(%rbp), %rdx
callq 0x2ed0
movq -0x18(%rbp), %rdi
callq 0x4460
movq (%rax), %rsi
leaq -0x40(%rbp), %rdi
callq 0x6c60
movq -0x18(%rbp), %rdi
callq 0x4460
movq %rax, -0xa8(%rbp)
jmp 0x3612
movq -0xa8(%rbp), %rax
movq (%rax), %rsi
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x58(%rbp), %rdi
callq *%rax
jmp 0x362b
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x4160
movq -0xb8(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x4190
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0xc(%rbp), %rdx
callq 0x4110
movq %rax, -0xb0(%rbp)
jmp 0x3669
movq -0xb0(%rbp), %rax
movq %rax, -0x60(%rbp)
movss -0xc(%rbp), %xmm0
movss %xmm0, -0xbc(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4160
movq %rax, -0x78(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x41e0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x41c0
movss -0xbc(%rbp), %xmm0
ucomiss (%rax), %xmm0
jne 0x385d
jp 0x385d
movl $0x0, -0x10(%rbp)
movslq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4160
movq %rax, -0x80(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x41e0
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x4500
movq %rax, %rdi
callq 0x4520
movq %rax, %rcx
movq -0xc8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x37e4
movq -0x98(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xd8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4160
movq %rax, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x41e0
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x4500
movq %rax, %rdi
movslq -0x10(%rbp), %rsi
callq 0x4540
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x2170
movq %rax, -0xd0(%rbp)
jmp 0x3777
movq -0xd0(%rbp), %rdi
leaq 0xc921(%rip), %rsi      # 0x100a6
callq 0x2190
jmp 0x378c
jmp 0x378e
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x36c5
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x2180
jmp 0x38e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x38d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4560
jmp 0x38d1
movq -0x98(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4160
movq %rax, -0x90(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x41e0
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x4500
movq %rax, %rdi
movslq -0x10(%rbp), %rsi
callq 0x4540
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x2170
movq %rax, -0xe0(%rbp)
jmp 0x3846
movq -0xe0(%rbp), %rdi
movq 0x1476c(%rip), %rsi     # 0x17fc0
callq 0x21c0
jmp 0x385b
jmp 0x3894
movq -0x98(%rbp), %rdi
addq $0x10, %rdi
leaq 0xc82f(%rip), %rsi      # 0x1009e
callq 0x2190
movq %rax, -0xf0(%rbp)
jmp 0x387d
movq -0xf0(%rbp), %rdi
movq 0x14735(%rip), %rsi     # 0x17fc0
callq 0x21c0
jmp 0x3892
jmp 0x3894
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x38bd
movq -0xf8(%rbp), %rdi
callq 0x44e0
movq -0xf8(%rbp), %rdi
callq 0x2180
leaq -0x58(%rbp), %rdi
callq 0x4560
leaq -0x40(%rbp), %rdi
callq 0x42a0
jmp 0x38dc
leaq -0x40(%rbp), %rdi
callq 0x42a0
jmp 0x38e5
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x22d0
nop