<commit_before>! Copyright (C) 2004, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays growable kernel math sequences
sequences.private ;
IN: vectors

TUPLE: vector
{ underlying array }
{ length array-capacity } ;

: <vector> ( n -- vector ) 0 <array> 0 vector boa ; inline

: >vector ( seq -- vector ) V{ } clone-like ;

M: vector like
    drop dup vector? [
        dup array? [ dup length vector boa ] [ >vector ] if
    ] unless ; inline

M: vector new-sequence
    drop [ f <array> ] [ integer>fixnum ] bi vector boa ; inline

M: vector equal?
    over vector? [ sequence= ] [ 2drop f ] if ;

M: array like
    #! If we have an array, we're done.
    #! If we have a vector, and it's at full capacity, we're done.
    #! Otherwise, call resize-array, which is a relatively
    #! fast primitive.
    drop dup array? [
        dup vector? [
            [ length ] [ underlying>> ] bi
            2dup length eq?
            [ nip ] [ resize-array ] if
        ] [ >array ] if
    ] unless ; inline

M: sequence new-resizable drop <vector> ; inline

INSTANCE: vector growable

: 1vector ( x -- vector ) V{ } 1sequence ;

: ?push ( elt seq/f -- seq )
    [ 1 <vector> ] unless* [ push ] keep ;<commit_msg>vectors: small speedup to ``f ?push`` and inline 1vector.<commit_after>! Copyright (C) 2004, 2008 <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays growable kernel math sequences
sequences.private ;
IN: vectors

TUPLE: vector
{ underlying array }
{ length array-capacity } ;

: <vector> ( n -- vector ) 0 <array> 0 vector boa ; inline

: >vector ( seq -- vector ) V{ } clone-like ;

M: vector like
    drop dup vector? [
        dup array? [ dup length vector boa ] [ >vector ] if
    ] unless ; inline

M: vector new-sequence
    drop [ f <array> ] [ integer>fixnum ] bi vector boa ; inline

M: vector equal?
    over vector? [ sequence= ] [ 2drop f ] if ;

M: array like
    #! If we have an array, we're done.
    #! If we have a vector, and it's at full capacity, we're done.
    #! Otherwise, call resize-array, which is a relatively
    #! fast primitive.
    drop dup array? [
        dup vector? [
            [ length ] [ underlying>> ] bi
            2dup length eq?
            [ nip ] [ resize-array ] if
        ] [ >array ] if
    ] unless ; inline

M: sequence new-resizable drop <vector> ; inline

INSTANCE: vector growable

: 1vector ( x -- vector ) 1array 1 vector boa ; inline

: ?push ( elt seq/f -- seq )
    [ [ push ] keep ] [ 1vector ] if* ;
{'fraction_non_alphanumeric': 0.12015655577299413, 'fraction_numerical': 0.012524461839530333, 'mean_word_length': 2.496580027359781, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 26, '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': '3714820', 'n_tokens_mistral': 830, 'n_tokens_neox': 796, 'n_words': 308}