-! Copyright (C) 2005, 2007 Slava Pestov.
+! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel kernel.private math math.private sequences
-sequences.private ;
+USING: accessors kernel kernel.private math math.private
+sequences sequences.private ;
IN: arrays
M: array clone (clone) ;
-M: array length array-capacity ;
+M: array length length>> ;
M: array nth-unsafe >r >fixnum r> array-nth ;
M: array set-nth-unsafe >r >fixnum r> set-array-nth ;
M: array resize resize-array ;
array? hashtable? vector?
tuple? sbuf? node? tombstone?
- array-capacity array-nth set-array-nth
+ array-nth set-array-nth
wrap probe
{ "imaginary" { "real" "math" } read-only }
} define-builtin
-"array" "arrays" create { } define-builtin
+"array" "arrays" create {
+ { "length" { "array-capacity" "sequences.private" } read-only }
+} define-builtin
"wrapper" "kernel" create {
{ "wrapped" read-only }
{ "sub-primitive" read-only }
} define-builtin
-"byte-array" "byte-arrays" create { } define-builtin
+"byte-array" "byte-arrays" create {
+ { "length" { "array-capacity" "sequences.private" } read-only }
+} define-builtin
"callstack" "kernel" create { } define-builtin
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel kernel.private alien.accessors sequences
+USING: accessors kernel kernel.private alien.accessors sequences
sequences.private math ;
IN: byte-arrays
M: byte-array clone (clone) ;
-M: byte-array length array-capacity ;
+M: byte-array length length>> ;
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
: >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
#! 4 slot == superclasses>>
rot dup tuple? [
layout-of 4 slot
- 2dup array-capacity fixnum<
+ 2dup 1 slot fixnum<
[ array-nth eq? ] [ 3drop f ] if
] [ 3drop f ] if ; inline
<PRIVATE
: wrap ( i array -- n )
- array-capacity 1 fixnum-fast fixnum-bitand ; inline
+ length>> 1 fixnum-fast fixnum-bitand ; inline
: hash@ ( key array -- i )
>r hashcode >fixnum dup fixnum+fast r> wrap ; inline
] if ; inline
: key@ ( key hash -- array n ? )
- array>> dup array-capacity 0 eq?
+ array>> dup length>> 0 eq?
[ no-key ] [ 2dup hash@ (key@) ] if ; inline
: <hash-array> ( n -- array )
: hash-large? ( hash -- ? )
[ count>> 3 fixnum*fast 1 fixnum+fast ]
- [ array>> array-capacity ] bi fixnum> ; inline
+ [ array>> length>> ] bi fixnum> ; inline
: hash-stale? ( hash -- ? )
[ deleted>> 10 fixnum*fast ] [ count>> ] bi fixnum> ; inline
<PRIVATE
-: array-capacity ( array -- n )
- 1 slot { array-capacity } declare ; inline
-
: array-nth ( n array -- elt )
swap 2 fixnum+fast slot ; inline