Project

General

Profile

Bug #1274

SortBy and SortedBy sometimes give wrong result

Added by John Abbott almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Urgent
Assignee:
Category:
bug
Target version:
Start date:
29 Apr 2019
Due date:
% Done:

100%

Estimated time:
1.55 h
Spent time:

Description

In CoCoA5 the SortBy and SortedBy functions sometimes give wrong answers!

Here is an example:

L := [8,  2,  9,  10,  15,  3,  1,  14,  5,  11,  13,  4,  16,  17,  6,  12,  7];
SortedBy(L, func(a,b) return a<b; endfunc);
[1,  2,  4,  5,  6,  3,  7,  8,  9,  10,  11,  12,  13,  14,  15,  16,  17]

Ouch!

Note: reported by Julian Danner (Passau)

History

#1 Updated by John Abbott almost 5 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

Example found by calling SortedBy on random permutations of 1..17.
Seems to work find for lists with only 16 or fewer elements.

The sorting impl calls InsertionSortBy when the list is shorter than 16.

#2 Updated by John Abbott almost 5 years ago

  • Status changed from In Progress to Resolved
  • Assignee set to John Abbott
  • % Done changed from 10 to 70

The bug was at the end of the first loop in QuickSortBy1 where the case Up = Down was not handled.

Added 1 line; seems OK now. Will check in ASAP.

Updated exbugs.cocoa5 too.

#3 Updated by John Abbott almost 5 years ago

  • Description updated (diff)
  • Estimated time set to 1.55 h

#4 Updated by Anna Maria Bigatti almost 5 years ago

can you send me the line you added?

#5 Updated by John Abbott over 4 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 70 to 100

This was actually fixed some time ago; I just forgot to tell redmine.

Also available in: Atom PDF