/* * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__ #define __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__ #include #include namespace neurun { namespace backend { class Backend; } // namespace backend } // namespace neurun namespace neurun { namespace graph { namespace operand { class BackendSet { public: BackendSet() = default; BackendSet(std::initializer_list backends); public: void add(const backend::Backend *backend) { _set.insert(backend); } void remove(const backend::Backend *backend) { _set.erase(backend); } uint32_t size() const { return static_cast(_set.size()); } bool empty() const { return _set.empty(); } bool contains(const backend::Backend *backend) const { return _set.find(backend) != _set.end(); } const backend::Backend *getOnlyElement() const; public: BackendSet operator|(const BackendSet &other) const; // Union BackendSet operator&(const BackendSet &other) const; // Intersect BackendSet operator-(const BackendSet &other) const; // Minus public: std::unordered_set::const_iterator begin() const { return _set.begin(); } std::unordered_set::const_iterator end() const { return _set.end(); } private: std::unordered_set _set; }; } // namespace operand } // namespace graph } // namespace neurun #endif // __NEURUN_GRAPH_OPERAND_BACKEND_SET_H__