aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/tests/ann/for-sift-top-k.h
blob: b122e21c8f61a65a2fc355e4f6ac6e6da76b86e2 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

struct TopK {
    static constexpr size_t K = 100;
    Hit hits[K];

    size_t recall(const TopK &other) const {
        size_t overlap = 0;
        size_t i = 0;
        size_t j = 0;
        while (i < K && j < K) {
            if (hits[i].docid == other.hits[j].docid) {
                ++overlap;
                ++i;
                ++j;
            } else if (hits[i].distance < other.hits[j].distance) {
                ++i;
            } else {
                ++j;
            }
        }
        return overlap;
    }
};