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

18
LINES

< > BotCompany Repo | #1031750 // AscendingOrderIntObjectMap - you can only put keys in ascending order

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

Libraryless. Click here for Pure Java version (3679L/22K).

sclass AscendingOrderIntObjectMap<A> {
  new IntBuffer keys;
  new L<A> values;
  
  void put(int key, A value) {
    if (!keys.isEmpty() && last(keys) >= key)
      fail("Ascending order fail: " + last(keys) + " / " + key);
    keys.add(key);
    values.add(value);
  }
  
  A get(int key) {
    int i = intBufferBinarySearch(keys, key);
    ret i >= 0 ? values.get(i) : null;
  }
  
  int size() { ret keys.size(); }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031750
Snippet name: AscendingOrderIntObjectMap - you can only put keys in ascending order
Eternal ID of this version: #1031750/2
Text MD5: fd3d7963a2b62f8e8d1e3c91b11ed451
Transpilation MD5: da1ef4d15316a203e19db817619dcb4c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-29 04:38:48
Source code size: 437 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 248 / 403
Version history: 1 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)