// File: amadvance[P]tommyds/check.c
// Function: test_hashtable
void test_hashtable(void)
{
	tommy_hashtable hashtable;
	struct object_hash* HASH;
	unsigned i, j, n;
	unsigned limit;
	const unsigned size = TOMMY_SIZE;
	const unsigned module = TOMMY_SIZE / 4;

	HASH = malloc(size * sizeof(struct object_hash));

	for(i=0;i<size;++i)
		HASH[i].value = i % module;

	/* initialize a very small hashtable */
	tommy_hashtable_init(&hashtable, 1);

	/* check that we allocated space for more elements */
	if (hashtable.bucket_max == 1)
		/* LCOV_EXCL_START */
		abort();
		/* LCOV_EXCL_STOP */

	/* destroy it as empty */
	tommy_hashtable_done(&hashtable);

	START("hashtable stack");
	limit = 5 * isqrt(size);
	for(n=0;n<=limit;++n) {
		/* last iteration is full size */
		if (n == limit)
			n = limit = size;

		tommy_hashtable_init(&hashtable, limit / 2);

		/* insert */
		for(i=0;i<n;++i)
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

		if (tommy_hashtable_memory_usage(&hashtable) < n * sizeof(void*))
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		if (tommy_hashtable_count(&hashtable) != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		the_count = 0;
		tommy_hashtable_foreach(&hashtable, count_callback);
		if (the_count != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		/* remove in backward order */
		for(i=0;i<n/2;++i)
			tommy_hashtable_remove_existing(&hashtable, &HASH[n-i-1].node);

		/* remove missing */
		for(i=0;i<n/2;++i)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[n-i-1], HASH[n-i-1].value) != 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		/* remove search */
		for(i=0;i<n/2;++i)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[n/2-i-1], HASH[n/2-i-1].value) == 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		tommy_hashtable_done(&hashtable);
	}
	STOP();

	START("hashtable queue");
	limit = isqrt(size) / 16;
	for(n=0;n<=limit;++n) {
		/* last iteration is full size */
		if (n == limit)
			n = limit = size;

		tommy_hashtable_init(&hashtable, limit / 2);

		/* insert first run */
		for(j=0,i=0;i<n;++i)
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

		the_count = 0;
		tommy_hashtable_foreach_arg(&hashtable, count_arg_callback, &the_count);
		if (the_count != n)
			/* LCOV_EXCL_START */
			abort();
			/* LCOV_EXCL_STOP */

		/* insert all the others */
		for(;i<size;++i,++j) {
			/* insert one */
			tommy_hashtable_insert(&hashtable, &HASH[i].node, &HASH[i], HASH[i].value);

			/* remove one */
			tommy_hashtable_remove_existing(&hashtable, &HASH[j].node);
		}

		for(;j<size;++j)
			if (tommy_hashtable_remove(&hashtable, search_callback, &HASH[j], HASH[j].value) == 0)
				/* LCOV_EXCL_START */
				abort();
				/* LCOV_EXCL_STOP */

		tommy_hashtable_done(&hashtable);
	}
	STOP();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0xf4240, -0x3c(%rbp)   # imm = 0xF4240
movl $0x3d090, -0x40(%rbp)   # imm = 0x3D090
movl $0x3567e00, %edi        # imm = 0x3567E00
callq 0x10b0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0xf4240, -0x2c(%rbp)   # imm = 0xF4240
jae 0x2f4b
movl -0x2c(%rbp), %eax
movl $0x3d090, %ecx          # imm = 0x3D090
xorl %edx, %edx
divl %ecx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl %edx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2f1b
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x7900
cmpq $0x1, -0x18(%rbp)
jne 0x2f65
callq 0x1040
leaq -0x20(%rbp), %rdi
callq 0x7a30
leaq 0x7312(%rip), %rdi      # 0xa287
callq 0x13e0
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x1310
imull $0x5, %eax, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
ja 0x31a3
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x2fb3
movl $0xf4240, -0x38(%rbp)   # imm = 0xF4240
movl $0xf4240, -0x34(%rbp)   # imm = 0xF4240
movl -0x38(%rbp), %eax
shrl %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0x7900
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x3019
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
callq 0x7a50
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2fcc
leaq -0x20(%rbp), %rdi
callq 0x7e00
movl -0x34(%rbp), %ecx
shlq $0x3, %rcx
cmpq %rcx, %rax
jae 0x3033
callq 0x1040
leaq -0x20(%rbp), %rdi
callq 0x3380
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
je 0x3049
callq 0x1040
movl $0x0, 0x100bdbd(%rip)   # 0x100ee10
leaq -0x20(%rbp), %rdi
leaq -0xa1e(%rip), %rsi      # 0x2640
callq 0x7cd0
movl 0x100bda7(%rip), %eax   # 0x100ee10
cmpl -0x34(%rbp), %eax
je 0x3073
callq 0x1040
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x34(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x30b4
movq -0x28(%rbp), %rsi
movl -0x34(%rbp), %eax
subl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
leaq -0x20(%rbp), %rdi
callq 0x7b20
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x307a
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x34(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x311e
movq -0x28(%rbp), %rdx
movl -0x34(%rbp), %eax
subl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
subl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
leaq 0x29f(%rip), %rsi       # 0x33a0
callq 0x7c10
cmpq $0x0, %rax
je 0x3111
callq 0x1040
jmp 0x3113
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x30bb
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x34(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x318c
movq -0x28(%rbp), %rdx
movl -0x34(%rbp), %eax
shrl %eax
subl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
subl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
leaq 0x231(%rip), %rsi       # 0x33a0
callq 0x7c10
cmpq $0x0, %rax
jne 0x317f
callq 0x1040
jmp 0x3181
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3125
leaq -0x20(%rbp), %rdi
callq 0x7a30
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2f91
callq 0x1460
leaq 0x70e8(%rip), %rdi      # 0xa297
callq 0x13e0
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x1310
shrl $0x4, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
ja 0x3368
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x31ed
movl $0xf4240, -0x38(%rbp)   # imm = 0xF4240
movl $0xf4240, -0x34(%rbp)   # imm = 0xF4240
movl -0x38(%rbp), %eax
shrl %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x20(%rbp), %rdi
callq 0x7900
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x325a
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
callq 0x7a50
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x320d
movl $0x0, 0x100bbac(%rip)   # 0x100ee10
leaq -0x20(%rbp), %rdi
leaq -0xc0f(%rip), %rsi      # 0x2660
leaq 0x100bb9a(%rip), %rdx   # 0x100ee10
callq 0x7d60
movl 0x100bb8f(%rip), %eax   # 0x100ee10
cmpl -0x34(%rbp), %eax
je 0x328b
callq 0x1040
jmp 0x328d
cmpl $0xf4240, -0x2c(%rbp)   # imm = 0xF4240
jae 0x32ff
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
callq 0x7a50
movq -0x28(%rbp), %rsi
movl -0x30(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
leaq -0x20(%rbp), %rdi
callq 0x7b20
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x328d
jmp 0x3301
cmpl $0xf4240, -0x30(%rbp)   # imm = 0xF4240
jae 0x3351
movq -0x28(%rbp), %rdx
movl -0x30(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rcx
leaq -0x20(%rbp), %rdi
leaq 0x6c(%rip), %rsi        # 0x33a0
callq 0x7c10
cmpq $0x0, %rax
jne 0x3344
callq 0x1040
jmp 0x3346
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3301
leaq -0x20(%rbp), %rdi
callq 0x7a30
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x31cb
callq 0x1460
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)