Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return value of size() is uint32_t for hash_set and hash_map while others are usually int #84566

Open
jsjtxietian opened this issue Nov 7, 2023 · 2 comments

Comments

@jsjtxietian
Copy link
Contributor

Godot version

Godot v4.2.beta (5ee9831)

System information

Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3619) - 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 Threads)

Issue description

In hash_map.h or hash_set.h we have:
_FORCE_INLINE_ uint32_t size() const { return num_elements; }

but other container's size() function all return int, like this in cowdata.h:

_FORCE_INLINE_ int size() const {
	uint32_t *size = (uint32_t *)_get_size();
	if (size) {
		return *size;
	} else {
		return 0;
	}
}

I guess we can do some clean up here. Better to change hashset's size() to return int, as uint32_t is good but may overflow when do some math about it.

Steps to reproduce

I met this problem when trying to add a hashset's size to a vector's size, and with treat warning with error on, the compiler complains about
'!=': signed/unsigned mismatch

Minimal reproduction project

N/A

@Calinou
Copy link
Member

Calinou commented Nov 7, 2023

@AThousandShips
Copy link
Member

AThousandShips commented Nov 7, 2023

Assuming the size of the hash table can fit in 31 bits (unsure, will have to check the prime tables) this could be done safely, but unsure if it is worth the overhaul of all internal use of it

Note that LocalVector, PooledList, and OAHashMap uses uint32_t for size by default, and PagedArray uses uint64_t, and LRU uses size_t

So it's not necessarily standardized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants