aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/sort.cpp
blob: 0a4db613649359ee84484e2eac93e42781126aaf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "sort.h"

namespace search {

bool
radix_prepare(size_t n, size_t last[257], size_t ptr[256], size_t cnt[256])
{
    // Accumulate cnt positions
    bool sorted = (cnt[0]==n);
    ptr[0] = 0;
    for(unsigned int i(1); i<256; i++) {
        ptr[i] = ptr[i-1] + cnt[i-1];
        sorted |= (cnt[i]==n);
    }
    memcpy(last, ptr, 256*sizeof(last[0]));
    last[256] = last[255] + cnt[255];
    return sorted;
}

}