But how often you want to "insert" elements in a sparse matrix? It seems like a very strange thing to do, I cannot imagine a situation where I would need to do that (during the lifetime of a sparse matrix).
I’m not saying B+ tree is the best structure for them. Just another one to consider. Which one is the best depends on use case.
I used these trees in the code that builds large sparse matrices from something else. The domain was CAM/CAE, it was finite elements. As a nice side effect, with one tree per row I was able to parallelize the construction of that matrix, as different CPU cores can update different rows of the matrix in parallel.
Sure, B+ trees are cool. I was just wondering about the use case for element insertion (except maybe for the construction of the matrix). Most of my time is spent in algebraic operations with immutable matrices.
Regarding the construction of the matrix, instead of insertions very often you can do it with tricks using kronecker products and the like.
> Most of my time is spent in algebraic operations with immutable matrices.
CSR is probably the way to go then.
Also, if you do that math on CPU and your matrix is not randomly sparse but made of small dense areas of non-zeroes, consider less compressed SIMD-friendly variant of CSR, where instead of individual elements you keep dense SIMD vectors.
For example, if you have AVX and need fp64 precision, keep 4 elements long slices of rows there. This way you can use 256-bit loads and FMA instructions to do that math.
Or if you spending most of time multiplying matrices as opposed to matrix*vector, might be reasonable to keep 2x2 dense blocks as opposed to 4x1.
Finite element assembly is one I see daily. There are many times In computational mechanics and also mesh manipulation (graphics programming, shape design, etc) when inserting into a sparse matrix is useful.
How about the PageRank algorithm, where your crawler detects new links and you need to insert new weights into the matrix from which you then later compute page ranks?
Wouldn't it be easier to first do your crawling and then construct the matrix in one go? But graphs more broadly sounds like an area where you might want to update the matrix yeah.
I used these trees in the code that builds large sparse matrices from something else. The domain was CAM/CAE, it was finite elements. As a nice side effect, with one tree per row I was able to parallelize the construction of that matrix, as different CPU cores can update different rows of the matrix in parallel.