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¶
- The protected base constructor stores
startValueinCurrentValue.Sequenceadditionally callsSetValue(startValue)(a redundant re-assignment);LongSequencedoes not. (BR-065) - Reading
NextValueincrementsCurrentValueby 1 first and returns the incremented value — with a start value of 0 the first value handed out is 1. (BR-066) SetValue(T)repositions the counter to an arbitrary value. (BR-065)Reset()setsCurrentValueback to literal0in 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/longoverflow wraps silently in the default unchecked context.*
Related documentation¶
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.csCommon/SAIF.Common/Classes/Sequence.csCommon/SAIF.Common/Classes/LongSequence.cs