Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / ir / OperationIndexSet.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __ONERT_MODEL_OPERATION_INDEX_SET_H__
18 #define __ONERT_MODEL_OPERATION_INDEX_SET_H__
19
20 #include <algorithm>
21 #include <cassert>
22 #include <initializer_list>
23 #include <unordered_set>
24
25 #include "ir/Index.h"
26
27 namespace onert
28 {
29 namespace ir
30 {
31
32 class OperationIndexSet
33 {
34 public:
35   OperationIndexSet(void) = default;
36   OperationIndexSet(std::initializer_list<OperationIndex> list);
37
38 public:
39   void insert(const OperationIndex &index) { _set.insert(index); }
40   void clear(void) { _set.clear(); }
41   void remove(const OperationIndex &index)
42   {
43     auto itr = std::find(_set.begin(), _set.end(), index);
44     assert(itr != _set.end());
45     _set.erase(itr);
46   }
47
48 public:
49   uint32_t size() const { return static_cast<uint32_t>(_set.size()); }
50   bool contains(const OperationIndex &index) const;
51
52 public:
53   std::unordered_set<OperationIndex>::iterator begin(void) { return _set.begin(); }
54   std::unordered_set<OperationIndex>::iterator end(void) { return _set.end(); }
55   std::unordered_set<OperationIndex>::const_iterator begin(void) const { return _set.begin(); }
56   std::unordered_set<OperationIndex>::const_iterator end(void) const { return _set.end(); }
57
58 private:
59   std::unordered_set<OperationIndex> _set;
60 };
61
62 } // namespace ir
63 } // namespace onert
64
65 #endif // __ONERT_MODEL_OPERATION_INDEX_SET_H__