From fc20d9b925b83532a19467293a7cdcbaa4ef3d6b Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:41:38 +0200 Subject: [Ryujinx.Common] Address dotnet-format issues (#5358) * 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 IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2211 warnings * Silence CA1806 and CA1834 issues * 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 * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Replace MmeShadowScratch with Array256 * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * 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 * Second dotnet format pass * Fix build issues * Fix StructArrayHelpers.cs * Apply suggestions from code review Co-authored-by: Ac_K * Fix return statements * Fix naming rule violations * Update src/Ryujinx.Common/Utilities/StreamUtils.cs Co-authored-by: Ac_K * Add trailing commas * Address review feedback * Address review feedback * Rename remaining type parameters to TKey and TValue * Fix manual formatting for logging levels * Fix spacing before comments --------- Co-authored-by: Ac_K --- src/Ryujinx.Common/Collections/TreeDictionary.cs | 149 ++++++++++++----------- 1 file changed, 76 insertions(+), 73 deletions(-) (limited to 'src/Ryujinx.Common/Collections/TreeDictionary.cs') diff --git a/src/Ryujinx.Common/Collections/TreeDictionary.cs b/src/Ryujinx.Common/Collections/TreeDictionary.cs index d118a30c..ff179488 100644 --- a/src/Ryujinx.Common/Collections/TreeDictionary.cs +++ b/src/Ryujinx.Common/Collections/TreeDictionary.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Common.Collections /// /// Dictionary that provides the ability for O(logN) Lookups for keys that exist in the Dictionary, and O(logN) lookups for keys immediately greater than or less than a specified key. /// - /// Key - /// Value - public class TreeDictionary : IntrusiveRedBlackTreeImpl>, IDictionary where K : IComparable + /// Key + /// Value + public class TreeDictionary : IntrusiveRedBlackTreeImpl>, IDictionary where TKey : IComparable { #region Public Methods @@ -20,11 +20,11 @@ namespace Ryujinx.Common.Collections /// Key of the node value to get /// Value associated w/ /// is null - public V Get(K key) + public TValue Get(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node node = GetNode(key); + Node node = GetNode(key); if (node == null) { @@ -42,7 +42,7 @@ namespace Ryujinx.Common.Collections /// Key of the node to add /// Value of the node to add /// or are null - public void Add(K key, V value) + public void Add(TKey key, TValue value) { ArgumentNullException.ThrowIfNull(key); ArgumentNullException.ThrowIfNull(value); @@ -55,7 +55,7 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to remove /// is null - public void Remove(K key) + public void Remove(TKey key) { ArgumentNullException.ThrowIfNull(key); @@ -71,9 +71,9 @@ namespace Ryujinx.Common.Collections /// Key for which to find the floor value of /// Key of node immediately less than /// is null - public K Floor(K key) + public TKey Floor(TKey key) { - Node node = FloorNode(key); + Node node = FloorNode(key); if (node != null) { return node.Key; @@ -87,9 +87,9 @@ namespace Ryujinx.Common.Collections /// Key for which to find the ceiling node of /// Key of node immediately greater than /// is null - public K Ceiling(K key) + public TKey Ceiling(TKey key) { - Node node = CeilingNode(key); + Node node = CeilingNode(key); if (node != null) { return node.Key; @@ -102,12 +102,12 @@ namespace Ryujinx.Common.Collections /// /// Key to find the successor of /// Value - public K SuccessorOf(K key) + public TKey SuccessorOf(TKey key) { - Node node = GetNode(key); + Node node = GetNode(key); if (node != null) { - Node successor = SuccessorOf(node); + Node successor = SuccessorOf(node); return successor != null ? successor.Key : default; } @@ -119,12 +119,12 @@ namespace Ryujinx.Common.Collections /// /// Key to find the predecessor of /// Value - public K PredecessorOf(K key) + public TKey PredecessorOf(TKey key) { - Node node = GetNode(key); + Node node = GetNode(key); if (node != null) { - Node predecessor = PredecessorOf(node); + Node predecessor = PredecessorOf(node); return predecessor != null ? predecessor.Key : default; } @@ -137,19 +137,19 @@ namespace Ryujinx.Common.Collections /// The key/value pairs will be added in Level Order. /// /// List to add the tree pairs into - public List> AsLevelOrderList() + public List> AsLevelOrderList() { - List> list = new List>(); + List> list = new(); - Queue> nodes = new Queue>(); + Queue> nodes = new(); if (this.Root != null) { nodes.Enqueue(this.Root); } - while (nodes.TryDequeue(out Node node)) + while (nodes.TryDequeue(out Node node)) { - list.Add(new KeyValuePair(node.Key, node.Value)); + list.Add(new KeyValuePair(node.Key, node.Value)); if (node.Left != null) { nodes.Enqueue(node.Left); @@ -166,9 +166,9 @@ namespace Ryujinx.Common.Collections /// Adds all the nodes in the dictionary into . /// /// A list of all KeyValuePairs sorted by Key Order - public List> AsList() + public List> AsList() { - List> list = new List>(); + List> list = new(); AddToList(Root, list); @@ -184,7 +184,7 @@ namespace Ryujinx.Common.Collections /// /// The node to search for nodes within /// The list to add node to - private void AddToList(Node node, List> list) + private void AddToList(Node node, List> list) { if (node == null) { @@ -193,7 +193,7 @@ namespace Ryujinx.Common.Collections AddToList(node.Left, list); - list.Add(new KeyValuePair(node.Key, node.Value)); + list.Add(new KeyValuePair(node.Key, node.Value)); AddToList(node.Right, list); } @@ -204,11 +204,11 @@ namespace Ryujinx.Common.Collections /// Key of the node to get /// Node reference in the tree /// is null - private Node GetNode(K key) + private Node GetNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node node = Root; + Node node = Root; while (node != null) { int cmp = key.CompareTo(node.Key); @@ -235,9 +235,9 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to insert /// Value of the node to insert - private void Insert(K key, V value) + private void Insert(TKey key, TValue value) { - Node newNode = BSTInsert(key, value); + Node newNode = BSTInsert(key, value); RestoreBalanceAfterInsertion(newNode); } @@ -251,10 +251,10 @@ namespace Ryujinx.Common.Collections /// Key of the node to insert /// Value of the node to insert /// The inserted Node - private Node BSTInsert(K key, V value) + private Node BSTInsert(TKey key, TValue value) { - Node parent = null; - Node node = Root; + Node parent = null; + Node node = Root; while (node != null) { @@ -274,7 +274,7 @@ namespace Ryujinx.Common.Collections return node; } } - Node newNode = new Node(key, value, parent); + Node newNode = new(key, value, parent); if (newNode.Parent == null) { Root = newNode; @@ -296,14 +296,17 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to delete /// The deleted Node - private Node Delete(K key) + private Node Delete(TKey key) { // O(1) Retrieval - Node nodeToDelete = GetNode(key); + Node nodeToDelete = GetNode(key); - if (nodeToDelete == null) return null; + if (nodeToDelete == null) + { + return null; + } - Node replacementNode; + Node replacementNode; if (LeftOf(nodeToDelete) == null || RightOf(nodeToDelete) == null) { @@ -314,7 +317,7 @@ namespace Ryujinx.Common.Collections replacementNode = PredecessorOf(nodeToDelete); } - Node tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); + Node tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); if (tmp != null) { @@ -354,11 +357,11 @@ namespace Ryujinx.Common.Collections /// Key for which to find the floor node of /// Node whose key is immediately less than or equal to , or null if no such node is found. /// is null - private Node FloorNode(K key) + private Node FloorNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node tmp = Root; + Node tmp = Root; while (tmp != null) { @@ -382,8 +385,8 @@ namespace Ryujinx.Common.Collections } else { - Node parent = tmp.Parent; - Node ptr = tmp; + Node parent = tmp.Parent; + Node ptr = tmp; while (parent != null && ptr == parent.Left) { ptr = parent; @@ -406,11 +409,11 @@ namespace Ryujinx.Common.Collections /// Key for which to find the ceiling node of /// Node whose key is immediately greater than or equal to , or null if no such node is found. /// is null - private Node CeilingNode(K key) + private Node CeilingNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node tmp = Root; + Node tmp = Root; while (tmp != null) { @@ -434,8 +437,8 @@ namespace Ryujinx.Common.Collections } else { - Node parent = tmp.Parent; - Node ptr = tmp; + Node parent = tmp.Parent; + Node ptr = tmp; while (parent != null && ptr == parent.Right) { ptr = parent; @@ -457,44 +460,44 @@ namespace Ryujinx.Common.Collections #region Interface Implementations // Method descriptions are not provided as they are already included as part of the interface. - public bool ContainsKey(K key) + public bool ContainsKey(TKey key) { ArgumentNullException.ThrowIfNull(key); return GetNode(key) != null; } - bool IDictionary.Remove(K key) + bool IDictionary.Remove(TKey key) { int count = Count; Remove(key); return count > Count; } - public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) { ArgumentNullException.ThrowIfNull(key); - Node node = GetNode(key); + Node node = GetNode(key); value = node != null ? node.Value : default; return node != null; } - public void Add(KeyValuePair item) + public void Add(KeyValuePair item) { ArgumentNullException.ThrowIfNull(item.Key); Add(item.Key, item.Value); } - public bool Contains(KeyValuePair item) + public bool Contains(KeyValuePair item) { if (item.Key == null) { return false; } - Node node = GetNode(item.Key); + Node node = GetNode(item.Key); if (node != null) { return node.Key.Equals(item.Key) && node.Value.Equals(item.Value); @@ -502,27 +505,27 @@ namespace Ryujinx.Common.Collections return false; } - public void CopyTo(KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0 || array.Length - arrayIndex < this.Count) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } - SortedList list = GetKeyValues(); + SortedList list = GetKeyValues(); int offset = 0; for (int i = arrayIndex; i < array.Length && offset < list.Count; i++) { - array[i] = new KeyValuePair(list.Keys[i], list.Values[i]); + array[i] = new KeyValuePair(list.Keys[i], list.Values[i]); offset++; } } - public bool Remove(KeyValuePair item) + public bool Remove(KeyValuePair item) { - Node node = GetNode(item.Key); + Node node = GetNode(item.Key); if (node == null) { @@ -539,7 +542,7 @@ namespace Ryujinx.Common.Collections return false; } - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { return GetKeyValues().GetEnumerator(); } @@ -549,13 +552,13 @@ namespace Ryujinx.Common.Collections return GetKeyValues().GetEnumerator(); } - public ICollection Keys => GetKeyValues().Keys; + public ICollection Keys => GetKeyValues().Keys; - public ICollection Values => GetKeyValues().Values; + public ICollection Values => GetKeyValues().Values; public bool IsReadOnly => false; - public V this[K key] + public TValue this[TKey key] { get => Get(key); set => Add(key, value); @@ -569,16 +572,16 @@ namespace Ryujinx.Common.Collections /// Returns a sorted list of all the node keys / values in the tree. /// /// List of node keys - private SortedList GetKeyValues() + private SortedList GetKeyValues() { - SortedList set = new SortedList(); - Queue> queue = new Queue>(); + SortedList set = new(); + Queue> queue = new(); if (Root != null) { queue.Enqueue(Root); } - while (queue.TryDequeue(out Node node)) + while (queue.TryDequeue(out Node node)) { set.Add(node.Key, node.Value); if (null != node.Left) @@ -600,14 +603,14 @@ namespace Ryujinx.Common.Collections /// /// Represents a node in the TreeDictionary which contains a key and value of generic type K and V, respectively. /// - /// Key of the node - /// Value of the node - public class Node : IntrusiveRedBlackTreeNode> where K : IComparable + /// Key of the node + /// Value of the node + public class Node : IntrusiveRedBlackTreeNode> where TKey : IComparable { - internal K Key; - internal V Value; + internal TKey Key; + internal TValue Value; - internal Node(K key, V value, Node parent) + internal Node(TKey key, TValue value, Node parent) { Key = key; Value = value; -- cgit v1.2.3