Home

Util.Dif issue?

I wrote the following program and it seems to me that the method Util.Dif() doesn't work properly with the array.
Is this the case?

void Main()
{
var rna1 = GenerateRandomBytes(32);
var rna2 = RandomNumberGenerator.GetBytes(32);

new { Row = string.Join(", ", rna1) }.Dump();
new { Row = string.Join(", ", rna2) }.Dump();

Util.HorizontalRun(true, rna1, rna2).Dump();
Util.Dif(rna1, rna2).Dump();

}

public static byte[] GenerateRandomBytes(int length)
{
using var rng = RandomNumberGenerator.Create();
var randomBytes = new byte[length];
rng.GetBytes(randomBytes);
return randomBytes;
}

Comments

  • edited December 2024

    If rows are completely different works as expected:

    void Main()
    {
        // TODO: Set both to the 1 to get strange result.
        const int firstRowIndex  = 1;
        const int secondRowIndex = 2;
    
        var rna1 = GenerateRandomBytes(32, firstRowIndex);
        var rna2 = GenerateRandomBytes(32, secondRowIndex);
    
        Util.Pivot(rna1).Dump();
        Util.Pivot(rna2).Dump();
    
        Util.Dif(rna1, rna2).Dump();
    }
    
    public static int[] GenerateRandomBytes(int length, int row)
    {
        using var rng = System.Security.Cryptography.RandomNumberGenerator.Create();
        var randomBytes = new byte[length];
        rng.GetBytes(randomBytes);
    
        return randomBytes.Select(i => row*1000+i).ToArray();
    }
    
  • 1039 exists in both. Why it compares like that?

  • Good point - it shouldn't attempt an element-by-element comparison if the lists are too dissimilar. This has now been fixed in 8.8.1.

Sign In or Register to comment.