2009-07-07 15:34:08 -04:00
|
|
|
! Copyright (C) 2009 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-11-29 23:10:37 -05:00
|
|
|
USING: classes functors growable kernel math sequences
|
|
|
|
sequences.private ;
|
2009-07-07 15:34:08 -04:00
|
|
|
IN: vectors.functor
|
|
|
|
|
|
|
|
FUNCTOR: define-vector ( V A <A> -- )
|
|
|
|
|
|
|
|
<V> DEFINES <${V}>
|
|
|
|
>V DEFINES >${V}
|
|
|
|
|
|
|
|
WHERE
|
|
|
|
|
|
|
|
TUPLE: V { underlying A } { length array-capacity } ;
|
|
|
|
|
|
|
|
: <V> ( capacity -- vector ) <A> 0 V boa ; inline
|
|
|
|
|
|
|
|
M: V like
|
|
|
|
drop dup V instance? [
|
|
|
|
dup A instance? [ dup length V boa ] [ >V ] if
|
2009-08-17 23:32:21 -04:00
|
|
|
] unless ; inline
|
2009-07-07 15:34:08 -04:00
|
|
|
|
2009-08-17 23:32:21 -04:00
|
|
|
M: V new-sequence drop [ <A> ] [ >fixnum ] bi V boa ; inline
|
2009-07-07 15:34:08 -04:00
|
|
|
|
2009-08-17 23:32:21 -04:00
|
|
|
M: A new-resizable drop <V> ; inline
|
2009-07-07 15:34:08 -04:00
|
|
|
|
2009-10-22 19:55:00 -04:00
|
|
|
M: V new-resizable drop <V> ; inline
|
|
|
|
|
2009-07-07 15:34:08 -04:00
|
|
|
M: V equal? over V instance? [ sequence= ] [ 2drop f ] if ;
|
|
|
|
|
|
|
|
: >V ( seq -- vector ) V new clone-like ; inline
|
|
|
|
|
|
|
|
INSTANCE: V growable
|
|
|
|
|
|
|
|
;FUNCTOR
|