You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TrustPilotChallenge/dotnet/WhiteRabbit/Word.cs

51 lines
1.3 KiB

namespace WhiteRabbit
{
class Word
{
public byte[] Original;
public long[] Buffers { get; }
public int LengthX4 { get; }
private Word()
{
this.Original = new byte[0];
this.Buffers = new long[128];
this.LengthX4 = 0;
}
public unsafe Word(byte[] word)
{
var tmpWord = new byte[word.Length + 1];
tmpWord[word.Length] = (byte)' ';
for (var i = 0; i < word.Length; i++)
{
tmpWord[i] = word[i];
}
this.Original = tmpWord;
var buffers = new long[128];
fixed (long* buffersPointer = buffers)
{
for (var i = 0; i < 32; i++)
{
var bytePointer = (byte*)(buffersPointer + 4 * i);
var endPointer = bytePointer + 32;
var currentPointer = bytePointer + i;
for (var j = 0; j < tmpWord.Length && currentPointer < endPointer; j++, currentPointer++)
{
*currentPointer = tmpWord[j];
}
}
}
this.Buffers = buffers;
this.LengthX4 = tmpWord.Length * 4;
}
private static Word Empty { get; } = new Word();
}
}