Skip to content

Commit 1a3254f

Browse files
[PBQP] Add begin and end to Vector (NFC)
This patch adds begin and end to Vector. The new functions will allow us to use llvm::interleaved in operator<< for example.
1 parent c2d6c7c commit 1a3254f

File tree

1 file changed

+11
-6
lines changed
  • llvm/include/llvm/CodeGen/PBQP

1 file changed

+11
-6
lines changed

llvm/include/llvm/CodeGen/PBQP/Math.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ class Vector {
4848
V.Length = 0;
4949
}
5050

51+
// Iterator-based access.
52+
const PBQPNum *begin() const { return Data.get(); }
53+
const PBQPNum *end() const { return Data.get() + Length; }
54+
PBQPNum *begin() { return Data.get(); }
55+
PBQPNum *end() { return Data.get() + Length; }
56+
5157
/// Comparison operator.
5258
bool operator==(const Vector &V) const {
5359
assert(Length != 0 && Data && "Invalid vector");
5460
if (Length != V.Length)
5561
return false;
56-
return std::equal(Data.get(), Data.get() + Length, V.Data.get());
62+
return std::equal(begin(), end(), V.begin());
5763
}
5864

5965
/// Return the length of the vector
@@ -80,15 +86,14 @@ class Vector {
8086
Vector& operator+=(const Vector &V) {
8187
assert(Length != 0 && Data && "Invalid vector");
8288
assert(Length == V.Length && "Vector length mismatch.");
83-
std::transform(Data.get(), Data.get() + Length, V.Data.get(), Data.get(),
84-
std::plus<PBQPNum>());
89+
std::transform(begin(), end(), V.begin(), begin(), std::plus<PBQPNum>());
8590
return *this;
8691
}
8792

8893
/// Returns the index of the minimum value in this vector
8994
unsigned minIndex() const {
9095
assert(Length != 0 && Data && "Invalid vector");
91-
return std::min_element(Data.get(), Data.get() + Length) - Data.get();
96+
return llvm::min_element(*this) - begin();
9297
}
9398

9499
private:
@@ -98,8 +103,8 @@ class Vector {
98103

99104
/// Return a hash_value for the given vector.
100105
inline hash_code hash_value(const Vector &V) {
101-
unsigned *VBegin = reinterpret_cast<unsigned*>(V.Data.get());
102-
unsigned *VEnd = reinterpret_cast<unsigned*>(V.Data.get() + V.Length);
106+
const unsigned *VBegin = reinterpret_cast<const unsigned *>(V.begin());
107+
const unsigned *VEnd = reinterpret_cast<const unsigned *>(V.end());
103108
return hash_combine(V.Length, hash_combine_range(VBegin, VEnd));
104109
}
105110

0 commit comments

Comments
 (0)