well, the location sorter is better, but i don't understand why, kinda by accident, will try to figure it out

This commit is contained in:
Me
2022-08-04 16:45:12 +02:00
parent ca8427262d
commit fce1bcbece
3 changed files with 82 additions and 11 deletions

View File

@@ -71,9 +71,11 @@ public:
// problem is the logic
bool operator<(const LocationConfig& rhs) const
{
size_t len_lhs = 0;
size_t len_rhs = 0;
size_t tmp = 0;
// size_t len_lhs = 0;
// size_t len_rhs = 0;
int len_lhs = 0;
int len_rhs = 0;
// size_t tmp = 0;
// consider adding 1 to path that ends in a file not folder.
@@ -82,8 +84,28 @@ public:
// and /test/test1 is bigger than test
// so we want to count /
len_lhs = _count_chars(this->path);
len_rhs = _count_chars(rhs.path);
// len_lhs = _count_chars(this->path);
// len_rhs = _count_chars(rhs.path);
const char *tmp1 = this->path.c_str();
size_t i = 0;
while (tmp1[i])
{
if (tmp1[i] == '/')
++len_lhs;
++i;
}
const char *tmp2 = rhs.path.c_str();
i = 0;
while (tmp2[i])
{
if (tmp2[i] == '/')
++len_rhs;
++i;
}
/*
while ((tmp = this->path.find_first_of("/", tmp)) != std::string::npos)
@@ -100,11 +122,17 @@ public:
++len_rhs;
}
*/
std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs << (len_lhs < len_rhs) << "\n";
return (len_lhs < len_rhs); // right comparison ? not <= ?
std::cout << "len_lhs: " << len_lhs << " len_rhs: " << len_rhs \
<< " bool res: " << (len_lhs > len_rhs) << "\n";
// i honestly can't tell you how or why but using > rather than <
// fixed all my problems
// the fact that the bool was always 0 before, and the correct order
// i want... super weird...
return (len_lhs > len_rhs); // right comparison ? not <= ?
};
/*
size_t _count_chars(std::string str)
{
const char *tmp = str.c_str();
@@ -120,7 +148,7 @@ public:
return (count);
}
*/
};