From b939ca00d67c22ac29f5b6d14f052018bd402f56 Mon Sep 17 00:00:00 2001 From: Karan Chadha Date: Mon, 8 Sep 2025 22:36:08 +0530 Subject: [PATCH] chore: add GlobalUsings.cs with project-wide using directives in data structures --- DataStructures/AATree/AATree.cs | 3 --- DataStructures/AVLTree/AVLTree.cs | 3 --- DataStructures/AVLTree/AVLTreeNode.cs | 2 -- .../BinarySearchTree/BinarySearchTree.cs | 3 --- DataStructures/BitArray.cs | 4 ---- DataStructures/Cache/LfuCache.cs | 2 -- DataStructures/Cache/LruCache.cs | 2 -- DataStructures/GlobalUsings.cs | 16 ++++++++++++++++ DataStructures/Graph/DirectedWeightedGraph.cs | 3 --- DataStructures/Graph/IDirectedWeightedGraph.cs | 2 -- DataStructures/Hashing/HashTable.cs | 3 --- DataStructures/Heap/BinaryHeap.cs | 3 --- DataStructures/Heap/FibonacciHeap/FHeapNode.cs | 2 -- .../Heap/FibonacciHeap/FibonacciHeap.cs | 4 ---- DataStructures/Heap/MinMaxHeap.cs | 4 ---- DataStructures/Heap/PairingHeap/PairingHeap.cs | 5 +---- .../Heap/PairingHeap/PairingNodeComparer.cs | 3 --- DataStructures/InvertedIndex.cs | 3 --- .../CircularLinkedList/CircularLinkedList.cs | 2 -- .../DoublyLinkedList/DoublyLinkedList.cs | 2 -- .../SinglyLinkedList/SinglyLinkedList.cs | 11 ++++------- DataStructures/LinkedList/SkipList/SkipList.cs | 7 ++----- DataStructures/Probabilistic/BloomFilter.cs | 3 --- DataStructures/Probabilistic/CountMinSketch.cs | 2 -- DataStructures/Probabilistic/HyperLogLog.cs | 4 ---- DataStructures/Queue/ArrayBasedQueue.cs | 2 -- DataStructures/Queue/ListBasedQueue.cs | 4 ---- DataStructures/Queue/StackBasedQueue.cs | 3 --- DataStructures/RedBlackTree/RedBlackTree.cs | 3 --- DataStructures/ScapegoatTree/Extensions.cs | 3 --- DataStructures/ScapegoatTree/Node.cs | 2 -- DataStructures/ScapegoatTree/ScapegoatTree.cs | 3 --- DataStructures/SegmentTrees/SegmentTree.cs | 2 -- DataStructures/SegmentTrees/SegmentTreeApply.cs | 2 -- DataStructures/SortedList.cs | 1 - DataStructures/Stack/ArrayBasedStack.cs | 2 -- DataStructures/Stack/ListBasedStack.cs | 3 --- DataStructures/Stack/QueueBasedStack.cs | 6 ------ DataStructures/Timeline.cs | 3 --- DataStructures/Tries/Trie.cs | 7 ++----- DataStructures/Tries/TrieNode.cs | 3 --- .../UnrolledList/UnrolledLinkedList.cs | 2 -- .../UnrolledList/UnrolledLinkedListNode.cs | 2 -- 43 files changed, 25 insertions(+), 126 deletions(-) create mode 100644 DataStructures/GlobalUsings.cs diff --git a/DataStructures/AATree/AATree.cs b/DataStructures/AATree/AATree.cs index 4b513cdc..1ee09ef4 100644 --- a/DataStructures/AATree/AATree.cs +++ b/DataStructures/AATree/AATree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.AATree; /// diff --git a/DataStructures/AVLTree/AVLTree.cs b/DataStructures/AVLTree/AVLTree.cs index 4d79b747..1dfc4064 100644 --- a/DataStructures/AVLTree/AVLTree.cs +++ b/DataStructures/AVLTree/AVLTree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.AVLTree; /// diff --git a/DataStructures/AVLTree/AVLTreeNode.cs b/DataStructures/AVLTree/AVLTreeNode.cs index 5f88e8e1..a0684147 100644 --- a/DataStructures/AVLTree/AVLTreeNode.cs +++ b/DataStructures/AVLTree/AVLTreeNode.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.AVLTree; /// diff --git a/DataStructures/BinarySearchTree/BinarySearchTree.cs b/DataStructures/BinarySearchTree/BinarySearchTree.cs index 9a384adb..c832071c 100644 --- a/DataStructures/BinarySearchTree/BinarySearchTree.cs +++ b/DataStructures/BinarySearchTree/BinarySearchTree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.BinarySearchTree; /// diff --git a/DataStructures/BitArray.cs b/DataStructures/BitArray.cs index 6b5baeb2..c903a5c3 100644 --- a/DataStructures/BitArray.cs +++ b/DataStructures/BitArray.cs @@ -114,11 +114,7 @@ // returns true if there inputs aren't equal otherwise false. // assumes: the input bit-arrays must have same length. -using System; using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace DataStructures; diff --git a/DataStructures/Cache/LfuCache.cs b/DataStructures/Cache/LfuCache.cs index 546fcc1b..47ca44ba 100644 --- a/DataStructures/Cache/LfuCache.cs +++ b/DataStructures/Cache/LfuCache.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace DataStructures.Cache; /// diff --git a/DataStructures/Cache/LruCache.cs b/DataStructures/Cache/LruCache.cs index 185eaf3a..eb0e4631 100644 --- a/DataStructures/Cache/LruCache.cs +++ b/DataStructures/Cache/LruCache.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace DataStructures.Cache; /// diff --git a/DataStructures/GlobalUsings.cs b/DataStructures/GlobalUsings.cs new file mode 100644 index 00000000..bf447145 --- /dev/null +++ b/DataStructures/GlobalUsings.cs @@ -0,0 +1,16 @@ +// ----------------------------------------------------------------------------- +// Global using directives for the C-Sharp solution. +// These namespaces are imported globally so they don’t need to be repeatedly declared +// in individual files, improving readability and reducing boilerplate. +// +// Guidelines: +// - Keep only the most commonly used namespaces here. +// - Add project-specific namespaces (e.g., Utilities.Extensions) only if they are +// required across the majority of files in the project. +// - Avoid placing rarely used namespaces here to maintain clarity. +// ----------------------------------------------------------------------------- + +global using System; // Core base classes and fundamental types +global using System.Collections.Generic; // Generic collection types (List, Dictionary, etc.) +global using System.Linq; // LINQ query operators for collections +global using System.Text; // Text encoding, StringBuilder, etc. diff --git a/DataStructures/Graph/DirectedWeightedGraph.cs b/DataStructures/Graph/DirectedWeightedGraph.cs index 666b9e48..98e70d42 100644 --- a/DataStructures/Graph/DirectedWeightedGraph.cs +++ b/DataStructures/Graph/DirectedWeightedGraph.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Graph; /// diff --git a/DataStructures/Graph/IDirectedWeightedGraph.cs b/DataStructures/Graph/IDirectedWeightedGraph.cs index 4325b870..7bab8af3 100644 --- a/DataStructures/Graph/IDirectedWeightedGraph.cs +++ b/DataStructures/Graph/IDirectedWeightedGraph.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace DataStructures.Graph; public interface IDirectedWeightedGraph diff --git a/DataStructures/Hashing/HashTable.cs b/DataStructures/Hashing/HashTable.cs index 8f6aac78..25dd72a1 100644 --- a/DataStructures/Hashing/HashTable.cs +++ b/DataStructures/Hashing/HashTable.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; using DataStructures.Hashing.NumberTheory; namespace DataStructures.Hashing; diff --git a/DataStructures/Heap/BinaryHeap.cs b/DataStructures/Heap/BinaryHeap.cs index a7f3a060..e69df22b 100644 --- a/DataStructures/Heap/BinaryHeap.cs +++ b/DataStructures/Heap/BinaryHeap.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Heap; /// diff --git a/DataStructures/Heap/FibonacciHeap/FHeapNode.cs b/DataStructures/Heap/FibonacciHeap/FHeapNode.cs index 88eb476b..3ccd54d9 100644 --- a/DataStructures/Heap/FibonacciHeap/FHeapNode.cs +++ b/DataStructures/Heap/FibonacciHeap/FHeapNode.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.Heap.FibonacciHeap; /// diff --git a/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs b/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs index 2d004ea1..b6ea73ab 100644 --- a/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs +++ b/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace DataStructures.Heap.FibonacciHeap; /// diff --git a/DataStructures/Heap/MinMaxHeap.cs b/DataStructures/Heap/MinMaxHeap.cs index a5770d91..3bad2161 100644 --- a/DataStructures/Heap/MinMaxHeap.cs +++ b/DataStructures/Heap/MinMaxHeap.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace DataStructures.Heap; /// diff --git a/DataStructures/Heap/PairingHeap/PairingHeap.cs b/DataStructures/Heap/PairingHeap/PairingHeap.cs index 2f898720..66fcb81d 100644 --- a/DataStructures/Heap/PairingHeap/PairingHeap.cs +++ b/DataStructures/Heap/PairingHeap/PairingHeap.cs @@ -1,7 +1,4 @@ -using System; using System.Collections; -using System.Collections.Generic; -using System.Linq; namespace DataStructures.Heap.PairingHeap; @@ -57,7 +54,7 @@ public T Extract() /// public void UpdateKey(T currentValue, T newValue) { - if(!mapping.ContainsKey(currentValue)) + if (!mapping.ContainsKey(currentValue)) { throw new ArgumentException("Current value is not present in this heap."); } diff --git a/DataStructures/Heap/PairingHeap/PairingNodeComparer.cs b/DataStructures/Heap/PairingHeap/PairingNodeComparer.cs index 6ffcb581..2f5ed52c 100644 --- a/DataStructures/Heap/PairingHeap/PairingNodeComparer.cs +++ b/DataStructures/Heap/PairingHeap/PairingNodeComparer.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Heap.PairingHeap; /// diff --git a/DataStructures/InvertedIndex.cs b/DataStructures/InvertedIndex.cs index 3dc3f039..4d25ce1e 100644 --- a/DataStructures/InvertedIndex.cs +++ b/DataStructures/InvertedIndex.cs @@ -1,6 +1,3 @@ -using System.Collections.Generic; -using System.Linq; - namespace DataStructures; /// diff --git a/DataStructures/LinkedList/CircularLinkedList/CircularLinkedList.cs b/DataStructures/LinkedList/CircularLinkedList/CircularLinkedList.cs index 18c5148d..097feea7 100644 --- a/DataStructures/LinkedList/CircularLinkedList/CircularLinkedList.cs +++ b/DataStructures/LinkedList/CircularLinkedList/CircularLinkedList.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.LinkedList.CircularLinkedList { /// diff --git a/DataStructures/LinkedList/DoublyLinkedList/DoublyLinkedList.cs b/DataStructures/LinkedList/DoublyLinkedList/DoublyLinkedList.cs index d976cc87..9aaae039 100644 --- a/DataStructures/LinkedList/DoublyLinkedList/DoublyLinkedList.cs +++ b/DataStructures/LinkedList/DoublyLinkedList/DoublyLinkedList.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using Utilities.Exceptions; namespace DataStructures.LinkedList.DoublyLinkedList; diff --git a/DataStructures/LinkedList/SinglyLinkedList/SinglyLinkedList.cs b/DataStructures/LinkedList/SinglyLinkedList/SinglyLinkedList.cs index 5de05d45..c17139cc 100644 --- a/DataStructures/LinkedList/SinglyLinkedList/SinglyLinkedList.cs +++ b/DataStructures/LinkedList/SinglyLinkedList/SinglyLinkedList.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.LinkedList.SinglyLinkedList; public class SinglyLinkedList @@ -161,7 +158,7 @@ public bool DeleteElement(T element) public bool DeleteFirst() { // checks if the List is empty - if(Head is null) + if (Head is null) { return false; } @@ -178,13 +175,13 @@ public bool DeleteFirst() public bool DeleteLast() { // checks if the List is empty - if(Head is null) + if (Head is null) { return false; } // checks if the List has only one element - if(Head.Next is null) + if (Head.Next is null) { Head = null; return true; @@ -192,7 +189,7 @@ public bool DeleteLast() // if not, iterates through the list to the second last element and deletes the last one SinglyLinkedListNode? secondlast = Head; - while(secondlast.Next?.Next is not null) + while (secondlast.Next?.Next is not null) { secondlast = secondlast.Next; } diff --git a/DataStructures/LinkedList/SkipList/SkipList.cs b/DataStructures/LinkedList/SkipList/SkipList.cs index 590b4bda..4fd2ef69 100644 --- a/DataStructures/LinkedList/SkipList/SkipList.cs +++ b/DataStructures/LinkedList/SkipList/SkipList.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; namespace DataStructures.LinkedList.SkipList; @@ -49,7 +46,7 @@ public SkipList(int capacity = 255) head = new(int.MinValue, default(TValue), maxLevels); tail = new(int.MaxValue, default(TValue), maxLevels); - for(int i = 0; i < maxLevels; i++) + for (int i = 0; i < maxLevels; i++) { head.Next[i] = tail; } @@ -69,7 +66,7 @@ public TValue this[int key] get { var previousNode = GetSkipNodes(key).First(); - if(previousNode.Next[0].Key == key) + if (previousNode.Next[0].Key == key) { return previousNode.Next[0].Value!; } diff --git a/DataStructures/Probabilistic/BloomFilter.cs b/DataStructures/Probabilistic/BloomFilter.cs index 7d2d00d1..50af90b4 100644 --- a/DataStructures/Probabilistic/BloomFilter.cs +++ b/DataStructures/Probabilistic/BloomFilter.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Probabilistic; public class BloomFilter where T : notnull diff --git a/DataStructures/Probabilistic/CountMinSketch.cs b/DataStructures/Probabilistic/CountMinSketch.cs index e45f9ed2..99e51369 100644 --- a/DataStructures/Probabilistic/CountMinSketch.cs +++ b/DataStructures/Probabilistic/CountMinSketch.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.Probabilistic; public class CountMinSketch where T : notnull diff --git a/DataStructures/Probabilistic/HyperLogLog.cs b/DataStructures/Probabilistic/HyperLogLog.cs index a7ec7148..aa314e48 100644 --- a/DataStructures/Probabilistic/HyperLogLog.cs +++ b/DataStructures/Probabilistic/HyperLogLog.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace DataStructures.Probabilistic; public class HyperLogLog where T : notnull diff --git a/DataStructures/Queue/ArrayBasedQueue.cs b/DataStructures/Queue/ArrayBasedQueue.cs index 8b220fc4..5abe9341 100644 --- a/DataStructures/Queue/ArrayBasedQueue.cs +++ b/DataStructures/Queue/ArrayBasedQueue.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.Queue; /// diff --git a/DataStructures/Queue/ListBasedQueue.cs b/DataStructures/Queue/ListBasedQueue.cs index e6e49cba..9b52970e 100644 --- a/DataStructures/Queue/ListBasedQueue.cs +++ b/DataStructures/Queue/ListBasedQueue.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; - namespace DataStructures.Queue; /// diff --git a/DataStructures/Queue/StackBasedQueue.cs b/DataStructures/Queue/StackBasedQueue.cs index 7b3277d0..4da1d56e 100644 --- a/DataStructures/Queue/StackBasedQueue.cs +++ b/DataStructures/Queue/StackBasedQueue.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Queue; /// diff --git a/DataStructures/RedBlackTree/RedBlackTree.cs b/DataStructures/RedBlackTree/RedBlackTree.cs index 3c361920..aff5e42e 100644 --- a/DataStructures/RedBlackTree/RedBlackTree.cs +++ b/DataStructures/RedBlackTree/RedBlackTree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.RedBlackTree; /// diff --git a/DataStructures/ScapegoatTree/Extensions.cs b/DataStructures/ScapegoatTree/Extensions.cs index 8146088a..840d1770 100644 --- a/DataStructures/ScapegoatTree/Extensions.cs +++ b/DataStructures/ScapegoatTree/Extensions.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.ScapegoatTree; public static class Extensions diff --git a/DataStructures/ScapegoatTree/Node.cs b/DataStructures/ScapegoatTree/Node.cs index 624c25f1..f652a1b7 100644 --- a/DataStructures/ScapegoatTree/Node.cs +++ b/DataStructures/ScapegoatTree/Node.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.ScapegoatTree; /// diff --git a/DataStructures/ScapegoatTree/ScapegoatTree.cs b/DataStructures/ScapegoatTree/ScapegoatTree.cs index 8f0a1b55..3c515597 100644 --- a/DataStructures/ScapegoatTree/ScapegoatTree.cs +++ b/DataStructures/ScapegoatTree/ScapegoatTree.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.ScapegoatTree; /// diff --git a/DataStructures/SegmentTrees/SegmentTree.cs b/DataStructures/SegmentTrees/SegmentTree.cs index 24961af0..4c17940c 100644 --- a/DataStructures/SegmentTrees/SegmentTree.cs +++ b/DataStructures/SegmentTrees/SegmentTree.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.SegmentTrees; /// diff --git a/DataStructures/SegmentTrees/SegmentTreeApply.cs b/DataStructures/SegmentTrees/SegmentTreeApply.cs index e28d0364..83c779d2 100644 --- a/DataStructures/SegmentTrees/SegmentTreeApply.cs +++ b/DataStructures/SegmentTrees/SegmentTreeApply.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.SegmentTrees; /// diff --git a/DataStructures/SortedList.cs b/DataStructures/SortedList.cs index 1729547c..d9250025 100644 --- a/DataStructures/SortedList.cs +++ b/DataStructures/SortedList.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Generic; namespace DataStructures; diff --git a/DataStructures/Stack/ArrayBasedStack.cs b/DataStructures/Stack/ArrayBasedStack.cs index 06c561d9..8916d487 100644 --- a/DataStructures/Stack/ArrayBasedStack.cs +++ b/DataStructures/Stack/ArrayBasedStack.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.Stack; /// diff --git a/DataStructures/Stack/ListBasedStack.cs b/DataStructures/Stack/ListBasedStack.cs index bd1b6d11..d5840546 100644 --- a/DataStructures/Stack/ListBasedStack.cs +++ b/DataStructures/Stack/ListBasedStack.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Stack; /// diff --git a/DataStructures/Stack/QueueBasedStack.cs b/DataStructures/Stack/QueueBasedStack.cs index 5ac0e4a3..8464cc5c 100644 --- a/DataStructures/Stack/QueueBasedStack.cs +++ b/DataStructures/Stack/QueueBasedStack.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace DataStructures.Stack; public class QueueBasedStack diff --git a/DataStructures/Timeline.cs b/DataStructures/Timeline.cs index 45bc638d..d8628526 100644 --- a/DataStructures/Timeline.cs +++ b/DataStructures/Timeline.cs @@ -12,10 +12,7 @@ this data structure can be used to represent an ordered series of dates or times 330: Constantine move the capital to Constantinople. */ -using System; using System.Collections; -using System.Collections.Generic; -using System.Linq; namespace DataStructures; diff --git a/DataStructures/Tries/Trie.cs b/DataStructures/Tries/Trie.cs index 803a4146..8c065297 100644 --- a/DataStructures/Tries/Trie.cs +++ b/DataStructures/Tries/Trie.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Tries; /// @@ -70,10 +67,10 @@ public void Remove(string s) s += Mark; int index = 0; TrieNode match = PrefixQuery(s, ref index); - while(match.IsLeaf()) + while (match.IsLeaf()) { char c = match.Value; - if(match.Parent == null) + if (match.Parent == null) { break; } diff --git a/DataStructures/Tries/TrieNode.cs b/DataStructures/Tries/TrieNode.cs index b356b1cf..fbbed64e 100644 --- a/DataStructures/Tries/TrieNode.cs +++ b/DataStructures/Tries/TrieNode.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; - namespace DataStructures.Tries; /// diff --git a/DataStructures/UnrolledList/UnrolledLinkedList.cs b/DataStructures/UnrolledList/UnrolledLinkedList.cs index 006bdfc9..310697a7 100644 --- a/DataStructures/UnrolledList/UnrolledLinkedList.cs +++ b/DataStructures/UnrolledList/UnrolledLinkedList.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace DataStructures.UnrolledList; /// diff --git a/DataStructures/UnrolledList/UnrolledLinkedListNode.cs b/DataStructures/UnrolledList/UnrolledLinkedListNode.cs index b59c6ac0..7c6153c8 100644 --- a/DataStructures/UnrolledList/UnrolledLinkedListNode.cs +++ b/DataStructures/UnrolledList/UnrolledLinkedListNode.cs @@ -1,5 +1,3 @@ -using System; - namespace DataStructures.UnrolledList; ///