// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.CompilerServices;
namespace SixLabors.Fonts {
///
/// Provides a readonly mapped view of an underlying slice, selecting arbitrary indices
/// from the source array.
///
/// The type of item contained in the underlying array.
internal readonly struct ReadonlyMappedArraySlice
where T : struct
{
private readonly ReadOnlyArraySlice data;
private readonly ReadOnlyArraySlice map;
///
/// Initializes a new instance of the struct.
///
/// The data slice.
/// The map slice.
public ReadonlyMappedArraySlice(in ReadOnlyArraySlice data, in ReadOnlyArraySlice map)
{
Guard.MustBeGreaterThanOrEqualTo(data.Length, map.Length, nameof(map));
this.data = data;
this.map = map;
}
///
/// Gets the number of items in the map.
///
public int Length => this.map.Length;
///
/// Returns a reference to specified element of the slice.
///
/// The index of the element to return.
/// The .
///
/// Thrown when index less than 0 or index greater than or equal to .
///
public readonly T this[int index]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.data[this.map[index]];
}
}
}