// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
leaq -0x95f(%rip), %rdi      # 0x43a0
movq 0x72ba(%rip), %rdx      # 0xbfc0
movq %rdx, %rsi
callq 0x5e20
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1633(%rip), %rsi      # 0x6350
callq 0x6370
movl $0x3e8, -0xc(%rbp)      # imm = 0x3E8
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2180
movq %rax, -0x18(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2180
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4ec0
movl -0x24(%rbp), %edi
callq 0x44a0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %edi
callq 0x44a0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0x6000
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x6200
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6300
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6320
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x30(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x34e5(%rip), %rsi      # 0x82e1
movl $0xcd, %edx
leaq 0x37cf(%rip), %rcx      # 0x85d7
leaq 0x35ea(%rip), %r8       # 0x83f9
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4e20
callq 0x2e50
jmp 0x4e22
jmp 0x4e24
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x349e(%rip), %rsi      # 0x82e1
movl $0xce, %edx
leaq 0x3788(%rip), %rcx      # 0x85d7
leaq 0x35b4(%rip), %r8       # 0x840a
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4e67
callq 0x2e50
jmp 0x4e69
jmp 0x4e6b
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x3457(%rip), %rsi      # 0x82e1
movl $0xcf, %edx
leaq 0x3741(%rip), %rcx      # 0x85d7
leaq 0x3587(%rip), %r8       # 0x8424
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4eae
callq 0x2e50
jmp 0x4eb0
jmp 0x4eb2
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4d52
movl $0x7d0, -0x44(%rbp)     # imm = 0x7D0
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x6200
cmpq $0x0, %rax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x33fa(%rip), %rsi      # 0x82e1
movl $0xd4, %edx
leaq 0x36e4(%rip), %rcx      # 0x85d7
leaq 0x3546(%rip), %r8       # 0x8440
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4f0b
callq 0x2e50
jmp 0x4f0d
jmp 0x4f0f
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x5f90
cmpq $0x0, %rax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x33b2(%rip), %rsi      # 0x82e1
movl $0xd5, %edx
leaq 0x369c(%rip), %rcx      # 0x85d7
leaq 0x3529(%rip), %r8       # 0x846b
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4f53
callq 0x2e50
jmp 0x4f55
leaq -0xbbc(%rip), %rdi      # 0x43a0
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x5e20
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x13d9(%rip), %rsi      # 0x6350
callq 0x6370
movl $0x35, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x5007
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0x6000
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x6100
andb $0x1, %al
movzbl %al, %edi
leaq 0x330d(%rip), %rsi      # 0x82e1
movl $0xde, %edx
leaq 0x35f7(%rip), %rcx      # 0x85d7
leaq 0x34a7(%rip), %r8       # 0x848e
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4ff8
callq 0x2e50
jmp 0x4ffa
jmp 0x4ffc
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4f8a
jmp 0x5009
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x54(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5f90
cmpq $0x0, %rax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x32ad(%rip), %rsi      # 0x82e1
movl $0xe0, %edx
leaq 0x3597(%rip), %rcx      # 0x85d7
leaq 0x3466(%rip), %r8       # 0x84ad
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x5058
callq 0x2e50
jmp 0x505a
movq -0x8(%rbp), %rdi
callq 0x61d0
movq -0x50(%rbp), %rdi
callq 0x61d0
movq -0x18(%rbp), %rdi
callq 0x2270
movq -0x20(%rbp), %rdi
callq 0x2270
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)