Libraryless. Click here for Pure Java version (9867L/54K).
1 | static <A> Map<A, MultiSet<Int>> runLengthStats(L<A> list) { |
2 | Map<A, MultiSet<Int>> map = new Map; |
3 | int n = l(list), i = 0; |
4 | while (i < n) { |
5 | A a = list.get(i); |
6 | int j = i+1; |
7 | while (j < n && eq(a, list.get(j))) ++j; |
8 | MultiSet<Int> ms = getOrCreate(map, a, -> new MultiSet); |
9 | ms.add(j-i); |
10 | i = j; |
11 | } |
12 | ret map; |
13 | } |
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: | 128 / 186 |
Version history: | 2 change(s) |
Referenced in: | [show references] |