Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 Java 中尽可能高效地实现一个稀疏矩阵。我收到一个比其他值有更多 0 的矩阵,我需要有效地保存它。我正在考虑使用一个包含值和位置的对象的数组由 line*max nr of columns + the column 组成。
Guava表可以是稀疏的。
Colt库也有稀疏矩阵。
完全取决于您在所述矩阵上执行的操作,哪种实现将适合您的需求。
例如,如果您所做的只是更新值并检索它们,Map<Point, Value>则将起作用。加法也很容易,但乘法变得非常困难。
Map<Point, Value>