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

40
LINES

< > BotCompany Repo | #1003152 // subArray - return part of an array. TODO: optimize (see subByteArray)

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

Libraryless. Click here for Pure Java version (302L/2K).

1  
static int[] subArray(int[] b, int start, int end) {
2  
  int[] x = new int[end-start];
3  
  System.arraycopy(b, start, x, 0, end-start);
4  
  ret x;
5  
}
6  
7  
meta-for byte also as long {
8  
  static byte[] subArray(byte[] b, int start, int end) {
9  
    start = max(start, 0); end = min(end, l(b));
10  
    if (start >= end) ret new byte[0];
11  
    byte[] x = new byte[end-start];
12  
    System.arraycopy(b, start, x, 0, end-start);
13  
    ret x;
14  
  }
15  
}
16  
17  
static short[] subArray(short[] b, int start, int end) {
18  
  if (start <= 0 && end >= l(b)) ret b;
19  
  short[] x = new short[end-start];
20  
  System.arraycopy(b, start, x, 0, end-start);
21  
  ret x;
22  
}
23  
24  
static float[] subArray(float[] b, int start, int end) {
25  
  float[] x = new float[end-start];
26  
  System.arraycopy(b, start, x, 0, end-start);
27  
  ret x;
28  
}
29  
30  
static O[] subArray(O[] b, int start) {
31  
  ret subArray(b, start, l(b));
32  
}
33  
34  
static O[] subArray(O[] b, int start, int end) {
35  
  start = max(start, 0); end = min(end, l(b));
36  
  if (start >= end) ret new O[0];
37  
  O[] x = new O[end-start];
38  
  System.arraycopy(b, start, x, 0, end-start);
39  
  ret x;
40  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003152
Snippet name: subArray - return part of an array. TODO: optimize (see subByteArray)
Eternal ID of this version: #1003152/8
Text MD5: bc830b7a106e1a97b2c0b783ad9f7d4b
Transpilation MD5: 11ef333bcd23bbaacf80f18a85ca6f1a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-28 19:37:50
Source code size: 1094 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 789 / 824
Version history: 7 change(s)
Referenced in: [show references]