Is there a builtin data structure in java that lets me do this:
Matrix matrix = new Matrix(); // No fixed size, and O(1) to initate
matrix.set(x,y,32); // adds 32 to arbitrary positions x and y in O(1)
matrix.isempty(x,y); // returns true or false wether x,y has been set to a value
matrix.clear(); // clears all elements in O(1)
You cannot use a two dimensional array, because you need to initate it to a fixed size, which takes O(x*y). You cannot use a list of lists, because you cannot add objects to arbitrary positions.