<commit_before>! Copyright (C) 2006 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: checksums kernel math sequences sequences.private ;
IN: checksums.crc32

CONSTANT: crc32-polynomial 0xedb88320

CONSTANT: crc32-table V{ }

256 <iota> [
    8 [
        [ 2/ ] [ even? ] bi [ crc32-polynomial bitxor ] unless
    ] times
] map 0 crc32-table copy

: (crc32) ( crc ch -- crc )
    dupd bitxor
    0xff bitand crc32-table nth-unsafe
    swap -8 shift bitxor ; inline

SINGLETON: crc32

INSTANCE: crc32 checksum

: init-crc32 ( input checksum -- x y input )
    drop [ 0xffffffff dup ] dip ; inline

<PRIVATE
: 4>be ( n -- byte-array ) ! duplicated from io.binary, but in core
    { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ;
PRIVATE>

: finish-crc32 ( x y -- bytes )
    bitxor 4>be ; inline

M: crc32 checksum-bytes
    init-crc32
    [ (crc32) ] each
    finish-crc32 ; inline

M: crc32 checksum-lines
    init-crc32
    [ [ (crc32) ] each CHAR: \n (crc32) ] each
    finish-crc32 ; inline
<commit_msg>checksums.crc32: fix comment.<commit_after>! Copyright (C) 2006 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: checksums kernel math sequences sequences.private ;
IN: checksums.crc32

CONSTANT: crc32-polynomial 0xedb88320

CONSTANT: crc32-table V{ }

256 <iota> [
    8 [
        [ 2/ ] [ even? ] bi [ crc32-polynomial bitxor ] unless
    ] times
] map 0 crc32-table copy

: (crc32) ( crc ch -- crc )
    dupd bitxor
    0xff bitand crc32-table nth-unsafe
    swap -8 shift bitxor ; inline

SINGLETON: crc32

INSTANCE: crc32 checksum

: init-crc32 ( input checksum -- x y input )
    drop [ 0xffffffff dup ] dip ; inline

<PRIVATE
: 4>be ( n -- byte-array ) ! duplicated from endian but in core
    { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ;
PRIVATE>

: finish-crc32 ( x y -- bytes )
    bitxor 4>be ; inline

M: crc32 checksum-bytes
    init-crc32
    [ (crc32) ] each
    finish-crc32 ; inline

M: crc32 checksum-lines
    init-crc32
    [ [ (crc32) ] each CHAR: \n (crc32) ] each
    finish-crc32 ; inline

{'fraction_non_alphanumeric': 0.11564299424184261, 'fraction_numerical': 0.06621880998080615, 'mean_word_length': 2.6968085106382977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '7227881', 'n_tokens_mistral': 899, 'n_tokens_neox': 798, 'n_words': 236}