| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | // See the LICENSE file in the project root for more information. |
| | | 4 | | |
| | | 5 | | using System.Numerics.Hashing; |
| | | 6 | | using System.ComponentModel; |
| | | 7 | | |
| | | 8 | | namespace System |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Represents position in non-contiguous set of memory. |
| | | 12 | | /// Properties of this type should not be interpreted by anything but the type that created it. |
| | | 13 | | /// </summary> |
| | | 14 | | public readonly struct SequencePosition : IEquatable<SequencePosition> |
| | | 15 | | { |
| | | 16 | | private readonly object _object; |
| | | 17 | | private readonly int _integer; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Creates new <see cref="SequencePosition"/> |
| | | 21 | | /// </summary> |
| | | 22 | | public SequencePosition(object @object, int integer) |
| | 1 | 23 | | { |
| | 1 | 24 | | _object = @object; |
| | 1 | 25 | | _integer = integer; |
| | 1 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Returns object part of this <see cref="SequencePosition"/> |
| | | 30 | | /// </summary> |
| | | 31 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1 | 32 | | public object GetObject() => _object; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Returns integer part of this <see cref="SequencePosition"/> |
| | | 36 | | /// </summary> |
| | | 37 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1 | 38 | | public int GetInteger() => _integer; |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Returns true if left and right point at the same segment and have the same index. |
| | | 42 | | /// </summary> |
| | 1 | 43 | | public static bool operator ==(SequencePosition left, SequencePosition right) => left._integer== right._integer |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Returns true if left and right do not point at the same segment and have the same index. |
| | | 47 | | /// </summary> |
| | 1 | 48 | | public static bool operator !=(SequencePosition left, SequencePosition right) => !(left == right); |
| | | 49 | | |
| | | 50 | | /// <inheritdoc /> |
| | 1 | 51 | | public bool Equals(SequencePosition position) => this == position; |
| | | 52 | | |
| | | 53 | | /// <inheritdoc /> |
| | | 54 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1 | 55 | | public override bool Equals(object obj) => obj is SequencePosition other && this == other; |
| | | 56 | | |
| | | 57 | | /// <inheritdoc /> |
| | | 58 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 1 | 59 | | public override int GetHashCode() => HashHelpers.Combine(_object?.GetHashCode() ?? 0, _integer); |
| | | 60 | | } |
| | | 61 | | } |