MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / CompareTwoVectors

Function CompareTwoVectors

source/opt/types.cpp:39–66  ·  view source on GitHub ↗

Returns true if the two vector of vectors are identical.

Source from the content-addressed store, hash-verified

37
38// Returns true if the two vector of vectors are identical.
39bool CompareTwoVectors(const U32VecVec a, const U32VecVec b) {
40 const auto size = a.size();
41 if (size != b.size()) return false;
42
43 if (size == 0) return true;
44 if (size == 1) return a.front() == b.front();
45
46 std::vector<const std::vector<uint32_t>*> a_ptrs, b_ptrs;
47 a_ptrs.reserve(size);
48 a_ptrs.reserve(size);
49 for (uint32_t i = 0; i < size; ++i) {
50 a_ptrs.push_back(&a[i]);
51 b_ptrs.push_back(&b[i]);
52 }
53
54 const auto cmp = [](const std::vector<uint32_t>* m,
55 const std::vector<uint32_t>* n) {
56 return m->front() < n->front();
57 };
58
59 std::sort(a_ptrs.begin(), a_ptrs.end(), cmp);
60 std::sort(b_ptrs.begin(), b_ptrs.end(), cmp);
61
62 for (uint32_t i = 0; i < size; ++i) {
63 if (*a_ptrs[i] != *b_ptrs[i]) return false;
64 }
65 return true;
66}
67
68} // namespace
69

Callers 2

HasSameDecorationsMethod · 0.85
IsSameImplMethod · 0.85

Calls 5

frontMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected