Libraryless. Click here for Pure Java version (8193L/46K).
1 | interface Matrix<A> extends WidthAndHeight { |
2 | public A get(int x, int y); |
3 | public void set(int x, int y, A a); |
4 | |
5 | default Pt size() { ret pt(getWidth(), getHeight()); } |
6 | default int nCells() { ret getWidth()*getHeight(); } |
7 | |
8 | default A get(Pt p) { ret get(p.x, p.y); } |
9 | default void set aka put(Pt p, A a) { set(p.x, p.y, a); } |
10 | |
11 | // one row of the matrix as a virtual list (mutable) |
12 | default L<A> getLine(int y) { |
13 | ret new RandomAccessAbstractList<A>() { |
14 | public int size() { ret getWidth(); } |
15 | |
16 | public A get(int x) { |
17 | ret Matrix.this.get(x, y); |
18 | } |
19 | |
20 | public A set(int x, A val) { |
21 | A old = Matrix.this.get(x, y); |
22 | Matrix.this.set(x, y, val); |
23 | ret old; |
24 | } |
25 | }; |
26 | } |
27 | } |
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: | 226 / 398 |
Version history: | 11 change(s) |
Referenced in: | [show references] |