Changeset 0e60443 in mainline


Ignore:
Timestamp:
2019-02-08T12:55:28Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
d64303b
Parents:
bc694b0
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-01-12 18:51:12)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-02-08 12:55:28)
Message:

Correcting test of the comparison function

This commit removes the old file description with qsort
and gnome sort. Furthermore it corrects how the return
value from the comparison function gets handled. In the
previous version the comparison function must have returned
-1, 0 or 1. The updated version will accept values smaller
than -1 too. This change was needed since the documentation
does not specify it and because all other *cmp functions
tend to return values smaller than -1 (as example strcmp())

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/gsort.c

    rbc694b0 r0e60443  
    3333/**
    3434 * @file
    35  * @brief Sorting functions.
     35 * @brief Gnome Sort.
    3636 *
    37  * This files contains functions implementing several sorting
    38  * algorithms (e.g. quick sort and gnome sort).
     37 * This file contains an implementation of gnome sort
    3938 *
    4039 */
     
    8079                if ((i != 0) &&
    8180                    (cmp(INDEX(data, i, elem_size),
    82                     INDEX(data, i - 1, elem_size), arg) == -1)) {
     81                    INDEX(data, i - 1, elem_size), arg) <= -1)) {
    8382                        memcpy(slot, INDEX(data, i, elem_size), elem_size);
    8483                        memcpy(INDEX(data, i, elem_size), INDEX(data, i - 1, elem_size),
Note: See TracChangeset for help on using the changeset viewer.