Logarithmic way of filtering sparse values..?
I have a situation where I show a matrix. The matrix contain values greater than or equal to 0. So to add convenience to the user I just added a bar slider whose minimum value is 0 and maximum value is the maximum value from the matrix. So when the user slides on the slider I just filter the matrix cells and show only those cells which have value gr开发者_如何学JAVAeater than the slider value user has slided.
My issue is that in the matrix table the values are quite sparse like there are a lot of values in the range sometime 1-5 and then 20-25 (can be other ranges also). So when i slider the tables gets reduced a lot.
I want something now that on moving the slider only a few values gets filtered. I was thinking if there is any logarithmic way of solving this problem...or may be some other way..
If your matrix is size M x N
consider storing the data in an array like data[L][2]
where L = M x N
and data[i][0]
is the actual value while data[i][1] is the value's position in your original M x N
matrix.
If data[i][0]
is sorted you can process it faster to find positions with values under a given threshold.
Example:
Matrix
1 2 3
0 7 1
5 1 9
Array (value, position)
0 1 1 1 2 3 5 7 9
4 1 6 8 2 3 7 5 9
Cells with values less than 3: 4 1 6 8 2
精彩评论