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

14
LINES

< > BotCompany Repo | #1035044 // intArrayToNonZeroTable - gives an IntBuffer of index, value, index, value, ... for all non-zero elements of the array

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

Libraryless. Click here for Pure Java version (5388L/30K).

static IntBuffer intArrayToNonZeroTable(int[] array) {
  // some reasonable compromise for initial size
  IntBuffer buf = new(array.length);
  
  for i over array: {
    int value = array[i];
    if (value != 0) {
      buf.add(i);
      buf.add(value);
    }
  }
  
  ret buf;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035044
Snippet name: intArrayToNonZeroTable - gives an IntBuffer of index, value, index, value, ... for all non-zero elements of the array
Eternal ID of this version: #1035044/2
Text MD5: 5fa467f91ef18c4ddcf7c813875f6913
Transpilation MD5: 64199f9a50362ebb83b2acd6374aaff0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-25 21:21:51
Source code size: 292 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 48 / 84
Version history: 1 change(s)
Referenced in: [show references]