Make array length foldable
parent
2025e6733d
commit
d0ae6bdb8f
|
@ -1,11 +1,11 @@
|
|||
! 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 ;
|
||||
|
|
|
@ -37,7 +37,7 @@ nl
|
|||
array? hashtable? vector?
|
||||
tuple? sbuf? node? tombstone?
|
||||
|
||||
array-capacity array-nth set-array-nth
|
||||
array-nth set-array-nth
|
||||
|
||||
wrap probe
|
||||
|
||||
|
|
|
@ -225,7 +225,9 @@ bi
|
|||
{ "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 }
|
||||
|
@ -261,7 +263,9 @@ bi
|
|||
{ "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
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
! 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
|
||||
|
|
|
@ -91,7 +91,7 @@ ERROR: bad-superclass class ;
|
|||
#! 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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ TUPLE: hashtable
|
|||
<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
|
||||
|
@ -30,7 +30,7 @@ TUPLE: hashtable
|
|||
] 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 )
|
||||
|
@ -71,7 +71,7 @@ TUPLE: hashtable
|
|||
|
||||
: 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
|
||||
|
|
|
@ -60,9 +60,6 @@ INSTANCE: immutable-sequence sequence
|
|||
|
||||
<PRIVATE
|
||||
|
||||
: array-capacity ( array -- n )
|
||||
1 slot { array-capacity } declare ; inline
|
||||
|
||||
: array-nth ( n array -- elt )
|
||||
swap 2 fixnum+fast slot ; inline
|
||||
|
||||
|
|
Loading…
Reference in New Issue