2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __ONERT_MODEL_OPERAND_INDEX_SEQUENCE_H__
18 #define __ONERT_MODEL_OPERAND_INDEX_SEQUENCE_H__
20 #include <initializer_list>
36 class OperandIndexSequence
39 OperandIndexSequence(void) = default;
40 OperandIndexSequence(std::initializer_list<OperandIndex> list);
41 OperandIndexSequence(std::initializer_list<int32_t> list);
42 OperandIndexSequence(std::initializer_list<uint32_t> list);
45 void append(const OperandIndex &index) { _vec.emplace_back(index); }
46 void append(const OperandIndexSequence &l) { _vec.insert(_vec.end(), l.begin(), l.end()); }
49 uint32_t size() const { return static_cast<uint32_t>(_vec.size()); }
50 const OperandIndex &at(IOIndex set_index) const { return _vec.at(set_index.value()); }
51 const OperandIndex &at(uint32_t index) const { return _vec.at(index); }
52 bool contains(const OperandIndex &index) const;
53 void replace(const OperandIndex &from, const OperandIndex &to);
54 OperandIndexSequence operator|(ir::Remove filter) const
58 case ir::Remove::DUPLICATED:
60 ir::OperandIndexSequence seq;
61 for (const auto &ind : _vec)
62 if (!seq.contains(ind))
66 case ir::Remove::UNDEFINED:
68 ir::OperandIndexSequence seq;
69 for (const auto &ind : _vec)
79 OperandIndexSequence operator+(const OperandIndexSequence &other) const;
80 friend std::ostream &operator<<(std::ostream &o, const OperandIndexSequence &operand_seq);
83 std::vector<OperandIndex>::const_iterator begin(void) const { return _vec.begin(); }
84 std::vector<OperandIndex>::const_iterator end(void) const { return _vec.end(); }
85 std::vector<OperandIndex>::iterator begin(void) { return _vec.begin(); }
86 std::vector<OperandIndex>::iterator end(void) { return _vec.end(); }
89 std::vector<OperandIndex> _vec;
95 #endif // __ONERT_MODEL_OPERAND_INDEX_SET_H__