File indexing completed on 2026-05-10 08:43:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef LLVM_ADT_INDEXEDMAP_H
0021 #define LLVM_ADT_INDEXEDMAP_H
0022
0023 #include "llvm/ADT/SmallVector.h"
0024 #include "llvm/ADT/STLExtras.h"
0025 #include "llvm/ADT/identity.h"
0026 #include <cassert>
0027
0028 namespace llvm {
0029
0030 template <typename T, typename ToIndexT = identity<unsigned>>
0031 class IndexedMap {
0032 using IndexT = typename ToIndexT::argument_type;
0033
0034
0035
0036 using StorageT = SmallVector<T, 0>;
0037
0038 StorageT storage_;
0039 T nullVal_;
0040 ToIndexT toIndex_;
0041
0042 public:
0043 IndexedMap() : nullVal_(T()) {}
0044
0045 explicit IndexedMap(const T& val) : nullVal_(val) {}
0046
0047 typename StorageT::reference operator[](IndexT n) {
0048 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
0049 return storage_[toIndex_(n)];
0050 }
0051
0052 typename StorageT::const_reference operator[](IndexT n) const {
0053 assert(toIndex_(n) < storage_.size() && "index out of bounds!");
0054 return storage_[toIndex_(n)];
0055 }
0056
0057 void reserve(typename StorageT::size_type s) {
0058 storage_.reserve(s);
0059 }
0060
0061 void resize(typename StorageT::size_type s) {
0062 storage_.resize(s, nullVal_);
0063 }
0064
0065 void clear() {
0066 storage_.clear();
0067 }
0068
0069 void grow(IndexT n) {
0070 unsigned NewSize = toIndex_(n) + 1;
0071 if (NewSize > storage_.size())
0072 resize(NewSize);
0073 }
0074
0075 bool inBounds(IndexT n) const {
0076 return toIndex_(n) < storage_.size();
0077 }
0078
0079 typename StorageT::size_type size() const {
0080 return storage_.size();
0081 }
0082 };
0083
0084 }
0085
0086 #endif