Exemple #1
0
        private unsafe void TestIndexOfWorksForAllLocations(ref ReadableBuffer readBuffer, byte emptyValue)
        {
            byte          huntValue  = (byte)~emptyValue;
            Vector <byte> huntVector = new Vector <byte>(huntValue);

            // we're going to fully index the final locations of the buffer, so that we
            // can mutate etc in constant time
            var addresses = BuildPointerIndex(ref readBuffer);

            // check it isn't there to start with
            var found = readBuffer.IndexOf(ref huntVector);

            Assert.True(found == ReadCursor.NotFound);

            // correctness test all values
            for (int i = 0; i < readBuffer.Length; i++)
            {
                *addresses[i] = huntValue;
                found = readBuffer.IndexOf(ref huntVector);
                *addresses[i] = emptyValue;

                Assert.True(found != ReadCursor.NotFound);
                var slice = readBuffer.Slice(found);
                Assert.True(slice.FirstSpan.UnsafePointer == addresses[i]);
            }
        }