Skip to content

Generate the next sequence value

Generate and manage an in-memory monotonic sequence counter, triggered when caller needs a monotonically increasing in-memory counter (e.g. record numbering in a generated file)*.

Field Value
Operation ID OP-028
Trigger Caller needs a monotonically increasing in-memory counter (e.g. record numbering in a generated file)*
Inputs Optional startValue (default 0)
Outputs int / long
Primary components SequenceGenerator<T>` / `Sequence` / `LongSequence` — `NextValue`, `SetValue`, `Reset
Entry point Common/SAIF.Common/Classes/SequenceGenerator.cs

Steps

  1. The protected base constructor stores startValue in CurrentValue. Sequence additionally calls SetValue(startValue) (a redundant re-assignment); LongSequence does not. (BR-065)
  2. Reading NextValue increments CurrentValue by 1 first and returns the incremented value — with a start value of 0 the first value handed out is 1. (BR-066)
  3. SetValue(T) repositions the counter to an arbitrary value. (BR-065)
  4. Reset() sets CurrentValue back to literal 0 in both concrete types — not to the original start value. (BR-067)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Caller creates or uses<br>a sequence generator"]) --> S1["Constructor stores<br>startValue in CurrentValue"]
    S1 --> C1{"Concrete type<br>is Sequence?"}
    C1 -->|Yes| S1a["Also call<br>SetValue(startValue)"]
    C1 -->|No| S1b["LongSequence skips<br>redundant call"]
    S1a --> S2["Caller reads NextValue"]
    S1b --> S2
    S2 --> S3["Increment CurrentValue<br>by 1, then return it"]
    S3 --> C2{"Caller calls<br>SetValue(T)?"}
    C2 -->|Yes| S4["Reposition CurrentValue<br>to arbitrary value"]
    C2 -->|No| C3{"Caller calls<br>Reset()?"}
    C3 -->|Yes| S5["Set CurrentValue back<br>to literal 0"]
    C3 -->|No| End([Counter value returned])
    S4 --> End
    S5 --> End

Failure and edge-case behavior

  • No synchronization — the increment in step 2 is not thread-safe.* No overflow guard; int/long overflow wraps silently in the default unchecked context.*

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • Common/SAIF.Common/Classes/SequenceGenerator.cs
  • Common/SAIF.Common/Classes/Sequence.cs
  • Common/SAIF.Common/Classes/LongSequence.cs