2023-10-14 19:43:10 -07:00
|
|
|
/*************************************************************************
|
|
|
|
|
* ModernUO *
|
|
|
|
|
* Copyright 2019-2023 - ModernUO Development Team *
|
|
|
|
|
* Email: hi@modernuo.com *
|
|
|
|
|
* File: BaseMulti.SectorMultiLinkList.cs *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2023-11-05 08:17:34 -08:00
|
|
|
using Server.Collections;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
|
|
|
|
namespace Server.Items;
|
|
|
|
|
|
|
|
|
|
// Adds support for the specific value link list on sectors for multis, separate from items
|
2023-11-05 08:17:34 -08:00
|
|
|
public partial class BaseMulti
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
// Sectors, specifically for multis
|
|
|
|
|
public BaseMulti SectorMultiNext { get; set; }
|
|
|
|
|
public BaseMulti SectorMultiPrevious { get; set; }
|
|
|
|
|
public bool OnSectorMultiLinkList { get; set; }
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public struct SectorMultiValueLinkList
|
|
|
|
|
{
|
|
|
|
|
public int Count { get; internal set; }
|
|
|
|
|
internal BaseMulti _first;
|
|
|
|
|
internal BaseMulti _last;
|
|
|
|
|
|
|
|
|
|
public int Version { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void Remove(BaseMulti node)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (!node.OnSectorMultiLinkList)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
throw new ArgumentException("Attempted to remove a node that is not on the list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (node.SectorMultiPrevious == null)
|
|
|
|
|
{
|
|
|
|
|
// If SectorMultiPrevious is null, then it is the first element.
|
|
|
|
|
if (_first != node)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to remove a node that is not on the list.");
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (_first == _last)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_last = null;
|
|
|
|
|
_first = null;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_first = node.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (node.SectorMultiNext != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
node.SectorMultiNext.SectorMultiPrevious = null;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node.SectorMultiPrevious.SectorMultiNext = node.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
// If SectorMultiNext is null, then it is the last element.
|
|
|
|
|
if (node.SectorMultiNext == null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_last = node.SectorMultiPrevious;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
else
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
node.SectorMultiNext.SectorMultiPrevious = node.SectorMultiPrevious;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
node.SectorMultiNext = null;
|
|
|
|
|
node.SectorMultiPrevious = null;
|
|
|
|
|
node.OnSectorMultiLinkList = false;
|
|
|
|
|
Count--;
|
|
|
|
|
Version++;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (Count < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Count is negative!");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
// Remove all entries before this node, not including this node.
|
|
|
|
|
public void RemoveAllBefore(BaseMulti e)
|
|
|
|
|
{
|
|
|
|
|
if (e == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (!e.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to remove nodes before a node that is not on the list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (e.SectorMultiPrevious == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
var current = e.SectorMultiPrevious;
|
|
|
|
|
e.SectorMultiPrevious = null;
|
|
|
|
|
|
|
|
|
|
while (current != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
var SectorMultiPrevious = current.SectorMultiPrevious;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
current.OnSectorMultiLinkList = false;
|
|
|
|
|
current.SectorMultiNext = null;
|
|
|
|
|
current.SectorMultiPrevious = null;
|
|
|
|
|
Count--;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (Count < 0)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
throw new Exception("Count is negative!");
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
current = SectorMultiPrevious;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
_first = e;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
// Remove all entries after this node, not including this node.
|
|
|
|
|
public void RemoveAllAfter(BaseMulti e)
|
|
|
|
|
{
|
|
|
|
|
if (e == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (!e.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to remove nodes after a node that is not on the list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (e.SectorMultiNext == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
var current = e.SectorMultiNext;
|
|
|
|
|
e.SectorMultiNext = null;
|
|
|
|
|
|
|
|
|
|
while (current != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
var SectorMultiNext = current.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
current.OnSectorMultiLinkList = false;
|
|
|
|
|
current.SectorMultiNext = null;
|
|
|
|
|
current.SectorMultiPrevious = null;
|
|
|
|
|
Count--;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (Count < 0)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
throw new Exception("Count is negative!");
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
current = SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
_last = e;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public void AddLast(BaseMulti e)
|
|
|
|
|
{
|
|
|
|
|
if (e == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (e.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to add a node that is already on a list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (_last != null)
|
|
|
|
|
{
|
|
|
|
|
AddAfter(_last, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_first = e;
|
|
|
|
|
_last = e;
|
|
|
|
|
Count = 1;
|
|
|
|
|
Version++;
|
2023-10-14 19:43:10 -07:00
|
|
|
e.OnSectorMultiLinkList = true;
|
|
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public void AddFirst(BaseMulti e)
|
|
|
|
|
{
|
|
|
|
|
if (e == null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (e.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to add a node that is already on a list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (_first != null)
|
|
|
|
|
{
|
|
|
|
|
AddBefore(_first, e);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_first = e;
|
|
|
|
|
_last = e;
|
|
|
|
|
Count = 1;
|
|
|
|
|
Version++;
|
|
|
|
|
e.OnSectorMultiLinkList = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public void AddBefore(BaseMulti existing, BaseMulti node)
|
|
|
|
|
{
|
|
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
ArgumentNullException.ThrowIfNull(existing);
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (!existing.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Argument '{nameof(existing)}' must be a node on a list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (node.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to add a node that is already on a list.");
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
node.SectorMultiNext = existing;
|
|
|
|
|
node.SectorMultiPrevious = existing.SectorMultiPrevious;
|
|
|
|
|
|
|
|
|
|
if (existing.SectorMultiPrevious != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
existing.SectorMultiPrevious.SectorMultiNext = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_first = node;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
existing.SectorMultiPrevious = node;
|
|
|
|
|
node.OnSectorMultiLinkList = true;
|
|
|
|
|
Count++;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public void AddAfter(BaseMulti existing, BaseMulti node)
|
|
|
|
|
{
|
|
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
ArgumentNullException.ThrowIfNull(existing);
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (!existing.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Argument '{nameof(existing)}' must be a node on a list.");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (node.OnSectorMultiLinkList)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to add a node that is already on a list.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.SectorMultiPrevious = existing;
|
|
|
|
|
node.SectorMultiNext = existing.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (existing.SectorMultiNext != null)
|
|
|
|
|
{
|
|
|
|
|
existing.SectorMultiNext.SectorMultiPrevious = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_last = node;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
existing.SectorMultiNext = node;
|
|
|
|
|
node.OnSectorMultiLinkList = true;
|
|
|
|
|
Count++;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAll()
|
|
|
|
|
{
|
|
|
|
|
var current = _first;
|
|
|
|
|
while (current != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
var SectorMultiNext = current.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
current.OnSectorMultiLinkList = false;
|
|
|
|
|
current.SectorMultiNext = null;
|
|
|
|
|
current.SectorMultiPrevious = null;
|
|
|
|
|
current = SectorMultiNext;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
_first = null;
|
|
|
|
|
_last = null;
|
|
|
|
|
Count = 0;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddLast(ref SectorMultiValueLinkList otherList, BaseMulti start, BaseMulti end)
|
|
|
|
|
{
|
|
|
|
|
// Should we check if start and end actually exist on the other list?
|
|
|
|
|
if (otherList.Count == 0 || otherList.Count == 1 && (start != end || otherList._first != start))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Attempted to add nodes that are not on the specified linklist.");
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (start.SectorMultiPrevious != null)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
start.SectorMultiPrevious.SectorMultiNext = end.SectorMultiNext;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Start is first
|
|
|
|
|
otherList._first = end.SectorMultiNext;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (end.SectorMultiNext != null)
|
|
|
|
|
{
|
|
|
|
|
end.SectorMultiNext.SectorMultiPrevious = start.SectorMultiPrevious;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
otherList._last = start.SectorMultiPrevious;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
var count = 1;
|
|
|
|
|
var current = start;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
// Assume start and end are in the right order, or bad things happen (crash).
|
|
|
|
|
while (current != end)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
current = current.SectorMultiNext;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
otherList.Count -= count;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (otherList.Count < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Count is negative!");
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
if (_last != null)
|
|
|
|
|
{
|
|
|
|
|
_last.SectorMultiNext = start;
|
|
|
|
|
start.SectorMultiPrevious = _last;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_first = start;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_last = end;
|
|
|
|
|
Count += count;
|
|
|
|
|
Version++;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public BaseMulti[] ToArray()
|
|
|
|
|
{
|
|
|
|
|
var arr = new BaseMulti[Count];
|
|
|
|
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
foreach (var t in this)
|
|
|
|
|
{
|
|
|
|
|
arr[index++] = t;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
return arr;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public ref struct SectorMultiValueListEnumerator
|
|
|
|
|
{
|
|
|
|
|
private bool _started;
|
|
|
|
|
private BaseMulti _current;
|
|
|
|
|
private ref readonly SectorMultiValueLinkList _linkList;
|
|
|
|
|
private int _version;
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public SectorMultiValueListEnumerator(in SectorMultiValueLinkList linkList)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_linkList = ref linkList;
|
|
|
|
|
_started = false;
|
|
|
|
|
_current = null;
|
|
|
|
|
_version = 0;
|
|
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public bool MoveNext()
|
|
|
|
|
{
|
|
|
|
|
if (!_started)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_current = _linkList._first;
|
|
|
|
|
_started = true;
|
|
|
|
|
_version = _linkList.Version;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
else if (_linkList.Version != _version)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion);
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
else
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_current = _current.SectorMultiNext;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
|
|
|
|
|
return _current != null;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public BaseMulti Current
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-11-05 08:17:34 -08:00
|
|
|
get => _current;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ref struct DescendingSectorMultiValueListEnumerator
|
|
|
|
|
{
|
|
|
|
|
private bool _started;
|
|
|
|
|
private BaseMulti _current;
|
|
|
|
|
private ref readonly SectorMultiValueLinkList _linkList;
|
|
|
|
|
private int _version;
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public DescendingSectorMultiValueListEnumerator(in SectorMultiValueLinkList linkList)
|
|
|
|
|
{
|
|
|
|
|
_linkList = ref linkList;
|
|
|
|
|
_started = false;
|
|
|
|
|
_current = null;
|
|
|
|
|
_version = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public bool MoveNext()
|
|
|
|
|
{
|
|
|
|
|
if (!_started)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_current = _linkList._last;
|
|
|
|
|
_started = true;
|
|
|
|
|
_version = _linkList.Version;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
else if (_linkList.Version != _version)
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
throw new InvalidOperationException(CollectionThrowStrings.InvalidOperation_EnumFailedVersion);
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
else
|
2023-10-14 19:43:10 -07:00
|
|
|
{
|
2023-11-05 08:17:34 -08:00
|
|
|
_current = _current.SectorMultiPrevious;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
return _current != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BaseMulti Current
|
|
|
|
|
{
|
2023-10-14 19:43:10 -07:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-11-05 08:17:34 -08:00
|
|
|
get => _current;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public DescendingSectorMultiValueListEnumerator GetEnumerator() => this;
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|
2023-11-05 08:17:34 -08:00
|
|
|
}
|
2023-10-14 19:43:10 -07:00
|
|
|
|
2023-11-05 08:17:34 -08:00
|
|
|
public static class SectorMultiValueLinkListExt
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static SectorMultiValueLinkList.SectorMultiValueListEnumerator GetEnumerator(this in SectorMultiValueLinkList linkList)
|
|
|
|
|
=> new(in linkList);
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static SectorMultiValueLinkList.DescendingSectorMultiValueListEnumerator ByDescending(this in SectorMultiValueLinkList linkList)
|
|
|
|
|
=> new(in linkList);
|
2023-10-14 19:43:10 -07:00
|
|
|
}
|