| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="IntegerSequence.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | namespace MyNet.Primitives.Sequences; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// A simple sequence generator. Note: it is NOT thread-safe. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// Initializes a new instance of the <see cref="IntegerSequence"/> class. |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <param name="seed">The sequence initial value.</param> |
| | | 16 | | public class IntegerSequence(uint seed) : ISequence<uint> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the <see cref="IntegerSequence"/> class. |
| | | 20 | | /// The sequence's initial current value is 0. |
| | | 21 | | /// </summary> |
| | | 22 | | public IntegerSequence() |
| | 6 | 23 | | : this(0u) { } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets this sequence's current value. |
| | | 27 | | /// </summary> |
| | | 28 | | public uint CurrentValue { get; private set; } = seed; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets computes and retrieves this sequence's next value. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <remarks> |
| | | 34 | | /// When called, the value of <see cref="CurrentValue"/> is updated. |
| | | 35 | | /// </remarks> |
| | 6 | 36 | | public uint NextValue => ++CurrentValue; |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Sets the current value to the specified value. |
| | | 40 | | /// Subsequent call to <see cref="NextValue"/> will return this <paramref name="value"/> + 1. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <param name="value">The new sequence current value.</param> |
| | 3 | 43 | | public void SetCurrentValue(uint value) => CurrentValue = value; |
| | | 44 | | } |
| | | 45 | | |