Wednesday, November 15, 2017

Order string (VI)

Nov. 15, 2017


Algorithm Study and Code Review


Here is the code related to the algorithm. I like to write a blog on the code. The main idea is to use primitive type string, just add index to the first element of string array, avoid a struct or a class definition. Kind of tricky. 


Follow up study 

Nov. 16, 2017

It is always a good idea to search code review to read IComparable<T> code review. I sepnt over 20 minutes to read the algorithm: Dynamically sorting with IComparer. And one of statement in the code review reads like the following:

This
public int CompareTo(ProductSortAttribute other)
{
    if (this.Index == other.Index)
    {
         return 0;
    }

    if (this.Index > other.Index)
    {
         return 1;
    }

    return -1;
}
can be shortened to
public int CompareTo(ProductSortAttribute other) {
    return this.Index.CompareTo(other.Index);
}
Since Int32 also implements Comparable<T>.

What is Int32?



Here are a list of things Julia starts to her independent study:
1. What is Int32? A structure
2. What interfaces does Int32 implements? IComparable<T>, IFormattable, IConvertible.
3. Where is the source code of Int32 in mscorlib? Link is here.

Comparable <T>  study



Sometimes, it is so easy to find an excellent lecture notes, and then I can follow quickly how to write basic comparer. Here is the one.

No comments:

Post a Comment