]> git.sesse.net Git - stockfish/blob - src/nnue/features/index_list.h
Avoid special casing for MinGW
[stockfish] / src / nnue / features / index_list.h
1 /*
2   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3   Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
4
5   Stockfish is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   Stockfish is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // Definition of index list of input features
20
21 #ifndef NNUE_FEATURES_INDEX_LIST_H_INCLUDED
22 #define NNUE_FEATURES_INDEX_LIST_H_INCLUDED
23
24 #include "../../position.h"
25 #include "../nnue_architecture.h"
26
27 namespace Eval::NNUE::Features {
28
29   // Class template used for feature index list
30   template <typename T, std::size_t MaxSize>
31   class ValueList {
32
33    public:
34     std::size_t size() const { return size_; }
35     void resize(std::size_t size) { size_ = size; }
36     void push_back(const T& value) { values_[size_++] = value; }
37     T& operator[](std::size_t index) { return values_[index]; }
38     T* begin() { return values_; }
39     T* end() { return values_ + size_; }
40     const T& operator[](std::size_t index) const { return values_[index]; }
41     const T* begin() const { return values_; }
42     const T* end() const { return values_ + size_; }
43
44     void swap(ValueList& other) {
45       const std::size_t max_size = std::max(size_, other.size_);
46       for (std::size_t i = 0; i < max_size; ++i) {
47         std::swap(values_[i], other.values_[i]);
48       }
49       std::swap(size_, other.size_);
50     }
51
52    private:
53     T values_[MaxSize];
54     std::size_t size_ = 0;
55   };
56
57   //Type of feature index list
58   class IndexList
59       : public ValueList<IndexType, RawFeatures::kMaxActiveDimensions> {
60   };
61
62 }  // namespace Eval::NNUE::Features
63
64 #endif // NNUE_FEATURES_INDEX_LIST_H_INCLUDED