File: common.hpp

package info (click to toggle)
rapidfuzz-cpp 3.1.1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 2,444 kB
  • sloc: cpp: 30,295; python: 63; makefile: 26; sh: 8
file content (38 lines) | stat: -rw-r--r-- 659 bytes parent folder | download | duplicates (2)
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
/* SPDX-License-Identifier: MIT */
/* Copyright © 2021 Max Bachmann */

#pragma once
#include <algorithm>

namespace rapidfuzz_reference {

template <typename T>
class Matrix {
public:
    Matrix(size_t _rows, size_t _cols) : rows(_rows), cols(_cols)
    {
        matrix = new T[rows * cols];
        std::fill(matrix, matrix + rows * cols, T());
    }

    ~Matrix()
    {
        delete[] matrix;
    }

    T& operator()(size_t row, size_t col)
    {
        return matrix[row + col * rows];
    }

    T& back()
    {
        return matrix[rows * cols - 1];
    }

    size_t rows;
    size_t cols;
    T* matrix;
};

} // namespace rapidfuzz_reference