// File: /workspace/github_c_makefile_star2_O3/chatziko-k08[P]lecture-code/tests/ADTMap_test.c
// Function: test_find
void test_find(void) {

	Map map = map_create(compare_ints, free, free);
	map_set_hash_function(map, hash_int);

	int N = 1000;
	int** key_array = malloc(N * sizeof(*key_array));
	int** value_array = malloc(N * sizeof(*value_array));

	for (int i = 0; i < N; i++) {
		key_array[i] = create_int(i);
		value_array[i] = create_int(i);

		map_insert(map, key_array[i], value_array[i]);
		MapNode found = map_find_node(map, key_array[i]);
		Pointer found_key = map_node_key(map, found);
		Pointer found_val = map_node_value(map, found);

		// Δοκιμάζουμε ότι ο κόμβος που μόλις κάναμε insert έχει το ίδιο Key και Value 
		TEST_ASSERT(found != MAP_EOF); 
		TEST_ASSERT(found_key == key_array[i]);
		TEST_ASSERT(found_val == value_array[i]);
	}	

	// Αναζήτηση στοιχείου που δεν υπάρχει στο map
	int not_exists = 2000;
	TEST_ASSERT(map_find_node(map, &not_exists) == MAP_EOF);
	TEST_ASSERT(map_find(map, &not_exists) == NULL);

	// Δοκιμή αναζήτησης μετά από διαδοχικά inserts/deletes (στην υλοποίηση με hashtable αυτό θα γεμίσει τον πίνακα με DELETED τιμές)
	Map map2 = map_create(compare_ints, NULL, NULL);
	map_set_hash_function(map2, hash_int);

	int M = 53;							// αρχικό μέγεθος στην υλοποίηση με hashtable
	for (int i = 0; i < M; i++) {
		map_insert(map2, key_array[i], value_array[i]);
		TEST_ASSERT(map_remove(map2, key_array[i]));
	}
	TEST_ASSERT(map_find(map2, &key_array[M]) == NULL);

	map_destroy(map);		// frees keys/values
	map_destroy(map2);

	free(key_array);
	free(value_array);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq -0x70f(%rip), %rdi      # 0x3cc4
movq 0x5be6(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4e20
movq %rax, %r14
leaq 0xcae(%rip), %rsi       # 0x509a
movq %rax, %rdi
callq 0x50a0
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21b0
movq %rax, %r12
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21b0
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movq %r14, 0x20(%rsp)
movq %r12, 0x8(%rsp)
movl $0x4, %edi
callq 0x21b0
movq %rax, %r15
movl %ebx, (%rax)
movq %rax, (%r12,%rbx,8)
movl $0x4, %edi
callq 0x21b0
movq %rax, %rbp
movl %ebx, (%rax)
movq 0x10(%rsp), %rax
movq %rbp, (%rax,%rbx,8)
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x4f17
movq %r14, %rdi
movq %r15, %rsi
callq 0x501b
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
callq 0x508e
movq %rax, %r12
movq %r14, %rdi
movq %r13, %rsi
callq 0x5092
movq %rax, %r14
xorl %edi, %edi
testq %r13, %r13
setne %dil
leaq 0x1e89(%rip), %rsi      # 0x6318
movl $0xcd, %edx
leaq 0x216e(%rip), %r13      # 0x6609
movq %r13, %rcx
leaq 0x1f8b(%rip), %r8       # 0x6430
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
xorl %edi, %edi
cmpq %r15, %r12
sete %dil
leaq 0x1e54(%rip), %r15      # 0x6318
movq %r15, %rsi
movl $0xce, %edx
movq %r13, %rcx
leaq 0x1f6b(%rip), %r8       # 0x6441
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
xorl %edi, %edi
cmpq %rbp, %r14
sete %dil
movq %r15, %rsi
movl $0xcf, %edx
movq %r13, %rcx
leaq 0x1f5b(%rip), %r8       # 0x645b
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
incq %rbx
cmpq $0x3e8, %rbx            # imm = 0x3E8
movq 0x20(%rsp), %r14
movq 0x8(%rsp), %r12
jne 0x441c
leaq 0x1c(%rsp), %rsi
movl $0x7d0, (%rsi)          # imm = 0x7D0
movq %r14, %rdi
callq 0x501b
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1dcc(%rip), %rsi      # 0x6318
leaq 0x20b6(%rip), %rcx      # 0x6609
leaq 0x1f1d(%rip), %r8       # 0x6477
movl $0xd4, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
leaq 0x1c(%rsp), %rsi
movq %r14, %rdi
callq 0x4ee4
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1d8d(%rip), %rsi      # 0x6318
leaq 0x2077(%rip), %rcx      # 0x6609
leaq 0x1f09(%rip), %r8       # 0x64a2
movl $0xd5, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
leaq -0x8f0(%rip), %rdi      # 0x3cc4
xorl %esi, %esi
xorl %edx, %edx
callq 0x4e20
movq %rax, %r12
leaq 0xad3(%rip), %rsi       # 0x509a
movq %rax, %rdi
callq 0x50a0
leaq 0x1d42(%rip), %r15      # 0x6318
leaq 0x202c(%rip), %r13      # 0x6609
leaq 0x1ee1(%rip), %rbp      # 0x64c5
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %r14
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x4f17
movq %r12, %rdi
movq %r14, %rsi
callq 0x4fac
movzbl %al, %edi
movq %r15, %rsi
movl $0xde, %edx
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
incq %rbx
cmpq $0x35, %rbx
jne 0x45e6
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
addq $0x1a8, %rsi            # imm = 0x1A8
movq %r12, %rdi
callq 0x4ee4
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1cba(%rip), %rsi      # 0x6318
leaq 0x1fa4(%rip), %rcx      # 0x6609
leaq 0x1e78(%rip), %r8       # 0x64e4
movl $0xe0, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x46af
movq 0x20(%rsp), %rdi
callq 0x5006
movq %r12, %rdi
callq 0x5006
movq %rbx, %rdi
callq 0x22c0
movq 0x10(%rsp), %rdi
callq 0x22c0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2e4b