Libraryless. Click here for Pure Java version (8193L/46K).
interface Matrix<A> extends WidthAndHeight { public A get(int x, int y); public void set(int x, int y, A a); default Pt size() { ret pt(getWidth(), getHeight()); } default int nCells() { ret getWidth()*getHeight(); } default A get(Pt p) { ret get(p.x, p.y); } default void set aka put(Pt p, A a) { set(p.x, p.y, a); } // one row of the matrix as a virtual list (mutable) default L<A> getLine(int y) { ret new RandomAccessAbstractList<A>() { public int size() { ret getWidth(); } public A get(int x) { ret Matrix.this.get(x, y); } public A set(int x, A val) { A old = Matrix.this.get(x, y); Matrix.this.set(x, y, val); ret old; } }; } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033111 |
Snippet name: | Matrix - 2D (possibly virtual) array interface |
Eternal ID of this version: | #1033111/12 |
Text MD5: | 5825f3e3da3deef2c0ab1944a4bafffe |
Transpilation MD5: | e07bf9162ef32bf6c36e02d5737b9dfa |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-20 20:20:03 |
Source code size: | 772 bytes / 27 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 225 / 397 |
Version history: | 11 change(s) |
Referenced in: | #1033112 - ArrayMatrix - simple array-based implementation of Matrix #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |