[vlc-devel] [PATCH 1/2] core: added sort by date (prepare for playlist fix)

Marcel Schnirring ms at marcel-schnirring.de
Mon Nov 28 22:04:22 CET 2016


Hi Filip,

Thanks for your feedback!
I will update my commit this way!

When I was writing this code, I was wondering if a rework of the underlying
sorting algorithm would make sense.

Using a stable sorting algorithm would allow the user to choose how he want
to sort equal entries in one property. This way, all the extra handling of
equal elements can be removed.

For example when you would like to sort based on Artist, Date, Album,
Title, you would click the column headers in reverse order (Title, Album,
Date, Artist).

Do you think this approach would make sense?

*Mit freundlichen Grüßen / Kind regards,*
Marcel Schnirring

*Heilbronner Strasse 36*
*76131 Karlsruhe*
*Deutschland / Germany*
*Email: ms at marcel-schnirring.de <ms at marcel-schnirring.de>*
*Mobile: (+49) 178 198 37 61 <%28%2B49%29%20178%20198%2037%2061>*

On Sun, Nov 27, 2016 at 9:59 PM, Filip Roséen <filip at atch.se> wrote:

> Hi Marcel,
>
> On 2016-11-26 23:55, Marcel Schnirring wrote:
>
>  Re-asking for review after a week has passed...
>  ---
>   include/vlc_playlist.h                       |  3 ++-
>   src/playlist/sort.c                          | 14 +++++++++++++-
>   2 files changed, 15 insertions(+), 2 deletions(-)
>
>  diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
>  index 5fef490..742372c 100644
>  --- a/include/vlc_playlist.h
>  +++ b/include/vlc_playlist.h
>  @@ -186,7 +186,8 @@ struct playlist_t
>       DEF( SORT_DESCRIPTION )\
>       DEF( SORT_RATING )\
>       DEF( SORT_URI )\
>  -    DEF( SORT_DISC_NUMBER )
>  +    DEF( SORT_DISC_NUMBER )\
>  +    DEF( SORT_DATE )
>
>   #define DEF( s ) s,
>   enum
>  diff --git a/src/playlist/sort.c b/src/playlist/sort.c
>  index 588bd35..68c15a5 100644
>  --- a/src/playlist/sort.c
>  +++ b/src/playlist/sort.c
>  @@ -226,6 +226,19 @@ SORTFN( SORT_ALBUM, first, second )
>       return i_ret;
>   }
>
>  +SORTFN( SORT_DATE, first, second )
>  +{
>  +    int i_ret = meta_sort( first, second, vlc_meta_Date, true );
>  +    /* Items came from the same date: compare the albums */
>  +    if( i_ret == 0 )
>  +        i_ret = meta_sort( first, second, vlc_meta_Album, false );
>  +    /* Items came from the same album: compare the track numbers */
>  +    if( i_ret == 0 )
>  +        i_ret = meta_sort( first, second, vlc_meta_TrackNumber, true );
>  +
>
> Given that the above is the exactly same logic as defined by SORTFN(
> SORT_ALBUM, ... ), you are far better off invoking this function directly
> rather than explicitly doing the same thing.
>
> SORTFN( SORT_DATE, first, second )
> {
>   int i_ret = meta_sort( first, second, vlc_meta_Date, true );
>
>   if( i_ret == 0 )
>     return proto_SORT_ALBUM( first, second);
> }
>
> See SORTFIN( SORT_ARTIST, ... ) for an equivalent example.
>
>  +    return i_ret;
>  +}
>  +
>   SORTFN( SORT_ARTIST, first, second )
>   {
>       int i_ret = meta_sort( first, second, vlc_meta_Artist, false );
>  @@ -361,4 +374,3 @@ static const sortfn_t sorting_fns[NUM_SORT_FNS][2] =
>   #define DEF( a ) { cmp_a_##a, cmp_d_##a },
>   { VLC_DEFINE_SORT_FUNCTIONS };
>   #undef  DEF
>  -
>  --
>  2.7.4
>
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20161128/1f56c1c2/attachment.html>


More information about the vlc-devel mailing list