In memory constrained environments you just make the underlying array a sparse vector, then it can be mostly empty without using much memory at all.
alternatively, depending on your data and the sparseness, bit vectors can indicate filled and empty slots and popcnt be used to find the actual slot for some index.