powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Как используется combiner в Stream#reduce ?
3 сообщений из 3, страница 1 из 1
Как используется combiner в Stream#reduce ?
    #39062140
questioner
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Собсно читал вот этот топик: http://stackoverflow.com/q/22808485/2674303


Один из вариантов сигнатуры метода reduce выглядит следующим образом:

Код: java
1.
2.
3.
<U> U reduce(U identity,
                 BiFunction<U, ? super T, U> accumulator,
                 BinaryOperator<U> combiner);




По представленной выше ссылке я понял, что combiner не вызывается для не параллельных стримов.

У меня вопрос немного другой. Как combiner используется когда у нас параллельный стрим и как вообще весь reduce происходит. В чем concept ?

P.S.
Исходники не поддаются моему пониманию.
...
Рейтинг: 0 / 0
Как используется combiner в Stream#reduce ?
    #39062161
chabapok
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
questioner,

Насколько я понял. Результаты в каждом потоке объединятся через accumulator, после чего результаты из разных потоков объединяются через combiner.

http://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#Reduction

Here, the identity element is both an initial seed value for the reduction and a default result if there are no input elements. The accumulator function takes a partial result and the next element, and produces a new partial result. The combiner function combines two partial results to produce a new partial result. (The combiner is necessary in parallel reductions, where the input is partitioned, a partial accumulation computed for each partition, and then the partial results are combined to produce a final result.)
...
Рейтинг: 0 / 0
Как используется combiner в Stream#reduce ?
    #39062226
questioner
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
chabapokquestioner,

Насколько я понял. Результаты в каждом потоке объединятся через accumulator, после чего результаты из разных потоков объединяются через combiner.

http://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#Reduction

Here, the identity element is both an initial seed value for the reduction and a default result if there are no input elements. The accumulator function takes a partial result and the next element, and produces a new partial result. The combiner function combines two partial results to produce a new partial result. (The combiner is necessary in parallel reductions, where the input is partitioned, a partial accumulation computed for each partition, and then the partial results are combined to produce a final result.)

Спасибо) очень похоже на правду
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Как используется combiner в Stream#reduce ?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]