cursors: adding hash-set-cursor.
parent
0a93877d4b
commit
1b085c55b7
|
|
@ -1,7 +1,7 @@
|
||||||
! (c)2010 Joe Groff bsd license
|
! (c)2010 Joe Groff bsd license
|
||||||
USING: accessors arrays assocs combinators.short-circuit fry
|
USING: accessors assocs combinators.short-circuit fry
|
||||||
hashtables kernel locals macros math math.functions math.order
|
generalizations hash-sets hashtables kernel macros math
|
||||||
generalizations sequences ;
|
math.functions math.order sequences sets ;
|
||||||
FROM: sequences.private => nth-unsafe set-nth-unsafe ;
|
FROM: sequences.private => nth-unsafe set-nth-unsafe ;
|
||||||
FROM: hashtables.private => tombstone? ;
|
FROM: hashtables.private => tombstone? ;
|
||||||
IN: cursors
|
IN: cursors
|
||||||
|
|
@ -292,6 +292,54 @@ INSTANCE: sequence-cursor output-cursor
|
||||||
M: sequence-cursor set-cursor-value-unsafe [ n>> ] [ seq>> ] bi set-nth-unsafe ; inline
|
M: sequence-cursor set-cursor-value-unsafe [ n>> ] [ seq>> ] bi set-nth-unsafe ; inline
|
||||||
M: sequence-cursor set-cursor-value [ n>> ] [ seq>> ] bi set-nth ; inline
|
M: sequence-cursor set-cursor-value [ n>> ] [ seq>> ] bi set-nth ; inline
|
||||||
|
|
||||||
|
!
|
||||||
|
! hash-set cursor
|
||||||
|
!
|
||||||
|
|
||||||
|
TUPLE: hash-set-cursor
|
||||||
|
{ hash-set hash-set read-only }
|
||||||
|
{ n fixnum read-only } ;
|
||||||
|
<PRIVATE
|
||||||
|
C: <hash-set-cursor> hash-set-cursor
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
INSTANCE: hash-set-cursor forward-cursor
|
||||||
|
|
||||||
|
M: hash-set-cursor cursor-compatible?
|
||||||
|
{
|
||||||
|
[ [ hash-set-cursor? ] both? ]
|
||||||
|
[ [ hash-set>> ] bi@ eq? ]
|
||||||
|
} 2&& ; inline
|
||||||
|
|
||||||
|
M: hash-set-cursor cursor-valid? ( cursor -- ? )
|
||||||
|
[ n>> ] [ hash-set>> array>> ] bi bounds-check? ; inline
|
||||||
|
|
||||||
|
M: hash-set-cursor cursor= ( cursor cursor -- ? )
|
||||||
|
[ n>> ] bi@ = ; inline
|
||||||
|
M: hash-set-cursor cursor-distance-hint ( cursor cursor -- n )
|
||||||
|
nip hash-set>> cardinality ; inline
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
: (inc-hash-set-cursor) ( array n -- n' )
|
||||||
|
[ 2dup swap { [ length < ] [ nth-unsafe tombstone? ] } 2&& ] [ 1 + ] while nip ; inline
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
M: hash-set-cursor inc-cursor ( cursor -- cursor' )
|
||||||
|
[ hash-set>> dup array>> ] [ n>> 1 + ] bi
|
||||||
|
(inc-hash-set-cursor) <hash-set-cursor> ; inline
|
||||||
|
|
||||||
|
INSTANCE: hash-set-cursor input-cursor
|
||||||
|
|
||||||
|
M: hash-set-cursor cursor-key-value-unsafe
|
||||||
|
[ n>> dup ] [ hash-set>> array>> ] bi nth-unsafe ; inline
|
||||||
|
|
||||||
|
INSTANCE: hash-set container
|
||||||
|
|
||||||
|
M: hash-set begin-cursor
|
||||||
|
dup array>> 0 (inc-hash-set-cursor) <hash-set-cursor> ; inline
|
||||||
|
M: hash-set end-cursor
|
||||||
|
dup array>> length <hash-set-cursor> ; inline
|
||||||
|
|
||||||
!
|
!
|
||||||
! map cursor
|
! map cursor
|
||||||
!
|
!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue