1 ! Copyright (C) 2010 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: hashtables kernel assocs accessors math arrays sequences ;
6 TUPLE: pair value key hash ;
8 : <pair> ( value key -- assoc )
11 : if-hash ( pair true-quot false-quot -- )
12 [ dup hash>> ] 2dip ?if-old ; inline
15 [ assoc-size 1 + ] [ drop 1 ] if-hash ; inline
17 : if-key ( key pair true-quot false-quot -- )
18 [ [ 2dup key>> eq? ] dip [ nip ] prepose ] dip if ; inline
22 [ at* ] [ 2drop f f ] if-hash
28 [ [ associate ] dip swap >>hash drop ] if-hash
31 ERROR: cannot-delete-key pair ;
34 [ cannot-delete-key ] [
35 [ delete-at ] [ 2drop ] if-hash
39 [ hash>> >alist ] [ [ key>> ] [ value>> ] bi 2array ] bi suffix ; inline