aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/typed_cells_comparator.h
blob: d1c890be961f49592657677dc13657398d70514b (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/eval/eval/cell_type.h>
#include <vespa/eval/eval/typed_cells.h>
#include <vespa/eval/eval/value_type.h>
#include <cstring>

namespace search::tensor {

/**
 * Comparator used to compare two vespalib::eval::TypedCells instances.
 *
 * The caller must first validate that they are of the same vespalib::eval::ValueType.
 */
class TypedCellsComparator {
private:
    size_t _mem_size;

public:
    TypedCellsComparator(const vespalib::eval::ValueType& type)
        : _mem_size(vespalib::eval::CellTypeUtils::mem_size(type.cell_type(), type.dense_subspace_size()))
    {}
    bool equals(const vespalib::eval::TypedCells& lhs, const vespalib::eval::TypedCells& rhs) const {
        return std::memcmp(lhs.data, rhs.data, _mem_size) == 0;
    }
};

}