GameplayTags
GameplayTags copied to clipboard
HasAnyExact return true instead of false
Hello!
I've noticed HasAnyExact returned the wrong result in this scenario:
- ContainerA contains TagA.TagB
- ContainerB contains TagA.TagC and TagA.TagD
If I do ContainerA.HasAnyExact(ContainerB), it returns true instead of false. I peeked a little at the code and it seems the only issue is that HasAnyInternal returns true by default instead of false. In the example above, i value is superior to end value therefore the loop is skipped and it will return true even if no match was found. As I didn't at the whole codebase, I might be overlooking something.
(Here is the function I'm talking about)
private static bool HasAnyInternal(List<int> tagIndexes, List<int> otherTagIndexes)
{
if (otherTagIndexes == null || otherTagIndexes.Count == 0 || tagIndexes == null || tagIndexes.Count == 0)
{
return false;
}
int start = BinarySearchUtility.Search(tagIndexes, otherTagIndexes[0], 0, tagIndexes.Count - 1);
if (start >= 0)
{
return true;
}
start = ~start;
int end = BinarySearchUtility.Search(tagIndexes, otherTagIndexes[^1], start, tagIndexes.Count - 1);
if (end >= 0)
{
return true;
}
end = ~end;
int j = 1;
int i = start + 1;
while (i < end && j < otherTagIndexes.Count)
{
if (otherTagIndexes[j] == tagIndexes[i])
{
return true;
}
if (tagIndexes[i] > otherTagIndexes[j])
{
i++;
continue;
}
j++;
while (otherTagIndexes[j] < tagIndexes[i])
{
j++;
if (j == end)
{
return false;
}
}
}
// I believe this should return false by default
return true;
}
Have a nice day!
I’m traveling, so I’ll fix it when I return home. Thanks for opening the issue!