diff --git a/DStruct/BinaryTrees/AVLTree.cs b/DStruct/BinaryTrees/AVLTree.cs index 193ab49..ccf5907 100644 --- a/DStruct/BinaryTrees/AVLTree.cs +++ b/DStruct/BinaryTrees/AVLTree.cs @@ -5,7 +5,7 @@ namespace DStruct.BinaryTrees { - /// Represents a node-based, self-balancing . + /// Represents a node-based, self-balancing enhanced to implement an efficient indexer. /// The type of the values stored in the . It must implement the interface. public class AVLTree : IBinarySearchTree where T : IComparable { diff --git a/DStruct/BinaryTrees/BinarySearchTree.cs b/DStruct/BinaryTrees/BinarySearchTree.cs index 6fe013d..114f9aa 100644 --- a/DStruct/BinaryTrees/BinarySearchTree.cs +++ b/DStruct/BinaryTrees/BinarySearchTree.cs @@ -5,7 +5,7 @@ namespace DStruct.BinaryTrees { - /// Represents a node-based which isn't self-balancing. + /// Represents a node-based, non self-balancing enhanced to implement an efficient indexer. /// The type of the values stored in the . It must implement the interface. public class BinarySearchTree : IBinarySearchTree where T : IComparable, IComparable diff --git a/DStruct/BinaryTrees/RedBlackTree.cs b/DStruct/BinaryTrees/RedBlackTree.cs index 36a3997..a463529 100644 --- a/DStruct/BinaryTrees/RedBlackTree.cs +++ b/DStruct/BinaryTrees/RedBlackTree.cs @@ -7,7 +7,7 @@ namespace DStruct.BinaryTrees { - /// Represents a node-based, self-balancing . + /// Represents a node-based, self-balancing enhanced to implement an efficient indexer. /// The type of the values stored in the . It must implement the interface. public class RedBlackTree : IBinarySearchTree where T : IComparable { diff --git a/DStruct/Sparse/SparseMatrix.cs b/DStruct/Sparse/SparseMatrix.cs index a67fb28..9973fd5 100644 --- a/DStruct/Sparse/SparseMatrix.cs +++ b/DStruct/Sparse/SparseMatrix.cs @@ -4,7 +4,7 @@ namespace DStruct.Sparse { - struct Coordinate + readonly struct Coordinate { public readonly int X; public readonly int Y; diff --git a/DStruct/Trie/TrieDictionary.cs b/DStruct/Trie/TrieDictionary.cs index 56938d2..e1470d5 100644 --- a/DStruct/Trie/TrieDictionary.cs +++ b/DStruct/Trie/TrieDictionary.cs @@ -181,7 +181,7 @@ public void Add(string key, T value) } } - /// Gets the key/value pairs stored in the that are associated to keys that begin with the chosen prefix. Complexity: O(N*L) + /// Gets the key/value pairs stored in the that are associated to keys that begin with the chosen prefix. Complexity: O(N*L) /// The prefix of the keys to retrieve. /// containing all the key/value pairs associated to keys that begin with . /// is null. diff --git a/README.md b/README.md index d67c592..ccbfd34 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,65 @@ # DStruct.NET -### DefaultDictionary +**DStruct** is a library I implemented around the end of 2018, when I first approached C# and felt like it was lacking some important data structures that other languages like Python and C++ offer in their standard libraries. + +All the data structures implemented in the library are listed below, divided by category. + + +- ### [DefaultDictionary](docs/DefaultDictionary.md) + +
## Binary Trees -### IBinarySearchTree +Different implementations of binary search trees, enhanced to offer an efficient way to access the N-th element through an indexer. + + +- ### [IBinarySearchTree](docs/BinaryTrees/IBinarySearchTree.md) -### BinarySearchTree +- ### [BinarySearchTree](docs/BinaryTrees/BinarySearchTree.md) -### AVLTree +- ### [AVLTree](docs/BinaryTrees/AVLTree.md) -### RedBlackTree +- ### [RedBlackTree](docs/BinaryTrees/RedBlackTree.md) + +
## Heaps -### BinaryHeap +- ### [BinaryHeap](docs/Heaps/BinaryHeap.md) + +- ### [MaxHeap](docs/Heaps/MaxHeap.md) -### MaxHeap +- ### [MinHeap](docs/Heaps/MinHeap.md) -### MinHeap +
## Queues -### Deque +- ### [Deque](docs/Queues/Deque.md) + +- ### [PriorityQueue](docs/Queues/PriorityQueue.md) -### PriorityQueue +
## Trie -### Trie +- ### [Trie](docs/Trie/Trie.md) -### TrieDictionary +- ### [TrieDictionary](docs/Trie/TrieDictionary.md) + +
## Probabilistic -### CountMinSketch +- ### [CountMinSketch](docs/Probabilistic/CountMinSketch.md) + +- ### [BloomFilter](docs/Probabilistic/BloomFilter.md) -### BloomFilter +
## Sparse -### SparseArray +- ### [SparseArray](docs/Sparse/SparseArray.md) -### SparseMatrix +- ### [SparseMatrix](docs/Sparse/SparseMatrix.md) diff --git a/docs/BinaryTrees/AVLTree.md b/docs/BinaryTrees/AVLTree.md new file mode 100644 index 0000000..88db10e --- /dev/null +++ b/docs/BinaryTrees/AVLTree.md @@ -0,0 +1,43 @@ +# AVLTree + +Implements: [`IBinarySearchTree`](IBinarySearchTree.md) + +Represents a node-based, self-balancing **IBinarySearchTree** enhanced to implement an efficient indexer. + +
+ +## Constructors + +`AVLTree()` Initializes a new instance of **AVLTree** that is empty. + +`AVLTree(IEnumerable collection)` Initializes a new instance of **AVLTree** that contains every item from the input collection. + +`AVLTree(IComparer comparer)` Initializes a new instance of **AVLTree** that is empty and uses the specified **IComparer**. + +
+ +## Properties + +`int Count` Gets the number of elements stored in the **AVLTree**. Complexity: O(1) + +`T Min` Gets the minimum value element stored in the **AVLTree**. Complexity: O(LogN) + +`T Max` Gets the maximum value element stored in the **AVLTree**. Complexity: O(LogN) + +`T this[int index]` Gets the element at the specified index. Complexity: O(LogN) + +
+ +## Methods + +`int Insert(T value)` Inserts an element into the **AVLTree** and returns its index. Complexity: O(LogN) + +`bool Find(T value)` Determines whether the **AVLTree** contains a specific value. Complexity: O(LogN) + +`bool Remove(T value)` Removes one occurrence of a specific element from the **AVLTree**. Complexity: O(LogN) + +`T[] InOrderTraverse()` Returns the list of the elements stored in the **AVLTree** in-order. Complexity: O(N) + +`T[] PreOrderTraverse()` Returns the list of the elements stored in the **AVLTree** pre-order. Complexity: O(N) + +`T[] PostOrderTraverse()` Returns the list of the elements stored in the **AVLTree** post-order. Complexity: O(N) diff --git a/docs/BinaryTrees/BinarySearchTree.md b/docs/BinaryTrees/BinarySearchTree.md new file mode 100644 index 0000000..f217cdc --- /dev/null +++ b/docs/BinaryTrees/BinarySearchTree.md @@ -0,0 +1,43 @@ +# BinarySearchTree + +Implements: [`IBinarySearchTree`](IBinarySearchTree.md) + +Represents a node-based, non self-balancing **IBinarySearchTree** enhanced to implement an efficient indexer. + +
+ +## Constructors + +`BinarySearchTree()` Initializes a new instance of **BinarySearchTree** that is empty. + +`BinarySearchTree(IEnumerable collection)` Initializes a new instance of **BinarySearchTree** that contains every item from the input collection. + +`BinarySearchTree(IComparer comparer)` Initializes a new instance of **BinarySearchTree** that is empty and uses the specified **IComparer**. + +
+ +## Properties + +`int Count` Gets the number of elements stored in the **BinarySearchTree**. Complexity: O(1) + +`T Min` Gets the minimum value element stored in the **BinarySearchTree**. Complexity: avg O(LogN), worst O(N) + +`T Max` Gets the maximum value element stored in the **BinarySearchTree**. Complexity: avg O(LogN), worst O(N) + +`T this[int index]` Gets the element at the specified index. Complexity: avg O(LogN), worst O(N) + +
+ +## Methods + +`int Insert(T value)` Inserts an element into the **BinarySearchTree** and returns its index. Complexity: avg O(LogN), worst O(N) + +`bool Find(T value)` Determines whether the **BinarySearchTree** contains a specific value. Complexity: avg O(LogN), worst O(N) + +`bool Remove(T value)` Removes one occurrence of a specific element from the **BinarySearchTree**. Complexity: avg O(LogN), worst O(N) + +`T[] InOrderTraverse()` Returns the list of the elements stored in the **BinarySearchTree** in-order. Complexity: O(N) + +`T[] PreOrderTraverse()` Returns the list of the elements stored in the **BinarySearchTree** pre-order. Complexity: O(N) + +`T[] PostOrderTraverse()` Returns the list of the elements stored in the **BinarySearchTree** post-order. Complexity: O(N) diff --git a/docs/BinaryTrees/IBinarySearchTree.md b/docs/BinaryTrees/IBinarySearchTree.md new file mode 100644 index 0000000..3fb4ba0 --- /dev/null +++ b/docs/BinaryTrees/IBinarySearchTree.md @@ -0,0 +1,33 @@ +# IBinarySearchTree + +*This is an interface* + +Represents a Binary Tree in which the elements are sorted in order so that operations can use the principle of Binary Search. + +
+ +## Properties + +`int Count` Gets the number of elements stored in the **IBinarySearchTree**. + +`T Min` Gets the minimum value element stored in the **IBinarySearchTree**. + +`T Max` Gets the maximum value element stored in the **IBinarySearchTree**. + +`T this[int index]` Gets the element at the specified index. + +
+ +## Methods + +`int Insert(T value)` Inserts an element into the **IBinarySearchTree** and returns its index. + +`bool Find(T value)` Determines whether the **IBinarySearchTree** contains a specific value. + +`bool Remove(T value)` Removes one occurrence of a specific element from the **IBinarySearchTree**. + +`T[] InOrderTraverse()` Returns the list of the elements stored in the **IBinarySearchTree** in-order. + +`T[] PreOrderTraverse()` Returns the list of the elements stored in the **IBinarySearchTree** pre-order. + +`T[] PostOrderTraverse()` Returns the list of the elements stored in the **IBinarySearchTree** post-order. diff --git a/docs/BinaryTrees/RedBlackTree.md b/docs/BinaryTrees/RedBlackTree.md new file mode 100644 index 0000000..3e5be1a --- /dev/null +++ b/docs/BinaryTrees/RedBlackTree.md @@ -0,0 +1,43 @@ +# RedBlackTree + +Implements: [`IBinarySearchTree`](IBinarySearchTree.md) + +Represents a node-based, self-balancing **IBinarySearchTree** enhanced to implement an efficient indexer. + +
+ +## Constructors + +`RedBlackTree()` Initializes a new instance of **RedBlackTree** that is empty. + +`RedBlackTree(IEnumerable collection)` Initializes a new instance of **RedBlackTree** that contains every item from the input collection. + +`RedBlackTree(IComparer comparer)` Initializes a new instance of **RedBlackTree** that is empty and uses the specified **IComparer**. + +
+ +## Properties + +`int Count` Gets the number of elements stored in the **RedBlackTree**. Complexity: O(1) + +`T Min` Gets the minimum value element stored in the **RedBlackTree**. Complexity: O(LogN) + +`T Max` Gets the maximum value element stored in the **RedBlackTree**. Complexity: O(LogN) + +`T this[int index]` Gets the element at the specified index. Complexity: O(LogN) + +
+ +## Methods + +`int Insert(T value)` Inserts an element into the **RedBlackTree** and returns its index. Complexity: O(LogN) + +`bool Find(T value)` Determines whether the **RedBlackTree** contains a specific value. Complexity: O(LogN) + +`bool Remove(T value)` Removes one occurrence of a specific element from the **RedBlackTree**. Complexity: O(LogN) + +`T[] InOrderTraverse()` Returns the list of the elements stored in the **RedBlackTree** in-order. Complexity: O(N) + +`T[] PreOrderTraverse()` Returns the list of the elements stored in the **RedBlackTree** pre-order. Complexity: O(N) + +`T[] PostOrderTraverse()` Returns the list of the elements stored in the **RedBlackTree** post-order. Complexity: O(N) diff --git a/docs/DefaultDictionary.md b/docs/DefaultDictionary.md new file mode 100644 index 0000000..3c990be --- /dev/null +++ b/docs/DefaultDictionary.md @@ -0,0 +1,11 @@ +# DefaultDictionary + +Inherits: `Dictionary` + +Represents a collection of keys and values that handles the creation of a default value if the requested key is not currently present. + +
+ +## Properties + +`TValue this[TKey key]`: Gets or sets the value associated with the specified **key**. diff --git a/docs/Heaps/BinaryHeap.md b/docs/Heaps/BinaryHeap.md new file mode 100644 index 0000000..2fb4ae8 --- /dev/null +++ b/docs/Heaps/BinaryHeap.md @@ -0,0 +1,23 @@ +# BinaryHeap + +*This is an abstract class* + +Represents a tree in which the value of each node is greater ([**MaxHeap**](MaxHeap.md)) or smaller ([**MinHeap**](MinHeap.md)) than the value of all its children. + +
+ +## Properties + +`int Count` Gets the number of elements contained in the **BinaryHeap**. + +`bool IsEmpty` Determines whether the **BinaryHeap** is empty. + +
+ +## Methods + +`void Push(T value)` Inserts a new element into the **BinaryHeap**. Complexity: O(LogN) + +`T Pop()` Removes the element at the root of the **BinaryHeap** and returns its value, maintaining the **BinaryHeap** properties. Complexity: O(LogN) + +`T Peek()` Returns the value of the root of the **BinaryHeap** without removing it. Complexity: O(1) diff --git a/docs/Heaps/MaxHeap.md b/docs/Heaps/MaxHeap.md new file mode 100644 index 0000000..97af6ef --- /dev/null +++ b/docs/Heaps/MaxHeap.md @@ -0,0 +1,29 @@ +# MaxHeap + +Inherits: [`BinaryHeap`](BinaryHeap.md) + +Represents a **BinaryHeap** in which the value of each node is greater than the value of all its children. + +
+ +## Constructors + +`MaxHeap()` Initializes a new instance of **MaxHeap** that is empty and has the default initial capacity. + +`MaxHeap(IEnumerable collection)` Initializes a new instance of **MaxHeap** that contains every element from the input collection and has enough capacity to accomodate the number of elements copied. + +`MaxHeap(int capacity)` Initializes a new instance of **MaxHeap** that is empty and has the specified initial capacity. + +`MaxHeap(IComparer comparer)` Initializes a new instance of **MaxHeap** that is empty and uses the specified **IComparer**. + +
+ +## Properties + +Check [**BinaryHeap**](BinaryHeap.md) + +
+ +## Methods + +Check [**BinaryHeap**](BinaryHeap.md) diff --git a/docs/Heaps/MinHeap.md b/docs/Heaps/MinHeap.md new file mode 100644 index 0000000..b8cf39d --- /dev/null +++ b/docs/Heaps/MinHeap.md @@ -0,0 +1,29 @@ +# MinHeap + +Inherits: [`BinaryHeap`](BinaryHeap.md) + +Represents a **BinaryHeap** in which the value of each node is smaller than the value of all its children. + +
+ +## Constructors + +`MinHeap()` Initializes a new instance of **MinHeap** that is empty and has the default initial capacity. + +`MinHeap(IEnumerable collection)` Initializes a new instance of **MinHeap** that contains every element from the input collection and has enough capacity to accomodate the number of elements copied. + +`MinHeap(int capacity)` Initializes a new instance of **MinHeap** that is empty and has the specified initial capacity. + +`MinHeap(IComparer comparer)` Initializes a new instance of **MinHeap** that is empty and uses the specified **IComparer**. + +
+ +## Properties + +Check [**BinaryHeap**](BinaryHeap.md) + +
+ +## Methods + +Check [**BinaryHeap**](BinaryHeap.md) diff --git a/docs/Probabilistic/BloomFilter.md b/docs/Probabilistic/BloomFilter.md new file mode 100644 index 0000000..4fc0c1d --- /dev/null +++ b/docs/Probabilistic/BloomFilter.md @@ -0,0 +1,21 @@ +# BloomFilter + +Represents a probabilistic data structure that is optimal to determine if an object isn't or may be present in a set. + +
+ +## Constructors + +`BloomFilter(int n, double p)` Initialized a new instance of **BloomFilter** with the specified desired capacity and false-positive probability. + +`BloomFilter(int m, int k)` Initialized a new instance of **BloomFilter** with the specified width and depth. + +
+ +## Methods + +`void Add(object obj)` Adds an object to the **BloomFilter**. Complexity: O(1) + +`bool Contains(object obj)` Determines if the specified object isn't or may be in the **BloomFilter**. Complexity: O(1) + +`void Clear()` Removes all objects from the **BloomFilter**. diff --git a/docs/Probabilistic/CountMinSketch.md b/docs/Probabilistic/CountMinSketch.md new file mode 100644 index 0000000..185a01a --- /dev/null +++ b/docs/Probabilistic/CountMinSketch.md @@ -0,0 +1,23 @@ +# CountMinSketch + +Represents a probabilistic data structure that serves as a memory efficient frequency table for objects in a stream of data. + +
+ +## Constructors + +`CountMinSketch(double epsilon, double delta)` Initializes a new instance of **CountMinSketch** in which the error of a query result is within a factor of *epsilon* with probability *1 - delta*. + +`CountMinSketch(int width, int depth)` Initializes a new instance of **CountMinSketch** with the specified width and depth. + +
+ +## Methods + +`void Add(object obj)` Increments the count of the given object by one. Complexity: O(1) + +`void Add(object obj, int count)` Increments the count of the given object by a specified amount. Complexity: O(1) + +`int Estimate(object obj)` Estimates the count of an object in the **CountMinSketch**. The returned number is always equal to or greater than the actual count of the object. Complexity: O(1) + +`void Clear()` Removes all objects from the **CountMinSketch**. diff --git a/docs/Queues/Deque.md b/docs/Queues/Deque.md new file mode 100644 index 0000000..3ee918b --- /dev/null +++ b/docs/Queues/Deque.md @@ -0,0 +1,55 @@ +# Deque + +Implements: `IEnumerable` + +Represents a double ended queue for which insertion and retrieval of elements close to either of the ends is very efficient. + +
+ +## Constructors + +`Deque()` Initializes a new instance of **Deque** that is empty and has the default initial capacity. + +`Deque(int capacity)` Initializes a new instance of **Deque** that is empty and has the specified initial capacity. + +`Deque(IEnumerable collection)` Initializes a new instance of **Deque** that contains every element from the input collection and has enough capacity to accomodate the number of elements copied. + +
+ +## Properties + +`int Count` Gets the number of elements contained in the **Deque**. + +`int Capacity` Gets the maximum number of elements the internal data structure can hold without resizing. + +`T Back` Returns the first element at the rear of the **Deque** without removing it. Complexity: O(1) + +`T Front` Returns the first element at the front of the **Deque** without removing it. Complexity: O(1) + +`T this[int index]` Gets or sets the element at the specified position of the **Deque**. Complexity: O(1) + +
+ +## Methods + +`void PushBack(T item)` Inserts a new element to the rear of the **Deque**. Complexity: O(1) + +`void PushFront(T item)` Inserts a new element to the front of the **Deque**. Complexity: O(1) + +`T PopBack()` Removes the element at the rear of the **Deque** and returns its value. Complexity: O(1) + +`T PopFront()` Removes the element at the front of the **Deque** and returns its value. Complexity: O(1) + +`void Clear()` Removes all elements from the **Deque**. Complexity: O(1) + +`bool Contains(T item)` Determines whether the **Deque** contains a specific element. Complexity: O(N) + +`void CopyTo(T[] array, int arrayIndex)` Copies the elements of the **Deque** to an **Array**, starting at a particular **Array** index. Complexity: O(N) + +`bool Remove(T item)` Removes the first occurrence of a specific element from the **Deque**. Complexity: O(N) + +`int IndexOf(T item)` Searches for the specified element and returns the zero-based index of the first occurrence within the entire **Deque**. Complexity: O(N) + +`void Insert(int index, T item)` Inserts an element into the **Deque** at the specified index. Complexity: O(N) + +`void RemoveAt(int index)` Removes the element at the specified index of the **Deque**. Complexity: O(N) diff --git a/docs/Queues/PriorityQueue.md b/docs/Queues/PriorityQueue.md new file mode 100644 index 0000000..a6a5ecc --- /dev/null +++ b/docs/Queues/PriorityQueue.md @@ -0,0 +1,33 @@ +# PriorityQueue + +Implements: `IEnumerable` + +Represents a Queue in which the elements are ordered using a specified priority. + +
+ +## Constructors + +`PriorityQueue()` Initializes a new instance of **PriorityQueue** which is empty and ordered by ascending priority value (higher priority first). + +`PriorityQueue(PriorityQueueOrder order)` Initializes a new instance of **PriorityQueue** which is empty and ordered by ascending or descending priority value. + +`PriorityQueue(int capacity, PriorityQueueOrder order)` Initializes a new instance of **PriorityQueue** which is ordered by ascending or descending priority value and has the specified initial capacity. + +
+ +## Properties + +`int Count` Gets the number of elements contained in the **PriorityQueue**. + +`bool IsEmpty` Determines whether the **PriorityQueue** is empty. + +
+ +## Methods + +`void Push(T value, int priority)` Inserts a new item into the **PriorityQueue**, in a position relative to the given priority. Complexity: O(LogN) + +`PriorityQueueNode Pop()` Removes the element with the highest (or lowest) priority from the **PriorityQueue** and returns its value. Complexity: O(LogN) + +`PriorityQueueNode Peek()` Returns the **PriorityQueueNode** with the highest (or lowest) priority in the **PriorityQueue** wihout removing it. Complexity: O(1) diff --git a/docs/Sparse/SparseArray.md b/docs/Sparse/SparseArray.md new file mode 100644 index 0000000..69372eb --- /dev/null +++ b/docs/Sparse/SparseArray.md @@ -0,0 +1,31 @@ +# SparseArray + +Implements: `IEnumerable` + +Provides a memory efficient implementation of an array in which most of the elements have the default value. + +
+ +## Constructors + +`SparseArray()` Initializes a new instance of **SparseArray** with no specified length. + +`SparseArray(int length)` Initializes a new instance of **SparseArray** with the fixed specified length. + +`SparseArray(T defaultValue)` Initializes a new instance of **SparseArray** with the specified default element value. + +`SparseArray(int length, T defaultValue)` Initializes a new instance of **SparseArray** with the fixed specified length and default element value. + +
+ +## Properties + +`int Count` Gets the number of elements with value other than the default one. + +`int Length` Gets the total length of the **SparseArray**. + +`ICollection Indices` Gets an **ICollection** containing the indices of the elements with value other than the default one. + +`ICollection Values` Gets an **ICollection** containing the elements with value other than the default one. + +`T this[int index]` Gets or sets the value of the element at the specified index of the **SparseArray**. Complexity: O(1) diff --git a/docs/Sparse/SparseMatrix.md b/docs/Sparse/SparseMatrix.md new file mode 100644 index 0000000..89a6de0 --- /dev/null +++ b/docs/Sparse/SparseMatrix.md @@ -0,0 +1,29 @@ +# SparseMatrix + +Implements: `IEnumerable` + +Provides a memory efficient implementation of a matrix in which most of the elements have the default value. + +
+ +## Constructors + +`SparseMatrix()` Initializes a new instance of **SparseMatrix**. + +`SparseMatrix(T defaultValue)` Initializes a new instance of **SparseMatrix** with the specified default element value. + +
+ +## Properties + +`int Count` Gets the number of elements with value other than the default one. + +`int MinX` Gets the minimum X-index of the **SparseMatrix**. + +`int MinY` Gets the minimum Y-index of the **SparseMatrix**. + +`int MaxX` Gets the maximum X-index of the **SparseMatrix**. + +`int MaxY` Gets the maximum Y-index of the **SparseMatrix**. + +`T this[int index0, int index1]` Gets or sets the value of the element at the specified coordinate of the **SparseMatrix**. Complexity: O(1) diff --git a/docs/Trie/Trie.md b/docs/Trie/Trie.md new file mode 100644 index 0000000..ac98cc7 --- /dev/null +++ b/docs/Trie/Trie.md @@ -0,0 +1,47 @@ +# Trie + +Implements: `ICollection` `IReadOnlyCollection` + +Represents a collection of strings that is very efficient at retrieving all the stored words with a common prefix. + +
+ +## Constructors + +`Trie()` Initializes a new instance of **Trie** that is empty. + +`Trie(IEnumerable collection)` Initializes a new instance of **Trie** that contains every item from the input collection. + +
+ +## Properties + +`int Count` Gets the number of elements contained in the **Trie**. Complexity: O(1) + +
+ +## Methods + +`void Add(string value)` Adds an element to the **Trie**. Complexity: O(L) + +`void Clear()` Removes all elements from the **Trie**. + +`void AddAll(IEnumerable collection)` Adds the elements of the specified collection to the **Trie**. Complexity: O(N*L) + +`async Task AddAllAsync(IEnumerable collection)` Adds the elements of the specified collection to the **Trie**, async. Complexity: O(N*L) + +`void CopyTo(string[] array, int arrayIndex)` Copies the elements of the **Trie** to an **Array**, starting at a particular **Array** index. Complexity: O(N*L) + +`bool Remove(string value)` Removes a specific element from the **Trie**. Complexity: O(L) + +`void RemoveAll(IEnumerable collection)` Removes the elements of the specified collection from the **Trie**. Complexity: O(N*L) + +`bool Contains(string value)` Determines whether the **Trie** contains a specific value. Complexity: O(L) + +`bool ContainsAll(IEnumerable collection)` Determines whether the **Trie** contains a specific collection of values. Complexity: O(N*L) + +`bool ContainsPrefix(string prefix)` Determines whether the **Trie** contains a specific prefix. Complexity: O(L) + +`string[] GetWithPrefix(string prefix)` Gets the strings stored in the **Trie** that begin with the chosen prefix. Complexity: O(N*L) + +`string[] ToArray()` Returns an **Array** containing all the elements stored in the **Trie**. diff --git a/docs/Trie/TrieDictionary.md b/docs/Trie/TrieDictionary.md new file mode 100644 index 0000000..93fe554 --- /dev/null +++ b/docs/Trie/TrieDictionary.md @@ -0,0 +1,55 @@ +# TrieDictionary + +Implements: `IDictionary` `IReadOnlyDictionary` + +Represents a dictionary in which the key/value coupling is implemented via a Trie. + +
+ +## Constructors + +`TrieDictionary()` Initializes a new instance of **TrieDictionary** that is empty. + +`TrieDictionary(IEnumerable> collection)` Initializes a new instance of **TrieDictionary** that contains every key/value pair from the input collection. + +
+ +## Properties + +`int Count` Gets the number of elements in the **TrieDictionary**. + +`ICollection Keys` Gets an **ICollection** containing the keys of the **TrieDictionary**. + +`ICollection Values` Gets an **ICollection** containing the values of the **TrieDictionary**. + +`T this[string key]` Gets or sets the element with the specified key. + +
+ +## Methods + +`void Add(string key, T value)` Adds a key/value pair to the **TrieDictionary**. Complexity: O(L) + +`void Add(KeyValuePair item)` Adds a key/value pair to the **TrieDictionary**. Complexity: O(L) + +`void AddAll(IEnumerable> collection)` Adds a collection of key/value pairs to the **TrieDictionary**. Complexity: O(N*L) + +`async Task AddAllAsync(IEnumerable> collection)` Adds a collection of key/value pairs to the **TrieDictionary**, async. Complexity: O(N*L) + +`void Clear()` Removes all elements from the **TrieDictionary**. + +`bool Contains(KeyValuePair item)` Determines whether the **TrieDictionary** contains a specific key/value pair. Complexity: O(L) + +`bool ContainsAll(IEnumerable> collection)` Determines whether the **TrieDictionary** contains a specific collection of key/value pairs. Complexity: O(N*L) + +`void CopyTo(KeyValuePair[] array, int arrayIndex)` Copies the key/value pairs of the **TrieDictionary** to an **Array**, starting at a particular **Array** index. Complexity: O(N*L) + +`bool Remove(KeyValuePair item)` Removes a specific key/value pair from the **TrieDictionary**. Complexity: O(L) + +`bool ContainsKey(string key)` Determines whether the **TrieDictionary** contains a specific key. Complexity: O(L) + +`KeyValuePair[] GetWithPrefix(string prefix)` Gets the key/value pairs stored in the **TrieDictionary** that are associated to keys that begin with the chosen prefix. Complexity: O(N*L) + +`bool Remove(string key)` Removes a specific key from the **TrieDictionary**. Complexity: O(L) + +`bool TryGetValue(string key, out T value)` Gets the value associated with the specified key. Complexity: O(L)