Not sure if you get it. If you really have billions of rows, even if you find a mechanism for efficiently storing your sparse matrix, you may have problems storing large amounts of data in memory.
However, you can use a simple map whose key is Pair , which contains a row and column to bind.
public class Pair<P, Q> { public final P p; public final Q q; public Pair(P p, Q q) { this.p = p; this.q = q; }
This will be used close to minimal storage, but does not necessarily solve your problem.
source share