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
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, DateTime, int>)
Invokes action for each tracked key in FIFO order.
The callback receives the key, its first-seen UTC timestamp, 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, DateTime, int> action)
Parameters
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, DateTime, int>) instead.
public int GetPosition(TKey key)
Parameters
keyTKey
Returns
PopOldest(out TKey, out DateTime)
Removes and returns the oldest tracked key.
public bool PopOldest(out TKey key, out DateTime firstSeenUtc)
Parameters
keyTKeyThe removed key, if one existed.
firstSeenUtcDateTimeThe first-seen UTC timestamp 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, DateTime)
Adds a key only if it is not already tracked.
public void TrackIfMissing(TKey key, DateTime firstSeenUtc)
Parameters
keyTKeyThe key to track.
firstSeenUtcDateTimeThe UTC timestamp to record as first-seen.
TryPeekOldest(out TKey, out DateTime)
Gets the oldest tracked key without removing it.
public bool TryPeekOldest(out TKey key, out DateTime firstSeenUtc)
Parameters
keyTKeyThe oldest key, if one exists.
firstSeenUtcDateTimeThe first-seen UTC timestamp of the oldest key.
Returns
- bool
trueif a key was found; otherwise,false.