Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1026148 // SparseIntArray2D_65536 - max 65536 rows, 65536 cols

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2412L/15K).

final sclass SparseIntArray2D_65536 implements IIntArray2D {
  int nrows, ncols;
  IntIntMap entries = new(256, 0.75f);
  
  *() {}
  *(int *nrows, int *ncols) {}
  
  public int nrows() { ret nrows; }
  public int ncols() { ret ncols; }

  /** Returns A(i, j). */
  public int get(int i, int j) {
    ret entries.get(combine(i, j));
  }

  /** Sets A(i, j). */
  public int set(int i, int j, int x) {
    if (x == 0)
      entries.remove(combine(i, j));
    else
      entries.put(combine(i, j), x);
    ret x;
  }
  
  static int combine(int i, int j) {
    ret i << 16 | j;
  }
}

Author comment

Began life as a copy of #1026140

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1026148
Snippet name: SparseIntArray2D_65536 - max 65536 rows, 65536 cols
Eternal ID of this version: #1026148/5
Text MD5: 88fb97961ccecb2d19efcf392f79e2c1
Transpilation MD5: fe06537f8b44d7f8bba269d1664b655c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 03:20:14
Source code size: 609 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 500
Version history: 4 change(s)
Referenced in: [show references]