fix/improvement for sortedpairs iterator

the compare function is in now the form comp(t,a,b) where t is the
table and a,b the keys to be compared. That allows to make compare
functions based on table values, comparing t[a] with t[b]