accelerating merging function by reducing search operation

Locating an matrix element in a sparse matrix, need to visit all
elements in a row. When the number of element in that row is big, this
will takes times. Now, I create a reference table to just look up from
the table to locate the pointer of the element.