dpaukov / combinatoricslib3

Combinatorial objects stream generators for Java.
Apache License 2.0
177 stars 24 forks source link

Return Stream[] or List<Stream> chunks for combinations #22

Open ghYura opened 1 year ago

ghYura commented 1 year ago

Please, implement for all Generators: Return -array[] or -List() of chunked Streams of precalculated (but not yet generated as output) combinations according to input parallel thread number as a divisor for total precalculated number of output combinations, i.g.:

   int n = Runtime.getRuntime().availableProcessors();
   assert n == 8;
   Generator.combination("red", "black", "white", "green", "blue")
       .simple(3)
       .asArrayOfStreamsForGivenThreads(n) //returns Stream[] or List<Stream>
       .stream()
       .parallel()
       .forEach(e->e.forEach(System.out::println));

so, therefore user can process in parallel in chunks:

   [red, black, white] // 0-stream 1st output
   [red, black, green] // 0-stream 2nd output
   [red, black, blue] // 2-stream 1st output
   [red, white, green] // 2-stream 2nd output
   [red, white, blue] // 4-stream 1st output
   [red, green, blue] // 4-stream 2nd output
   [black, white, green] // 1-stream 1st output
   [black, white, blue] // 1-stream 2nd output
   [black, green, blue] // 3-stream 1st output
   [white, green, blue] // 3-stream 2nd output 

   //total output ==10 //out of 5-capacity array or list

(5 streams - since it is best match for given threads divisor 10/8 == Math.ceil(5/4) == 2 (so total output 10/per 2 = 5 element-array or list) for output number of array.length or list.size() but precalculated number of total output ==10) Please note:

  1. It is important, that array Stream[] or List should not be prefilled by output generated data, just chunks of stream to be used for further parallel processing

  2. In Mathmatics, there are some formulas exist for every type of combination (total output number)

Thank you