Path: blob/main/contrib/llvm-project/compiler-rt/lib/orc/interval_set.h
39566 views
//===--------- interval_set.h - A sorted interval set -----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Implements a coalescing interval set.9//10//===----------------------------------------------------------------------===//1112#ifndef ORC_RT_INTERVAL_SET_H13#define ORC_RT_INTERVAL_SET_H1415#include "interval_map.h"1617namespace __orc_rt {1819/// Implements a coalescing interval set.20///21/// Adjacent intervals are coalesced.22///23/// NOTE: The interface is kept mostly compatible with LLVM's IntervalMap24/// collection to make it easy to swap over in the future if we choose25/// to.26template <typename KeyT, IntervalCoalescing Coalescing>27class IntervalSet {28private:29using ImplMap = IntervalMap<KeyT, std::monostate, Coalescing>;30public:3132using value_type = std::pair<KeyT, KeyT>;3334class const_iterator {35friend class IntervalSet;36public:37using difference_type = typename ImplMap::iterator::difference_type;38using value_type = IntervalSet::value_type;39using pointer = const value_type *;40using reference = const value_type &;41using iterator_category = std::input_iterator_tag;4243const_iterator() = default;44const value_type &operator*() const { return I->first; }45const value_type *operator->() const { return &I->first; }46const_iterator &operator++() { ++I; return *this; }47const_iterator operator++(int) { auto Tmp = I; ++I; return Tmp; }48friend bool operator==(const const_iterator &LHS,49const const_iterator &RHS) {50return LHS.I == RHS.I;51}52friend bool operator!=(const const_iterator &LHS,53const const_iterator &RHS) {54return LHS.I != RHS.I;55}56private:57const_iterator(typename ImplMap::const_iterator I) : I(std::move(I)) {}58typename ImplMap::const_iterator I;59};6061bool empty() const { return Map.empty(); }6263void clear() { Map.clear(); }6465const_iterator begin() const { return const_iterator(Map.begin()); }66const_iterator end() const { return const_iterator(Map.end()); }6768const_iterator find(KeyT K) const {69return const_iterator(Map.find(K));70}7172void insert(KeyT KS, KeyT KE) {73Map.insert(std::move(KS), std::move(KE), std::monostate());74}7576void erase(KeyT KS, KeyT KE) {77Map.erase(KS, KE);78}7980private:81ImplMap Map;82};8384} // End namespace __orc_rt8586#endif // ORC_RT_INTERVAL_SET_H878889