I know there’s HashMap.GetKeyValueArrays(allocator); , but that’s a pretty involved process for when i just want to get the item at a known index.
or just any random item in the hashmap
I know there’s HashMap.GetKeyValueArrays(allocator); , but that’s a pretty involved process for when i just want to get the item at a known index.
or just any random item in the hashmap
what is an index in a hashmap? (or do you mean key)
that when you use indexer. hashMap[key]
no, like hashmap.KeyValuePairAt(0)
i just need to get the n’th item, or the 0th item. i have to do this because of that
static int GetAnyValidSimplex() {
NativeArray<int> keys = _indexToSimplex.GetKeyArray(Allocator.Temp);
int index = keys.Length % 2 == 0 ? keys.Length / 2 : (keys.Length - 1) / 2;
int value = keys[index];
keys.Dispose();
return value;
}
This is always expensive as the HashMap stores a linked list of sparse buckets. Also the indices are not stable. Even adding an element can change all of them.
Do you actually need a HashMap or do you simply want to store tuples? Do you have a lot of lookups by key? How big is the map?
wait, so you’re telling me it doesn’t actually use a hash and just compares the keys until you get the right key?
The map is absolutely massive. it contains all of the tetrahedrons formed out of light probes. but i need to use some sort of map so that each tetrahedron can reference a neighbour tetrahedron so that you can traverse them and quickly find the object that needs global illumination
Okay, that’s internal. there could be empty slots in internal key/value array.
random access could give you unexpected value. so you need to stick to GetKeyValueArrays.
internally it’s more like a LinkList, for fast add/remove. so when some key-value pair is remove there will be a gap. so you can not random access.
It’s a standard pattern for hashmap.
If you look into System.Dictionary. It uses the same approach. Dictionary just don’t tell you that it’s allocating because there’s GC.
will use index reference or pointer if I were you. Double pointer if the content is re-allocatable.
with linear storage NativeArray/NativeList.
That’s how unity.physic managed convex collider Face/Edge/Vertex and Voronoi Region.