From ff53dcf5607a82ad38388502b4cf5cc8cca77733 Mon Sep 17 00:00:00 2001
From: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Date: Mon, 26 Jun 2023 07:25:06 +0200
Subject: [ARMeilleure] Address dotnet-format issues (#5357)
* dotnet format style --severity info
Some changes were manually reverted.
* dotnet format analyzers --serverity info
Some changes have been minimally adapted.
* Restore a few unused methods and variables
* Silence dotnet format IDE0060 warnings
* Silence dotnet format IDE0052 warnings
* Address or silence dotnet format IDE1006 warnings
* Address or silence dotnet format CA2208 warnings
* Address dotnet format CA1822 warnings
* Address or silence dotnet format CA1069 warnings
* Silence CA1806 and CA1834 issues
* Address dotnet format CA1401 warnings
* Fix new dotnet-format issues after rebase
* Address review comments
* Address dotnet format CA2208 warnings properly
* Fix formatting for switch expressions
* Address most dotnet format whitespace warnings
* Apply dotnet format whitespace formatting
A few of them have been manually reverted and the corresponding warning was silenced
* Add previously silenced warnings back
I have no clue how these disappeared
* Revert formatting changes for OpCodeTable.cs
* Enable formatting for a few cases again
* Format if-blocks correctly
* Enable formatting for a few more cases again
* Fix inline comment alignment
* Run dotnet format after rebase and remove unused usings
- analyzers
- style
- whitespace
* Disable 'prefer switch expression' rule
* Add comments to disabled warnings
* Remove a few unused parameters
* Adjust namespaces
* Simplify properties and array initialization, Use const when possible, Remove trailing commas
* Start working on disabled warnings
* Fix and silence a few dotnet-format warnings again
* Address IDE0251 warnings
* Address a few disabled IDE0060 warnings
* Silence IDE0060 in .editorconfig
* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"
This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.
* dotnet format whitespace after rebase
* First dotnet format pass
* Remove unnecessary formatting exclusion
* Add unsafe dotnet format changes
* Change visibility of JitSupportDarwin to internal
---
src/ARMeilleure/Translation/IntervalTree.cs | 132 ++++++++++++++--------------
1 file changed, 66 insertions(+), 66 deletions(-)
(limited to 'src/ARMeilleure/Translation/IntervalTree.cs')
diff --git a/src/ARMeilleure/Translation/IntervalTree.cs b/src/ARMeilleure/Translation/IntervalTree.cs
index 9af01bea..afd89b93 100644
--- a/src/ARMeilleure/Translation/IntervalTree.cs
+++ b/src/ARMeilleure/Translation/IntervalTree.cs
@@ -6,15 +6,15 @@ namespace ARMeilleure.Translation
///
/// An Augmented Interval Tree based off of the "TreeDictionary"'s Red-Black Tree. Allows fast overlap checking of ranges.
///
- /// Key
- /// Value
- class IntervalTree where K : IComparable
+ /// Key
+ /// Value
+ class IntervalTree where TK : IComparable
{
private const int ArrayGrowthSize = 32;
private const bool Black = true;
private const bool Red = false;
- private IntervalTreeNode _root = null;
+ private IntervalTreeNode _root = null;
private int _count = 0;
public int Count => _count;
@@ -27,9 +27,9 @@ namespace ARMeilleure.Translation
/// Key of the node value to get
/// Value with the given
/// True if the key is on the dictionary, false otherwise
- public bool TryGet(K key, out V value)
+ public bool TryGet(TK key, out TV value)
{
- IntervalTreeNode node = GetNode(key);
+ IntervalTreeNode node = GetNode(key);
if (node == null)
{
@@ -49,7 +49,7 @@ namespace ARMeilleure.Translation
/// Overlaps array to place results in
/// Index to start writing results into the array. Defaults to 0
/// Number of intervals found
- public int Get(K start, K end, ref K[] overlaps, int overlapCount = 0)
+ public int Get(TK start, TK end, ref TK[] overlaps, int overlapCount = 0)
{
GetKeys(_root, start, end, ref overlaps, ref overlapCount);
@@ -65,11 +65,11 @@ namespace ARMeilleure.Translation
/// Optional factory used to create a new value if is already on the tree
/// is null
/// True if the value was added, false if the start key was already in the dictionary
- public bool AddOrUpdate(K start, K end, V value, Func updateFactoryCallback)
+ public bool AddOrUpdate(TK start, TK end, TV value, Func updateFactoryCallback)
{
ArgumentNullException.ThrowIfNull(value);
- return BSTInsert(start, end, value, updateFactoryCallback, out IntervalTreeNode node);
+ return BSTInsert(start, end, value, updateFactoryCallback, out _);
}
///
@@ -80,11 +80,11 @@ namespace ARMeilleure.Translation
/// Value to add
/// is null
/// if is not yet on the tree, or the existing value otherwise
- public V GetOrAdd(K start, K end, V value)
+ public TV GetOrAdd(TK start, TK end, TV value)
{
ArgumentNullException.ThrowIfNull(value);
- BSTInsert(start, end, value, null, out IntervalTreeNode node);
+ BSTInsert(start, end, value, null, out IntervalTreeNode node);
return node.Value;
}
@@ -93,7 +93,7 @@ namespace ARMeilleure.Translation
///
/// Key of the node to remove
/// Number of deleted values
- public int Remove(K key)
+ public int Remove(TK key)
{
int removed = Delete(key);
@@ -106,9 +106,9 @@ namespace ARMeilleure.Translation
/// Adds all the nodes in the dictionary into .
///
/// A list of all values sorted by Key Order
- public List AsList()
+ public List AsList()
{
- List list = new List();
+ List list = new();
AddToList(_root, list);
@@ -124,7 +124,7 @@ namespace ARMeilleure.Translation
///
/// The node to search for values within
/// The list to add values to
- private void AddToList(IntervalTreeNode node, List list)
+ private void AddToList(IntervalTreeNode node, List list)
{
if (node == null)
{
@@ -144,11 +144,11 @@ namespace ARMeilleure.Translation
/// Key of the node to get
/// is null
/// Node reference in the tree
- private IntervalTreeNode GetNode(K key)
+ private IntervalTreeNode GetNode(TK key)
{
ArgumentNullException.ThrowIfNull(key);
- IntervalTreeNode node = _root;
+ IntervalTreeNode node = _root;
while (node != null)
{
int cmp = key.CompareTo(node.Start);
@@ -175,7 +175,7 @@ namespace ARMeilleure.Translation
/// End of the range
/// Overlaps array to place results in
/// Overlaps count to update
- private void GetKeys(IntervalTreeNode node, K start, K end, ref K[] overlaps, ref int overlapCount)
+ private void GetKeys(IntervalTreeNode node, TK start, TK end, ref TK[] overlaps, ref int overlapCount)
{
if (node == null || start.CompareTo(node.Max) >= 0)
{
@@ -206,10 +206,10 @@ namespace ARMeilleure.Translation
/// This should only be called if the max increases - not for rebalancing or removals.
///
/// The node to start propagating from
- private void PropagateIncrease(IntervalTreeNode node)
+ private static void PropagateIncrease(IntervalTreeNode node)
{
- K max = node.Max;
- IntervalTreeNode ptr = node;
+ TK max = node.Max;
+ IntervalTreeNode ptr = node;
while ((ptr = ptr.Parent) != null)
{
@@ -229,13 +229,13 @@ namespace ARMeilleure.Translation
/// This fully recalculates the max value from all children when there is potential for it to decrease.
///
/// The node to start propagating from
- private void PropagateFull(IntervalTreeNode node)
+ private static void PropagateFull(IntervalTreeNode node)
{
- IntervalTreeNode ptr = node;
+ IntervalTreeNode ptr = node;
do
{
- K max = ptr.End;
+ TK max = ptr.End;
if (ptr.Left != null && ptr.Left.Max.CompareTo(max) > 0)
{
@@ -263,10 +263,10 @@ namespace ARMeilleure.Translation
/// Optional factory used to create a new value if is already on the tree
/// Node that was inserted or modified
/// True if was not yet on the tree, false otherwise
- private bool BSTInsert(K start, K end, V value, Func updateFactoryCallback, out IntervalTreeNode outNode)
+ private bool BSTInsert(TK start, TK end, TV value, Func updateFactoryCallback, out IntervalTreeNode outNode)
{
- IntervalTreeNode parent = null;
- IntervalTreeNode node = _root;
+ IntervalTreeNode parent = null;
+ IntervalTreeNode node = _root;
while (node != null)
{
@@ -311,7 +311,7 @@ namespace ARMeilleure.Translation
return false;
}
}
- IntervalTreeNode newNode = new IntervalTreeNode(start, end, value, parent);
+ IntervalTreeNode newNode = new(start, end, value, parent);
if (newNode.Parent == null)
{
_root = newNode;
@@ -337,16 +337,16 @@ namespace ARMeilleure.Translation
///
/// Key to search for
/// Number of deleted values
- private int Delete(K key)
+ private int Delete(TK key)
{
- IntervalTreeNode nodeToDelete = GetNode(key);
+ IntervalTreeNode nodeToDelete = GetNode(key);
if (nodeToDelete == null)
{
return 0;
}
- IntervalTreeNode replacementNode;
+ IntervalTreeNode replacementNode;
if (LeftOf(nodeToDelete) == null || RightOf(nodeToDelete) == null)
{
@@ -357,7 +357,7 @@ namespace ARMeilleure.Translation
replacementNode = PredecessorOf(nodeToDelete);
}
- IntervalTreeNode tmp = LeftOf(replacementNode) ?? RightOf(replacementNode);
+ IntervalTreeNode tmp = LeftOf(replacementNode) ?? RightOf(replacementNode);
if (tmp != null)
{
@@ -400,9 +400,9 @@ namespace ARMeilleure.Translation
///
/// Root Node
/// Node with the maximum key in the tree of
- private static IntervalTreeNode Maximum(IntervalTreeNode node)
+ private static IntervalTreeNode Maximum(IntervalTreeNode node)
{
- IntervalTreeNode tmp = node;
+ IntervalTreeNode tmp = node;
while (tmp.Right != null)
{
tmp = tmp.Right;
@@ -416,13 +416,13 @@ namespace ARMeilleure.Translation
///
/// Node to find the predecessor of
/// Predecessor of
- private static IntervalTreeNode PredecessorOf(IntervalTreeNode node)
+ private static IntervalTreeNode PredecessorOf(IntervalTreeNode node)
{
if (node.Left != null)
{
return Maximum(node.Left);
}
- IntervalTreeNode parent = node.Parent;
+ IntervalTreeNode parent = node.Parent;
while (parent != null && node == parent.Left)
{
node = parent;
@@ -435,15 +435,15 @@ namespace ARMeilleure.Translation
#region Private Methods (RBL)
- private void RestoreBalanceAfterRemoval(IntervalTreeNode balanceNode)
+ private void RestoreBalanceAfterRemoval(IntervalTreeNode balanceNode)
{
- IntervalTreeNode ptr = balanceNode;
+ IntervalTreeNode ptr = balanceNode;
while (ptr != _root && ColorOf(ptr) == Black)
{
if (ptr == LeftOf(ParentOf(ptr)))
{
- IntervalTreeNode sibling = RightOf(ParentOf(ptr));
+ IntervalTreeNode sibling = RightOf(ParentOf(ptr));
if (ColorOf(sibling) == Red)
{
@@ -475,7 +475,7 @@ namespace ARMeilleure.Translation
}
else
{
- IntervalTreeNode sibling = LeftOf(ParentOf(ptr));
+ IntervalTreeNode sibling = LeftOf(ParentOf(ptr));
if (ColorOf(sibling) == Red)
{
@@ -509,14 +509,14 @@ namespace ARMeilleure.Translation
SetColor(ptr, Black);
}
- private void RestoreBalanceAfterInsertion(IntervalTreeNode balanceNode)
+ private void RestoreBalanceAfterInsertion(IntervalTreeNode balanceNode)
{
SetColor(balanceNode, Red);
while (balanceNode != null && balanceNode != _root && ColorOf(ParentOf(balanceNode)) == Red)
{
if (ParentOf(balanceNode) == LeftOf(ParentOf(ParentOf(balanceNode))))
{
- IntervalTreeNode sibling = RightOf(ParentOf(ParentOf(balanceNode)));
+ IntervalTreeNode sibling = RightOf(ParentOf(ParentOf(balanceNode)));
if (ColorOf(sibling) == Red)
{
@@ -539,7 +539,7 @@ namespace ARMeilleure.Translation
}
else
{
- IntervalTreeNode sibling = LeftOf(ParentOf(ParentOf(balanceNode)));
+ IntervalTreeNode sibling = LeftOf(ParentOf(ParentOf(balanceNode)));
if (ColorOf(sibling) == Red)
{
@@ -564,17 +564,17 @@ namespace ARMeilleure.Translation
SetColor(_root, Black);
}
- private void RotateLeft(IntervalTreeNode node)
+ private void RotateLeft(IntervalTreeNode node)
{
if (node != null)
{
- IntervalTreeNode right = RightOf(node);
+ IntervalTreeNode right = RightOf(node);
node.Right = LeftOf(right);
if (node.Right != null)
{
node.Right.Parent = node;
}
- IntervalTreeNode nodeParent = ParentOf(node);
+ IntervalTreeNode nodeParent = ParentOf(node);
right.Parent = nodeParent;
if (nodeParent == null)
{
@@ -595,17 +595,17 @@ namespace ARMeilleure.Translation
}
}
- private void RotateRight(IntervalTreeNode node)
+ private void RotateRight(IntervalTreeNode node)
{
if (node != null)
{
- IntervalTreeNode left = LeftOf(node);
+ IntervalTreeNode left = LeftOf(node);
node.Left = RightOf(left);
if (node.Left != null)
{
node.Left.Parent = node;
}
- IntervalTreeNode nodeParent = ParentOf(node);
+ IntervalTreeNode nodeParent = ParentOf(node);
left.Parent = nodeParent;
if (nodeParent == null)
{
@@ -637,7 +637,7 @@ namespace ARMeilleure.Translation
///
/// Node
/// The boolean color of , or black if null
- private static bool ColorOf(IntervalTreeNode node)
+ private static bool ColorOf(IntervalTreeNode node)
{
return node == null || node.Color;
}
@@ -649,7 +649,7 @@ namespace ARMeilleure.Translation
///
/// Node to set the color of
/// Color (Boolean)
- private static void SetColor(IntervalTreeNode node, bool color)
+ private static void SetColor(IntervalTreeNode node, bool color)
{
if (node != null)
{
@@ -662,7 +662,7 @@ namespace ARMeilleure.Translation
///
/// Node to retrieve the left child from
/// Left child of
- private static IntervalTreeNode LeftOf(IntervalTreeNode node)
+ private static IntervalTreeNode LeftOf(IntervalTreeNode node)
{
return node?.Left;
}
@@ -672,7 +672,7 @@ namespace ARMeilleure.Translation
///
/// Node to retrieve the right child from
/// Right child of
- private static IntervalTreeNode RightOf(IntervalTreeNode node)
+ private static IntervalTreeNode RightOf(IntervalTreeNode node)
{
return node?.Right;
}
@@ -682,14 +682,14 @@ namespace ARMeilleure.Translation
///
/// Node to retrieve the parent from
/// Parent of
- private static IntervalTreeNode ParentOf(IntervalTreeNode node)
+ private static IntervalTreeNode ParentOf(IntervalTreeNode node)
{
return node?.Parent;
}
#endregion
- public bool ContainsKey(K key)
+ public bool ContainsKey(TK key)
{
return GetNode(key) != null;
}
@@ -704,36 +704,36 @@ namespace ARMeilleure.Translation
///
/// Represents a node in the IntervalTree which contains start and end keys of type K, and a value of generic type V.
///
- /// Key type of the node
- /// Value type of the node
- class IntervalTreeNode
+ /// Key type of the node
+ /// Value type of the node
+ class IntervalTreeNode
{
public bool Color = true;
- public IntervalTreeNode Left = null;
- public IntervalTreeNode Right = null;
- public IntervalTreeNode Parent = null;
+ public IntervalTreeNode Left = null;
+ public IntervalTreeNode Right = null;
+ public IntervalTreeNode Parent = null;
///
/// The start of the range.
///
- public K Start;
+ public TK Start;
///
/// The end of the range.
///
- public K End;
+ public TK End;
///
/// The maximum end value of this node and all its children.
///
- public K Max;
+ public TK Max;
///
/// Value stored on this node.
///
- public V Value;
+ public TV Value;
- public IntervalTreeNode(K start, K end, V value, IntervalTreeNode parent)
+ public IntervalTreeNode(TK start, TK end, TV value, IntervalTreeNode parent)
{
Start = start;
End = end;
--
cgit v1.2.3