]> gitweb.factorcode.org Git - factor.git/blob - core/byte-arrays/byte-arrays.factor
50ea4b32ba3cf9f106c45eb5b88adbaa7fe3b2c1
[factor.git] / core / byte-arrays / byte-arrays.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel kernel.private alien.accessors sequences
4 sequences.private math ;
5 IN: byte-arrays
6
7 M: byte-array clone (clone) ;
8 M: byte-array length length>> ;
9 M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
10 M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
11 : >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
12 M: byte-array like drop dup byte-array? [ >byte-array ] unless ;
13 M: byte-array new-sequence drop <byte-array> ;
14
15 M: byte-array equal?
16     over byte-array? [ sequence= ] [ 2drop f ] if ;
17
18 M: byte-array resize
19     resize-byte-array ;
20
21 INSTANCE: byte-array sequence
22
23 : 1byte-array ( x -- byte-array ) 1 <byte-array> [ set-first ] keep ; inline
24
25 : 2byte-array ( x y -- byte-array ) B{ } 2sequence ; inline
26
27 : 3byte-array ( x y z -- byte-array ) B{ } 3sequence ; inline
28
29 : 4byte-array ( w x y z -- byte-array ) B{ } 4sequence ; inline