1 ! Copyright (C) 2008 Slava Pestov.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: arrays kernel kernel.private math sequences
\r
4 sequences.private growable bit-arrays prettyprint.custom
\r
9 { underlying bit-array initial: ?{ } }
\r
10 { length array-capacity } ;
\r
12 : <bit-vector> ( n -- bit-vector )
\r
13 <bit-array> 0 bit-vector boa ; inline
\r
15 : >bit-vector ( seq -- bit-vector )
\r
16 T{ bit-vector f ?{ } 0 } clone-like ;
\r
19 drop dup bit-vector? [
\r
21 [ dup length bit-vector boa ] [ >bit-vector ] if
\r
24 M: bit-vector new-sequence
\r
25 drop [ <bit-array> ] [ >fixnum ] bi bit-vector boa ;
\r
27 M: bit-vector equal?
\r
28 over bit-vector? [ sequence= ] [ 2drop f ] if ;
\r
30 M: bit-array new-resizable drop <bit-vector> ;
\r
32 INSTANCE: bit-vector growable
\r
34 : ?V{ \ } [ >bit-vector ] parse-literal ; parsing
\r
36 M: bit-vector >pprint-sequence ;
\r
37 M: bit-vector pprint-delims drop \ ?V{ \ } ;
\r
38 M: bit-vector pprint* pprint-object ;
\r