Class SortedHashSet<T>
A sorted HashSet implementation using balanced binary search tree. IEnumerable will enumerate in sorted order. This may be better than regular HashSet implementation which can give o(K) in worst case (but O(1) amortized when collisions K is avoided).
Inherited Members
Namespace: Advanced.Algorithms.DataStructures
Assembly: Advanced.Algorithms.dll
Syntax
public class SortedHashSet<T> : IEnumerable<T>, IEnumerable where T : IComparable
Type Parameters
Name | Description |
---|---|
T | The value datatype. |
Constructors
SortedHashSet()
Declaration
public SortedHashSet()
Properties
Count
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Add(T)
Add a new value. Time complexity: O(log(n)).
Declaration
public void Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to add. |
Contains(T)
Does this hash table contains the given value. Time complexity: O(log(n)).
Declaration
public bool Contains(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to check. |
Returns
Type | Description |
---|---|
Boolean | True if this hashset contains the given value. |
GetEnumerator()
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> |
Next(T)
Return the next higher value after given value in this hashset. Time complexity: O(log(n)).
Declaration
public T Next(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
T | Null if the given value does'nt exist or next value does'nt exist. |
Previous(T)
Return the next lower value before given value in this HashSet. Time complexity: O(log(n)).
Declaration
public T Previous(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
T | Null if the given value does'nt exist or previous value does'nt exist. |
Remove(T)
Remove the given value. Time complexity: O(log(n)).
Declaration
public void Remove(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to remove. |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |