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

27
LINES

< > BotCompany Repo | #1025078 // RollingMaximum - using "descending maxima" algorithm [OK]

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

Libraryless. Click here for Pure Java version (2528L/16K).

sclass RollingMaximum {
  int windowSize = 100, i;
  L<Entry> queue = new CircularArrayList; //linkedList();

  sclass Entry {
    int removeIndex;
    double value;
  
    *() {}
    *(int *removeIndex, double *value) {}
  }
  
  *() {}
  *(int *windowSize) {}
    
  double addAndGet(double val) {
    while (nempty(queue) && i >= first(queue).removeIndex)
      popFirst(queue);

    while (nempty(queue) && last(queue).value <= val)
      popLast(queue);

    queue.add(new Entry(i + windowSize, val));
    i++;
    ret first(queue).value;
  }
}

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: #1025078
Snippet name: RollingMaximum - using "descending maxima" algorithm [OK]
Eternal ID of this version: #1025078/9
Text MD5: b3bea9e67bd5c18f267de7afab46db39
Transpilation MD5: 85be16b767ddb878118b4cd99b539f75
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-05 13:24:27
Source code size: 575 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 637
Version history: 8 change(s)
Referenced in: [show references]