MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / splitList

Method splitList

JSAT/src/jsat/utils/ListUtils.java:37–57  ·  view source on GitHub ↗

This method takes a list and breaks it into count lists backed by the original list, with elements being equally spaced among the lists. The lists will be returned in order of the consecutive values they represent in the source list. NOTE : Because the implementation uses {@li

(List<T> source, int count)

Source from the content-addressed store, hash-verified

35 * @return a lists of lists, each of with the same size with at most a difference of 1.
36 */
37 public static <T> List<List<T>> splitList(List<T> source, int count)
38 {
39 if(count <= 0)
40 throw new RuntimeException("Chunks must be greater then 0, not " + count);
41 List<List<T>> chunks = new ArrayList<List<T>>(count);
42 int baseSize = source.size() / count;
43 int remainder = source.size() % count;
44 int start = 0;
45
46
47 for(int i = 0; i < count; i++)
48 {
49 int end = start+baseSize;
50 if(remainder-- > 0)
51 end++;
52 chunks.add(source.subList(start, end));
53 start = end;
54 }
55
56 return chunks;
57 }
58
59 /**
60 * Returns a new unmodifiable view that is the merging of two lists

Callers 7

testSplitListMethod · 0.95
setUpMethod · 0.95
allNearestNeighborsMethod · 0.95
allEpsNeighborsMethod · 0.95
getKthNeighborStatsMethod · 0.95
estimateBandwidthsMethod · 0.95
updateBetasMethod · 0.95

Calls 2

sizeMethod · 0.65
addMethod · 0.45

Tested by 1

testSplitListMethod · 0.76