Monday, June 25, 2018

C# HashSet class

June 25, 2018

Introduction


It is the algorithm called Sudoku solver, my favorite one. I did have a mock interview on June 23, 2018. I wrote C# solution and came cross the question, do HashSet class have Remove API. I notice that it is time for me to spend time to memorize all APIs of C# HashSet class.

HashSet class


There are so many things to do once I decide to start to memorize HashSet class.

I plan to study IEqualityComparer interface, and then I read HashSet source code.

I will write down all API here. It is important to try to memorize all API first. And then I should come out questions to ask about class design, implementation detail.


Follow up 


7 constructors

HashSet<T>()
HashSet<T>(IEnumerable<T>)
HashSet<T>(IEnumerable<T>, IEqualityComparer<T>)
HashSet<T>(IEqualityComparer<T>)
HashSet<T>(Int32)
HashSet<T>(Inte32, IEqualityComparer<T>)
HashSet<T>(SerializationInfo, StreamingContext)

Properties

Comparer
Count

Methods

Add(T)
Clear()
Contains(T)
CopyTo(T[]) - it is convenient to call - to array is so easy
CopyTo(T[], Int32)  - copies the elements of a HashSet<T> object to an array, starting at the specified array index
CopyTo(T[], Int32, Int32)
Static - CreateSetComparer() - it takes me more than 10 minutes to read - ask why it is static?
Equals(Object)
ExceptWith(IEnumerable<T>) - Removes all elements in the specified collection from the current HashSet<T> object.
Virtual - Finalize() - understand why it is virtural ?

GetEnumerator() - Returns an eneumerator taht iterates through a HashSet<T> object
GetHashCode()-
GetObjectData(SerializationInfo, StreamingContext)
GetType() - Gets the Type of the current instance.
IntersectWith(IEnumerable<T>) - Modifies the current HashSet<t> object ot contain only elements that are present in that object and in the specified collection.
IsProperSubsetOf(IEnumerable<T>) - Determines whether a HashSet<T> object is a proper subset of the specified collection
IsProperSupersetOf(IEnumerable<T>) - supset
IsSubsetOf(IEnumerable<T>)



20 minutes study


Plan to spend 20 minutes quick study of five categories of types

GetType() - Gets the Type of the current instance.
Spend 10 minutes to read the code using GetType()


Classes -> System.Object
Value types -> System.ValueType
Interfaces - System.Object
Enumerations - System.Enum
Delegates -> System.MulticastDelegate


10 minutes to read

IsProperSubsetOf API docuement is here.



Questions asked:

Why CreateSetComparer() is static?
Why Finalize() is virtual?
what is proper subset? subset vs proper subset?

No comments:

Post a Comment