HashSet<T>
Overview
Represents an unordered collection of objects.
Elements in this collection can be accessed only using enumerator. Hashset<T> accepts nil as a valid value for reference types and does not allows duplicate elements.
Note: On Nougat platform set internally converts nil
to the NSNull
type.
Use case
Due to its nature Hashset<T> outperforms List<T> in some operations (such Remove, Contains) in cost of preserving items order, so you can use set when speed of those operations is crucial.
var Readers := new HashSet<String>;
Readers.Add("Aiden");
Readers.Add("Jayden");
Readers.Add("Ethan");
writeLn("Readers:");
Readers.ForEach(item -> writeLn(item));
writeLn;
var Writers := new HashSet<String>;
Writers.Add("Jayden");
Writers.Add("Jacob");
writeLn("Writers:");
Writers.ForEach(item -> writeLn(item));
writeLn;
writeLn("All users:");
Writers.ForEach(item -> Readers.Add(item));
Readers.ForEach(item -> writeLn(item));
Output:
Readers:
Aiden
Jayden
Ethan
Writers:
Jayden
Jacob
All users:
Aiden
Jayden
Ethan
Jacob
Loops
Please note: Instead of using for/each or for/in loops in the collections please use ForEach methods.
For example:
var Items := new List<String>(["One", "Two", "Three"]);
Items.ForEach(item -> DoSomething(item));
Location
- Reference: Sugar
- Namespace: Sugar.Collections
constructor
Creates a new instance of the class.
constructor(Set: HashSet<T>)
HashSet<T>(HashSet<T> Set)
init(_ Set: HashSet<T>)
HashSet<T>(HashSet<T> Set)
Sub New(Set As HashSet<T>)
Parameters:
- Set:
Add mapped
Adds an object to the set and returns value which idicates whether object was added.
method Add(Item: T): Boolean
Boolean Add(T Item)
func Add(_ Item: T) -> Boolean
Boolean Add(T Item)
Function Add(Item As T) As Boolean
Parameters:
- Item: The object to be added.
Contains mapped
Determines whether an element is in the set.
method Contains(Item: T): Boolean
Boolean Contains(T Item)
func Contains(_ Item: T) -> Boolean
Boolean Contains(T Item)
Function Contains(Item As T) As Boolean
Parameters:
- Item: The object to locate in the set.
Count
Gets the number of elements contained in the set.
property Count: Int32 read;
Int32 Count { get; }
var Count: Int32 { get{} }
Int32 Count { __get; }
ReadOnly Property Count() As Int32
ForEach mapped
method ForEach(Action: Action<T>)
void ForEach(Action<T> Action)
func ForEach(_ Action: Action<T>)
void ForEach(Action<T> Action)
Sub ForEach(Action As Action<T>)
Parameters:
- Action:
Intersect mapped
method Intersect(Set: HashSet<T>)
void Intersect(HashSet<T> Set)
func Intersect(_ Set: HashSet<T>)
void Intersect(HashSet<T> Set)
Sub Intersect(Set As HashSet<T>)
Parameters:
- Set:
IsSubsetOf mapped
method IsSubsetOf(Set: HashSet<T>): Boolean
Boolean IsSubsetOf(HashSet<T> Set)
func IsSubsetOf(_ Set: HashSet<T>) -> Boolean
Boolean IsSubsetOf(HashSet<T> Set)
Function IsSubsetOf(Set As HashSet<T>) As Boolean
Parameters:
- Set:
IsSupersetOf mapped
method IsSupersetOf(Set: HashSet<T>): Boolean
Boolean IsSupersetOf(HashSet<T> Set)
func IsSupersetOf(_ Set: HashSet<T>) -> Boolean
Boolean IsSupersetOf(HashSet<T> Set)
Function IsSupersetOf(Set As HashSet<T>) As Boolean
Parameters:
- Set:
Remove mapped
Removes specified object from the set.
method Remove(Item: T): Boolean
Boolean Remove(T Item)
func Remove(_ Item: T) -> Boolean
Boolean Remove(T Item)
Function Remove(Item As T) As Boolean
Parameters:
- Item: The object to remove.
SetEquals mapped
method SetEquals(Set: HashSet<T>): Boolean
Boolean SetEquals(HashSet<T> Set)
func SetEquals(_ Set: HashSet<T>) -> Boolean
Boolean SetEquals(HashSet<T> Set)
Function SetEquals(Set As HashSet<T>) As Boolean
Parameters:
- Set:
Union mapped
method Union(Set: HashSet<T>)
void Union(HashSet<T> Set)
func Union(_ Set: HashSet<T>)
void Union(HashSet<T> Set)
Sub Union(Set As HashSet<T>)
Parameters:
- Set:
Count
Gets the number of elements contained in the set.
constructor
Creates a new instance of the class.
constructor(Set: HashSet<T>)
HashSet<T>(HashSet<T> Set)
init(_ Set: HashSet<T>)
HashSet<T>(HashSet<T> Set)
Sub New(Set As HashSet<T>)
Parameters:
- Set:
Add mapped
Adds an object to the set and returns value which idicates whether object was added.
method Add(Item: T): Boolean
Boolean Add(T Item)
func Add(_ Item: T) -> Boolean
Boolean Add(T Item)
Function Add(Item As T) As Boolean
Parameters:
- Item: The object to be added.
Contains mapped
Determines whether an element is in the set.
method Contains(Item: T): Boolean
Boolean Contains(T Item)
func Contains(_ Item: T) -> Boolean
Boolean Contains(T Item)
Function Contains(Item As T) As Boolean
Parameters:
- Item: The object to locate in the set.
ForEach mapped
method ForEach(Action: Action<T>)
void ForEach(Action<T> Action)
func ForEach(_ Action: Action<T>)
void ForEach(Action<T> Action)
Sub ForEach(Action As Action<T>)
Parameters:
- Action:
Intersect mapped
method Intersect(Set: HashSet<T>)
void Intersect(HashSet<T> Set)
func Intersect(_ Set: HashSet<T>)
void Intersect(HashSet<T> Set)
Sub Intersect(Set As HashSet<T>)
Parameters:
- Set:
IsSubsetOf mapped
method IsSubsetOf(Set: HashSet<T>): Boolean
Boolean IsSubsetOf(HashSet<T> Set)
func IsSubsetOf(_ Set: HashSet<T>) -> Boolean
Boolean IsSubsetOf(HashSet<T> Set)
Function IsSubsetOf(Set As HashSet<T>) As Boolean
Parameters:
- Set:
IsSupersetOf mapped
method IsSupersetOf(Set: HashSet<T>): Boolean
Boolean IsSupersetOf(HashSet<T> Set)
func IsSupersetOf(_ Set: HashSet<T>) -> Boolean
Boolean IsSupersetOf(HashSet<T> Set)
Function IsSupersetOf(Set As HashSet<T>) As Boolean
Parameters:
- Set:
Remove mapped
Removes specified object from the set.
method Remove(Item: T): Boolean
Boolean Remove(T Item)
func Remove(_ Item: T) -> Boolean
Boolean Remove(T Item)
Function Remove(Item As T) As Boolean
Parameters:
- Item: The object to remove.
SetEquals mapped
method SetEquals(Set: HashSet<T>): Boolean
Boolean SetEquals(HashSet<T> Set)
func SetEquals(_ Set: HashSet<T>) -> Boolean
Boolean SetEquals(HashSet<T> Set)
Function SetEquals(Set As HashSet<T>) As Boolean
Parameters:
- Set:
Union mapped
method Union(Set: HashSet<T>)
void Union(HashSet<T> Set)
func Union(_ Set: HashSet<T>)
void Union(HashSet<T> Set)
Sub Union(Set As HashSet<T>)
Parameters:
- Set: