use of water.util.IcedLong in project h2o-3 by h2oai.
the class WordCountTaskTest method testWordCountText8.
@Test
public void testWordCountText8() {
String fName = "bigdata/laptop/text8.gz";
// only run if text8 is present
assumeThat("text8 data available", locateFile(fName), is(notNullValue()));
Frame fr = parse_test_file(fName, "NA", 0, new byte[] { Vec.T_STR });
try {
Map<BufferedString, IcedLong> counts = new WordCountTask().doAll(fr.vec(0))._counts;
assertEquals(253854, counts.size());
assertEquals(303L, counts.get(new BufferedString("anarchism"))._val);
assertEquals(316376L, counts.get(new BufferedString("to"))._val);
assertNotNull(counts);
} finally {
fr.remove();
}
}
use of water.util.IcedLong in project h2o-3 by h2oai.
the class WordCountTaskTest method testWordCount.
@Test
public void testWordCount() {
String[] strData = new String[10000];
for (int i = 0; i < strData.length; i++) {
int b = i % 10;
if (b < 3)
strData[i] = "A";
else if (b < 5)
strData[i] = "B";
else
strData[i] = "C";
}
Frame fr = new TestFrameBuilder().withName("data").withColNames("Str").withVecTypes(Vec.T_STR).withDataForCol(0, strData).withChunkLayout(100, 900, 5000, 4000).build();
try {
Map<BufferedString, IcedLong> counts = new WordCountTask().doAll(fr.vec(0))._counts;
assertEquals(3, counts.size());
assertEquals(3000L, counts.get(new BufferedString("A"))._val);
assertEquals(2000L, counts.get(new BufferedString("B"))._val);
assertEquals(5000L, counts.get(new BufferedString("C"))._val);
System.out.println(counts);
} finally {
fr.remove();
}
}
use of water.util.IcedLong in project h2o-3 by h2oai.
the class CreateInteractions method mySort.
private static Map<Long, Long> mySort(Map<IcedLong, IcedLong> unsortMap) {
List<Map.Entry<IcedLong, IcedLong>> list = new LinkedList<>(unsortMap.entrySet());
// Sorting the list based on values
Collections.sort(list, new Comparator<Map.Entry<IcedLong, IcedLong>>() {
public int compare(Map.Entry<IcedLong, IcedLong> o1, Map.Entry<IcedLong, IcedLong> o2) {
return ((Long) o2.getValue()._val).compareTo(o1.getValue()._val);
}
});
// Maintaining insertion order with the help of LinkedList
Map sortedMap = new LinkedHashMap<>();
for (Map.Entry<IcedLong, IcedLong> entry : list) {
sortedMap.put(entry.getKey()._val, entry.getValue()._val);
}
return sortedMap;
}
Aggregations