!7 static int maxWords = 100000; static int maxWordLength = 10; static int topTenTargetLength = 10; static Map map; static L topTen; p { map = l_persistentTreeMap("Words + count"); topTen = l_persistentList("Top Ten"); } svoid addWordHits(Collection... words) { for (S s : words) { long count = longMultiSet_add(map, word); insertToTopTen(word, count); } } svoid insertToTopTen(S word, long count) { int i = l(topTen); while (i > 0 && count >= toLong(map.get(topTen.get(i-1)))) --i; if (i >= topTenTargetLength) ret; topTen.add(i, word); truncateList(topTen, topTenTargetLength); }