Skip to content

Fix CharSegment Equals #136

@uselessgoddess

Description

@uselessgoddess

CharSegment has bug in Equals method

public override bool Equals(Segment<char> other)
{
bool contentEqualityComparer(IList<char> left, IList<char> right)
{
// Base can be not an array, but still IList<char>
if (Base is char[] baseArray && other.Base is char[] otherArray)
{
return baseArray.ContentEqualTo(Offset, Length, otherArray, other.Offset);
}
else
{
return left.ContentEqualTo(right);
}
}
return this.EqualTo(other, contentEqualityComparer);
}

Fix it
Small example [use this sandbox and add property PublicDictionary to Walker4]:

/*
public IDictionary<CharSegment, long> PublicDictionary
{
    get => Dictionary;
}
*/

var text = "aaaaaaaaaa";
var walker = new Walker4();
walker.WalkAll(text);
foreach (var l in walker.PublicDictionary)
{
    foreach (var r in walker.PublicDictionary)
    {
        Console.WriteLine($"{l} == {r} ==> {l.Key.Equals(r.Key)}");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghigh priorityThis issue requires immediate execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions