Are hash maps more memory efficient then regular arrays?

Like in terms of retrieval of data? When would you want to use a hash map over a regular array? Complexity of data?

Haven’t seen much talk about this on the devforum

local hash_table = {
	["1_2"] = "foo",
	["1_3"] = "bar"
}

local array = {
	[1] = {
		[2] = "foo"
	},
	[1] = {
		[3] = "bar"
	}
}
1 Like

Table accesses in Lua work similarly for both number keys and string keys, so in this case you’re using a hash map either way. Tables with number keys are not contiguous (as suggested by this), and thus don’t have the memory or access speed advantages of arrays.

1 Like