fixed code style
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include<vector>
|
||||
#include<map>
|
||||
#include<unordered_set>
|
||||
#include<string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <numeric>
|
||||
|
||||
#include "range_structures.h"
|
||||
@@ -17,9 +17,7 @@ static vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const
|
||||
{
|
||||
uint64_t rightPart = dim2.start + j * dim2.step;
|
||||
if (leftPart == rightPart)
|
||||
{
|
||||
return { i, j };
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@@ -30,9 +28,8 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
|
||||
{
|
||||
vector<uint64_t> partSolution = FindParticularSolution(dim1, dim2);
|
||||
if (partSolution.empty())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t x0 = partSolution[0], y0 = partSolution[1];
|
||||
/* x = x_0 + c * t */
|
||||
/* y = y_0 + d * t */
|
||||
@@ -46,9 +43,8 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
|
||||
int64_t tMin = max(tXMin, tYMin);
|
||||
uint64_t tMax = min(tXMax, tYMax);
|
||||
if (tMin > tMax)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint64_t start3 = dim1.start + x0 * dim1.step;
|
||||
uint64_t step3 = c * dim1.step;
|
||||
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 };
|
||||
@@ -60,15 +56,13 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
||||
{
|
||||
ArrayDimension* intersection = DimensionIntersection(dim1, dim2);
|
||||
if (!intersection)
|
||||
{
|
||||
return { dim1 };
|
||||
}
|
||||
|
||||
vector<ArrayDimension> result;
|
||||
/* add the part before intersection */
|
||||
if (dim1.start < intersection->start)
|
||||
{
|
||||
if (dim1.start < intersection->start)
|
||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step });
|
||||
}
|
||||
|
||||
/* add the parts between intersection steps */
|
||||
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
||||
uint64_t interValue = intersection->start;
|
||||
@@ -103,11 +97,11 @@ static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const A
|
||||
vector<ArrayDimension> res;
|
||||
ArrayDimension* inter = DimensionIntersection(dim1, dim2);
|
||||
if (!inter)
|
||||
{
|
||||
return { dim1, dim2 };
|
||||
}
|
||||
|
||||
res.push_back(*inter);
|
||||
delete(inter);
|
||||
|
||||
vector<ArrayDimension> diff1, diff2;
|
||||
diff1 = DimensionDifference(dim1, dim2);
|
||||
diff2 = DimensionDifference(dim2, dim1);
|
||||
@@ -118,29 +112,24 @@ static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const A
|
||||
|
||||
static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
|
||||
{
|
||||
if (firstElement.empty() || secondElement.empty()) {
|
||||
if (firstElement.empty() || secondElement.empty())
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t dimAmount = firstElement.size();
|
||||
/* check if there is no intersecction */
|
||||
for (size_t i = 0; i < dimAmount; i++)
|
||||
{
|
||||
if (FindParticularSolution(firstElement[i], secondElement[i]).empty()) {
|
||||
if (FindParticularSolution(firstElement[i], secondElement[i]).empty())
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
vector<ArrayDimension> result(dimAmount);
|
||||
for (size_t i = 0; i < dimAmount; i++)
|
||||
{
|
||||
ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]);
|
||||
if (resPtr)
|
||||
{
|
||||
result[i] = *resPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -148,15 +137,14 @@ static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>&
|
||||
static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement,
|
||||
const vector<ArrayDimension>& secondElement)
|
||||
{
|
||||
if (firstElement.empty() || secondElement.empty()) {
|
||||
if (firstElement.empty() || secondElement.empty())
|
||||
return {};
|
||||
}
|
||||
|
||||
vector<ArrayDimension> intersection = ElementsIntersection(firstElement, secondElement);
|
||||
vector<vector<ArrayDimension>> result;
|
||||
if (intersection.empty())
|
||||
{
|
||||
return { firstElement };
|
||||
}
|
||||
|
||||
for (int i = 0; i < firstElement.size(); i++)
|
||||
{
|
||||
auto dimDiff = DimensionDifference(firstElement[i], secondElement[i]);
|
||||
@@ -212,9 +200,8 @@ void AccessingSet::FindCoveredBy(const vector<ArrayDimension>& element, vector<v
|
||||
for (const auto& currentElement : allElements)
|
||||
{
|
||||
auto intersection = ElementsIntersection(element, currentElement);
|
||||
if (!intersection.empty()) {
|
||||
if (!intersection.empty())
|
||||
result.push_back(intersection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,13 +216,11 @@ void AccessingSet::Insert(const vector<ArrayDimension>& element)
|
||||
|
||||
AccessingSet AccessingSet::Union(const AccessingSet& source) {
|
||||
AccessingSet result;
|
||||
for (auto& element : source.GetElements()) {
|
||||
for (auto& element : source.GetElements())
|
||||
result.Insert(element);
|
||||
}
|
||||
|
||||
for (auto& element : allElements)
|
||||
{
|
||||
result.Insert(element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -244,22 +229,20 @@ AccessingSet AccessingSet::Intersect(const AccessingSet& secondSet) const
|
||||
vector<vector<ArrayDimension>> result;
|
||||
if (secondSet.GetElements().empty() || this->allElements.empty())
|
||||
return AccessingSet(result);
|
||||
|
||||
for (const auto& element : allElements)
|
||||
{
|
||||
if (secondSet.ContainsElement(element))
|
||||
{
|
||||
result.push_back(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<vector<ArrayDimension>> coveredBy;
|
||||
secondSet.FindCoveredBy(element, coveredBy);
|
||||
if (!coveredBy.empty())
|
||||
{
|
||||
result.insert(result.end(), coveredBy.begin(), coveredBy.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AccessingSet(result);
|
||||
}
|
||||
|
||||
@@ -267,6 +250,7 @@ AccessingSet AccessingSet::Diff(const AccessingSet& secondSet) const
|
||||
{
|
||||
if (secondSet.GetElements().empty() || allElements.empty())
|
||||
return *this;
|
||||
|
||||
AccessingSet intersection = this->Intersect(secondSet);
|
||||
AccessingSet uncovered = *this;
|
||||
vector<vector<ArrayDimension>> result;
|
||||
@@ -288,30 +272,21 @@ bool operator!=(const ArrayDimension& lhs, const ArrayDimension& rhs)
|
||||
bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs)
|
||||
{
|
||||
for (size_t i = 0; i < lhs.allElements.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < lhs.allElements[i].size(); j++)
|
||||
{
|
||||
if (lhs.allElements[i][j] != rhs.allElements[i][j])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& [key, value] : lhs)
|
||||
{
|
||||
if (rhs.find(key) == rhs.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user