<commit_before>! Copyright (C) 2014 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: kernel locals math math.order math.ranges sequences
sequences.private ;

IN: sorting.bubble

<PRIVATE

:: (bubble-sort!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
    seq length [
        1 - f over [0,b) [| i |
            i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ =
            [ i 1 + i [ seq set-nth-unsafe ] bi-curry@ bi* drop t ]
            [ 2drop ] if
        ] each
    ] loop drop ; inline

PRIVATE>

: bubble-sort! ( seq quot: ( obj1 obj2 -- <=> ) -- )
    over length 2 < [ 2drop ] [ (bubble-sort!) ] if ; inline

: natural-bubble-sort! ( seq -- )
    [ <=> ] bubble-sort! ;
<commit_msg>sorting.bubble: loop up to last changed index.<commit_after>! Copyright (C) 2014 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: kernel locals math math.order math.ranges sequences
sequences.private ;

IN: sorting.bubble

<PRIVATE

:: (bubble-sort!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
    seq length 1 - [
        f over [0,b) [| i |
            i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ =
            [ i 1 + i [ seq set-nth-unsafe ] bi-curry@ bi* 2drop i t ]
            [ 2drop ] if
        ] each
    ] loop drop ; inline

PRIVATE>

: bubble-sort! ( seq quot: ( obj1 obj2 -- <=> ) -- )
    over length 2 < [ 2drop ] [ (bubble-sort!) ] if ; inline

: natural-bubble-sort! ( seq -- )
    [ <=> ] bubble-sort! ;

{'fraction_non_alphanumeric': 0.15821917808219177, 'fraction_numerical': 0.022602739726027398, 'mean_word_length': 2.121794871794872, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '909587', 'n_tokens_mistral': 548, 'n_tokens_neox': 517, 'n_words': 155}