// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Runtime.CompilerServices; namespace SixLabors.Fonts { /// /// Provides a 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 MappedArraySlice where T : struct { private readonly ArraySlice data; private readonly ArraySlice map; /// /// Initializes a new instance of the struct. /// /// The data slice. /// The map slice. public MappedArraySlice(in ArraySlice data, in ArraySlice 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 ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref this.data[this.map[index]]; } } }