Your "simpler" version can be made to work with a sequence (as Stefan said), 
and actually using a tuple instead of an object (since they have comparison 
operators defined):
    
    
    import random
    import algorithm
    
    const
      els = 10_000_000
      maxval = 1_000_000
    
    type E = tuple
      r: int32
      i: int32
    
    proc main() =
      var a = newSeq[E](els)
      
      for i in 0..high(a):
        a[i].r = int32(rand(maxval))
        a[i].i = int32(i)
      a.sort()
      echo a[0..<5], " ... ", a[^5..^1]
    
    main()
    
    
    Run

Reply via email to