<commit_before>! Copyright (C) 2003, 2007 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences ;
IN: io.binary

: le> ( seq -- x ) dup length iota 0 [ 8 * shift + ] 2reduce ;
: be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ;

: mask-byte ( x -- y ) 0xff bitand ; inline

: nth-byte ( x n -- b ) -8 * shift mask-byte ; inline

: >le ( x n -- byte-array ) iota [ nth-byte ] with B{ } map-as ;
: >be ( x n -- byte-array ) >le reverse! ;

: d>w/w ( d -- w1 w2 )
    [ 0xffffffff bitand ]
    [ -32 shift 0xffffffff bitand ] bi ;

: w>h/h ( w -- h1 h2 )
    [ 0xffff bitand ]
    [ -16 shift 0xffff bitand ] bi ;

: h>b/b ( h -- b1 b2 )
    [ mask-byte ]
    [ -8 shift mask-byte ] bi ;

: signed-le> ( bytes -- x )
    [ le> ] [ length 8 * 1 - 2^ 1 - ] bi
    2dup > [ bitnot bitor ] [ drop ] if ;

: signed-be> ( bytes -- x )
    <reversed> signed-le> ;<commit_msg>io.binary: faster >be.<commit_after>! Copyright (C) 2003, 2007 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences ;
IN: io.binary

: le> ( seq -- x ) dup length iota 0 [ 8 * shift + ] 2reduce ;

: be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ;

: mask-byte ( x -- y ) 0xff bitand ; inline

: nth-byte ( x n -- b ) -8 * shift mask-byte ; inline

<PRIVATE

: map-bytes ( x seq -- byte-array )
    [ nth-byte ] with B{ } map-as ; inline

PRIVATE>

: >le ( x n -- byte-array ) iota map-bytes ;

: >be ( x n -- byte-array ) iota <reversed> map-bytes ;

: d>w/w ( d -- w1 w2 )
    [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ;

: w>h/h ( w -- h1 h2 )
    [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ;

: h>b/b ( h -- b1 b2 )
    [ mask-byte ] [ -8 shift mask-byte ] bi ;

: signed-le> ( bytes -- x )
    [ le> ] [ length 8 * 1 - 2^ 1 - ] bi
    2dup > [ bitnot bitor ] [ drop ] if ;

: signed-be> ( bytes -- x )
    <reversed> signed-le> ;
{'fraction_non_alphanumeric': 0.17770767613038907, 'fraction_numerical': 0.03680336487907466, 'mean_word_length': 2.0206349206349206, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '4484225', 'n_tokens_mistral': 812, 'n_tokens_neox': 752, 'n_words': 241}