Store matrices and compare them in java -
i need store many matrices , compare of them retrieving last matrix added , previous one.
i create these matrices using:
int[][] matrix = new int[10][10];
my matrices have 0s, 1s , 2s. want compare matrices based on value of each position. in case, 2 matrices different long @ least 1 position has different value. each matrix created bases on elements detected via reactivision. elements not moved 2s, elements added 1s, , there isn't it's 0.
for example:
1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
and
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
would different.
the number of matrices stored not fixed. if have 10 matrix created, efficient way store these , able compare them ?
i've searched on stackoverflow , other forums can't find answer
since many (maybe most) entries in matrices zeroes, inefficient store them as is. need use sparse matrix representation. here pretty exhaustive list of matrix libraries, many of allow sparse representations.
most of them have equals()
method, can override suit definition (or not, if definition same yours).
finally, since need compare last 2 matrices, need sort of queue. maintain list, , use listiterator
this.
Comments
Post a Comment