Libraryless. Click here for Pure Java version (9867L/54K).
static <A> Map<A, MultiSet<Int>> runLengthStats(L<A> list) { Map<A, MultiSet<Int>> map = new Map; int n = l(list), i = 0; while (i < n) { A a = list.get(i); int j = i+1; while (j < n && eq(a, list.get(j))) ++j; MultiSet<Int> ms = getOrCreate(map, a, -> new MultiSet); ms.add(j-i); i = j; } ret map; }
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036264 |
Snippet name: | runLengthStats |
Eternal ID of this version: | #1036264/3 |
Text MD5: | 3c3454e1fa0b78d427892718517ed81d |
Transpilation MD5: | 59035002b8e3a45f4cddb797ae498b03 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-06 15:23:04 |
Source code size: | 346 bytes / 13 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 129 / 186 |
Version history: | 2 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |