aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/test/thread_meets.cpp
blob: 607179c53f992bdaf5cfce0d680058a387d42fb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "thread_meets.h"

namespace vespalib::test {

void
ThreadMeets::Nop::mingle()
{
}

void
ThreadMeets::Avg::mingle()
{
    double sum = 0;
    for (size_t i = 0; i < size(); ++i) {
        sum += in(i);
    }
    double result = sum / size();
    for (size_t i = 0; i < size(); ++i) {
        out(i) = result;
    }
}

void
ThreadMeets::Vote::mingle()
{
    size_t true_cnt = 0;
    size_t false_cnt = 0;
    for (size_t i = 0; i < size(); ++i) {
        if (in(i)) {
            ++true_cnt;
        } else {
            ++false_cnt;
        }
    }
    bool result = (true_cnt > false_cnt);
    for (size_t i = 0; i < size(); ++i) {
        out(i) = result;
    }
}

}