1//===- IndexedValuesMap.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
10#define LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/SmallVector.h"
14#include <cstdint>
15#include <utility>
16
17namespace llvm {
18namespace dwarf_linker {
19
20/// This class stores values sequentually and assigns index to the each value.
21template <typename T> class IndexedValuesMap {
22public:
23 uint64_t getValueIndex(T Value) {
24 typename ValueToIndexMapTy::iterator It = ValueToIndexMap.find(Value);
25 if (It == ValueToIndexMap.end()) {
26 It = ValueToIndexMap.insert(std::make_pair(Value, Values.size())).first;
27 Values.push_back(Value);
28 }
29 return It->second;
30 }
31
32 const SmallVector<T> &getValues() const { return Values; }
33
34 void clear() {
35 ValueToIndexMap.clear();
36 Values.clear();
37 }
38
39 bool empty() { return Values.empty(); }
40
41protected:
42 using ValueToIndexMapTy = DenseMap<T, uint64_t>;
43 ValueToIndexMapTy ValueToIndexMap;
44 SmallVector<T> Values;
45};
46
47} // end of namespace dwarf_linker
48} // end of namespace llvm
49
50#endif // LLVM_DWARFLINKER_INDEXEDVALUESMAP_H
51

source code of llvm/include/llvm/DWARFLinker/IndexedValuesMap.h