1 //===- IndexedValuesMap.h ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/SmallVector.h"
18 namespace dwarflinker_parallel
{
20 template <typename T
> class IndexedValuesMap
{
22 uint64_t getValueIndex(T Value
) {
23 typename
ValueToIndexMapTy::iterator It
= ValueToIndexMap
.find(Value
);
24 if (It
== ValueToIndexMap
.end()) {
25 It
= ValueToIndexMap
.insert(std::make_pair(Value
, Values
.size())).first
;
26 Values
.push_back(Value
);
31 const SmallVector
<T
> &getValues() { return Values
; }
34 ValueToIndexMap
.clear();
38 bool empty() { return Values
.empty(); }
41 using ValueToIndexMapTy
= DenseMap
<T
, uint64_t>;
42 ValueToIndexMapTy ValueToIndexMap
;
43 SmallVector
<T
> Values
;
46 } // end of namespace dwarflinker_parallel
47 } // end namespace llvm
49 #endif // LLVM_LIB_DWARFLINKERPARALLEL_INDEXEDVALUESMAP_H