Uses 3874K of libraries. Click here for Pure Java version (8776L/57K/202K).
!7 static int maxWords = 100000; static int maxWordLength = 10; static int topTenTargetLength = 10; static Map<S, Long> map; static L<S> topTen; p-subst { tt(); centerHigherConsole(); map = l_persistentTreeMap("Words + count"); topTen = l_persistentList("Top Ten"); printTopTen(); botIfMain(); } svoid addWordHits(Collection<S> words) { for (S word : words) { word = shorten(word, maxWordLength); long count = longMultiSet_add(map, word); insertToTopTen(word, count); } } svoid insertToTopTen(S word, long count) { int originalIndex = indexOf(topTen, word); int i = originalIndex < 0 ? l(topTen) : originalIndex; while (i > 0 && count >= toLong(map.get(topTen.get(i-1)))) --i; if (i >= topTenTargetLength || i == originalIndex) ret; if (originalIndex >= 0) topTen.remove(originalIndex); topTen.add(i, word); truncateList(topTen, topTenTargetLength); } svoid printTopTen { printAsciiHeading("TOP TEN"); pnl(map(topTen, func(S s) { s + " - " + map.get(s) })); } answer { if "clear top ten" { topTen.clear(); ret "OK"; } addWordHits(words2(s)); printTopTen(); try answer "OK"; }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009446 |
Snippet name: | Word Collector [dev.] |
Eternal ID of this version: | #1009446/11 |
Text MD5: | 0cac6d447dae1639cd2808c5528f3bc9 |
Transpilation MD5: | 48a03185531cc8435480f4dceff14269 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-01 20:51:03 |
Source code size: | 1187 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 568 / 710 |
Version history: | 10 change(s) |
Referenced in: | -