/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/ADT/UniqueVector.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- llvm/ADT/UniqueVector.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_ADT_UNIQUEVECTOR_H |
10 | | #define LLVM_ADT_UNIQUEVECTOR_H |
11 | | |
12 | | #include <cassert> |
13 | | #include <cstddef> |
14 | | #include <map> |
15 | | #include <vector> |
16 | | |
17 | | namespace llvm { |
18 | | |
19 | | //===----------------------------------------------------------------------===// |
20 | | /// UniqueVector - This class produces a sequential ID number (base 1) for each |
21 | | /// unique entry that is added. T is the type of entries in the vector. This |
22 | | /// class should have an implementation of operator== and of operator<. |
23 | | /// Entries can be fetched using operator[] with the entry ID. |
24 | | template<class T> class UniqueVector { |
25 | | public: |
26 | | using VectorType = typename std::vector<T>; |
27 | | using iterator = typename VectorType::iterator; |
28 | | using const_iterator = typename VectorType::const_iterator; |
29 | | |
30 | | private: |
31 | | // Map - Used to handle the correspondence of entry to ID. |
32 | | std::map<T, unsigned> Map; |
33 | | |
34 | | // Vector - ID ordered vector of entries. Entries can be indexed by ID - 1. |
35 | | VectorType Vector; |
36 | | |
37 | | public: |
38 | | /// insert - Append entry to the vector if it doesn't already exist. Returns |
39 | | /// the entry's index + 1 to be used as a unique ID. |
40 | 1.46M | unsigned insert(const T &Entry) { |
41 | 1.46M | // Check if the entry is already in the map. |
42 | 1.46M | unsigned &Val = Map[Entry]; |
43 | 1.46M | |
44 | 1.46M | // See if entry exists, if so return prior ID. |
45 | 1.46M | if (Val) return Val1.95k ; |
46 | 1.45M | |
47 | 1.45M | // Compute ID for entry. |
48 | 1.45M | Val = static_cast<unsigned>(Vector.size()) + 1; |
49 | 1.45M | |
50 | 1.45M | // Insert in vector. |
51 | 1.45M | Vector.push_back(Entry); |
52 | 1.45M | return Val; |
53 | 1.45M | } llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::insert(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 40 | 1.45M | unsigned insert(const T &Entry) { | 41 | 1.45M | // Check if the entry is already in the map. | 42 | 1.45M | unsigned &Val = Map[Entry]; | 43 | 1.45M | | 44 | 1.45M | // See if entry exists, if so return prior ID. | 45 | 1.45M | if (Val) return Val0 ; | 46 | 1.45M | | 47 | 1.45M | // Compute ID for entry. | 48 | 1.45M | Val = static_cast<unsigned>(Vector.size()) + 1; | 49 | 1.45M | | 50 | 1.45M | // Insert in vector. | 51 | 1.45M | Vector.push_back(Entry); | 52 | 1.45M | return Val; | 53 | 1.45M | } |
LiveDebugValues.cpp:llvm::UniqueVector<(anonymous namespace)::LiveDebugValues::VarLoc>::insert((anonymous namespace)::LiveDebugValues::VarLoc const&) Line | Count | Source | 40 | 6.42k | unsigned insert(const T &Entry) { | 41 | 6.42k | // Check if the entry is already in the map. | 42 | 6.42k | unsigned &Val = Map[Entry]; | 43 | 6.42k | | 44 | 6.42k | // See if entry exists, if so return prior ID. | 45 | 6.42k | if (Val) return Val1.36k ; | 46 | 5.05k | | 47 | 5.05k | // Compute ID for entry. | 48 | 5.05k | Val = static_cast<unsigned>(Vector.size()) + 1; | 49 | 5.05k | | 50 | 5.05k | // Insert in vector. | 51 | 5.05k | Vector.push_back(Entry); | 52 | 5.05k | return Val; | 53 | 5.05k | } |
llvm::UniqueVector<llvm::Comdat const*>::insert(llvm::Comdat const* const&) Line | Count | Source | 40 | 2.81k | unsigned insert(const T &Entry) { | 41 | 2.81k | // Check if the entry is already in the map. | 42 | 2.81k | unsigned &Val = Map[Entry]; | 43 | 2.81k | | 44 | 2.81k | // See if entry exists, if so return prior ID. | 45 | 2.81k | if (Val) return Val584 ; | 46 | 2.22k | | 47 | 2.22k | // Compute ID for entry. | 48 | 2.22k | Val = static_cast<unsigned>(Vector.size()) + 1; | 49 | 2.22k | | 50 | 2.22k | // Insert in vector. | 51 | 2.22k | Vector.push_back(Entry); | 52 | 2.22k | return Val; | 53 | 2.22k | } |
|
54 | | |
55 | | /// idFor - return the ID for an existing entry. Returns 0 if the entry is |
56 | | /// not found. |
57 | 2.82k | unsigned idFor(const T &Entry) const { |
58 | 2.82k | // Search for entry in the map. |
59 | 2.82k | typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry); |
60 | 2.82k | |
61 | 2.82k | // See if entry exists, if so return ID. |
62 | 2.82k | if (MI != Map.end()) return MI->second; |
63 | 0 | |
64 | 0 | // No luck. |
65 | 0 | return 0; |
66 | 0 | } llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::idFor(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const Line | Count | Source | 57 | 14 | unsigned idFor(const T &Entry) const { | 58 | 14 | // Search for entry in the map. | 59 | 14 | typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry); | 60 | 14 | | 61 | 14 | // See if entry exists, if so return ID. | 62 | 14 | if (MI != Map.end()) return MI->second; | 63 | 0 | | 64 | 0 | // No luck. | 65 | 0 | return 0; | 66 | 0 | } |
llvm::UniqueVector<llvm::Comdat const*>::idFor(llvm::Comdat const* const&) const Line | Count | Source | 57 | 2.81k | unsigned idFor(const T &Entry) const { | 58 | 2.81k | // Search for entry in the map. | 59 | 2.81k | typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry); | 60 | 2.81k | | 61 | 2.81k | // See if entry exists, if so return ID. | 62 | 2.81k | if (MI != Map.end()) return MI->second; | 63 | 0 | | 64 | 0 | // No luck. | 65 | 0 | return 0; | 66 | 0 | } |
|
67 | | |
68 | | /// operator[] - Returns a reference to the entry with the specified ID. |
69 | 200k | const T &operator[](unsigned ID) const { |
70 | 200k | assert(ID-1 < size() && "ID is 0 or out of range!"); |
71 | 200k | return Vector[ID - 1]; |
72 | 200k | } llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::operator[](unsigned int) const Line | Count | Source | 69 | 14 | const T &operator[](unsigned ID) const { | 70 | 14 | assert(ID-1 < size() && "ID is 0 or out of range!"); | 71 | 14 | return Vector[ID - 1]; | 72 | 14 | } |
LiveDebugValues.cpp:llvm::UniqueVector<(anonymous namespace)::LiveDebugValues::VarLoc>::operator[](unsigned int) const Line | Count | Source | 69 | 200k | const T &operator[](unsigned ID) const { | 70 | 200k | assert(ID-1 < size() && "ID is 0 or out of range!"); | 71 | 200k | return Vector[ID - 1]; | 72 | 200k | } |
|
73 | | |
74 | | /// Return an iterator to the start of the vector. |
75 | | iterator begin() { return Vector.begin(); } |
76 | | |
77 | | /// Return an iterator to the start of the vector. |
78 | 4.97k | const_iterator begin() const { return Vector.begin(); } llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::begin() const Line | Count | Source | 78 | 1 | const_iterator begin() const { return Vector.begin(); } |
llvm::UniqueVector<llvm::Comdat const*>::begin() const Line | Count | Source | 78 | 4.97k | const_iterator begin() const { return Vector.begin(); } |
|
79 | | |
80 | | /// Return an iterator to the end of the vector. |
81 | | iterator end() { return Vector.end(); } |
82 | | |
83 | | /// Return an iterator to the end of the vector. |
84 | 4.97k | const_iterator end() const { return Vector.end(); } llvm::UniqueVector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::end() const Line | Count | Source | 84 | 1 | const_iterator end() const { return Vector.end(); } |
llvm::UniqueVector<llvm::Comdat const*>::end() const Line | Count | Source | 84 | 4.97k | const_iterator end() const { return Vector.end(); } |
|
85 | | |
86 | | /// size - Returns the number of entries in the vector. |
87 | 0 | size_t size() const { return Vector.size(); } |
88 | | |
89 | | /// empty - Returns true if the vector is empty. |
90 | | bool empty() const { return Vector.empty(); } |
91 | | |
92 | | /// reset - Clears all the entries. |
93 | | void reset() { |
94 | | Map.clear(); |
95 | | Vector.resize(0, 0); |
96 | | } |
97 | | }; |
98 | | |
99 | | } // end namespace llvm |
100 | | |
101 | | #endif // LLVM_ADT_UNIQUEVECTOR_H |