Made interval object generic using templates.

The input intervals with less than <split value> elements assumed it was
sorted, now always sorts.