Class ArrivalOrderTracker<TKey>
- Namespace
- FishMMO.Auth.Core.Collections
- Assembly
- FishMMO-ServerAuth.dll
Queue/index tracker that preserves first-seen ordering with O(1) add/remove by key. Useful for TTL sweeps that should process oldest entries first.
public sealed class ArrivalOrderTracker<TKey>
Type Parameters
TKeyTracked key type.
- Inheritance
-
ArrivalOrderTracker<TKey>
- Inherited Members
Remarks
First-seen times are monotonic seconds (a MonotonicClock.NowSeconds reading), never
DateTime.UtcNow: the account manager's backstop sweep ages entries by them, and on the
wall clock a step forward purged every connection mid-sign-in at once while a step back held
abandoned ones for the size of the step. A caller that only wants the order (the login queue)
passes default and ignores the value.
Constructors
ArrivalOrderTracker(IEqualityComparer<TKey>?)
Initializes a new tracker with an optional key comparer.
public ArrivalOrderTracker(IEqualityComparer<TKey>? comparer = null)
Parameters
comparerIEqualityComparer<TKey>
Properties
Count
Current number of tracked keys.
public int Count { get; }
Property Value
Methods
Clear()
Clears all tracked keys.
public void Clear()
Contains(TKey)
Returns true if key is currently tracked.
O(1) via dictionary lookup.
public bool Contains(TKey key)
Parameters
keyTKey
Returns
ForEachInOrder(Action<TKey, double, int>)
Invokes action for each tracked key in FIFO order.
The callback receives the key, its first-seen monotonic time, and its
1-based position. All work is done under the internal lock so the
callback should be fast and must not call back into the tracker.
Returns the total number of entries processed.
public int ForEachInOrder(Action<TKey, double, int> action)
Parameters
actionAction<TKey, double, int>Callback invoked for each entry: (key, firstSeenSeconds, position).
Returns
- int
The total number of entries iterated.
GetPosition(TKey)
Gets the 1-based position of key in the queue.
Returns 0 if the key is not tracked.
O(1) via dictionary+LinkedListNode traversal is NOT possible
(LinkedListNode has no index). This does an O(N) linear scan.
Callers that need per-entry positions for the entire queue
should use ForEachInOrder(Action<TKey, double, int>) instead.
public int GetPosition(TKey key)
Parameters
keyTKey
Returns
PopOldest(out TKey, out double)
Removes and returns the oldest tracked key.
public bool PopOldest(out TKey key, out double firstSeenSeconds)
Parameters
keyTKeyThe removed key, if one existed.
firstSeenSecondsdoubleThe first-seen monotonic time of the removed key.
Returns
- bool
trueif a key was removed; otherwise,false.
Remove(TKey)
Removes a tracked key if present. O(1) via Dictionary→LinkedListNode lookup.
public bool Remove(TKey key)
Parameters
keyTKeyThe key to remove.
Returns
- bool
trueif the key was found and removed; otherwise,false.
TrackIfMissing(TKey, double)
Adds a key only if it is not already tracked.
public void TrackIfMissing(TKey key, double firstSeenSeconds)
Parameters
keyTKeyThe key to track.
firstSeenSecondsdoubleThe monotonic time, in seconds, to record as first-seen.
TryPeekOldest(out TKey, out double)
Gets the oldest tracked key without removing it.
public bool TryPeekOldest(out TKey key, out double firstSeenSeconds)
Parameters
keyTKeyThe oldest key, if one exists.
firstSeenSecondsdoubleThe first-seen monotonic time of the oldest key.
Returns
- bool
trueif a key was found; otherwise,false.