1 ! Copyright (C) 2011 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors assocs combinators hashtables
5 hashtables.wrapped kernel parser sequences vocabs.loader ;
7 IN: hashtables.sequences
9 ERROR: not-a-sequence object ;
11 TUPLE: sequence-wrapper < wrapped-key ;
13 C: <sequence-wrapper> sequence-wrapper
15 M: sequence-wrapper equal?
16 over sequence-wrapper?
17 [ [ underlying>> ] bi@ sequence= ]
18 [ 2drop f ] if ; inline
20 M: sequence-wrapper hashcode*
21 underlying>> [ sequence-hashcode ] recursive-hashcode ; inline
23 TUPLE: sequence-hashtable < wrapped-hashtable ;
25 : <sequence-hashtable> ( n -- shashtable )
26 <hashtable> sequence-hashtable boa ; inline
28 M: sequence-hashtable wrap-key
29 drop dup sequence? [ <sequence-wrapper> ] [ not-a-sequence ] if ;
31 M: sequence-hashtable clone
32 underlying>> clone sequence-hashtable boa ; inline
34 : >sequence-hashtable ( assoc -- shashtable )
35 [ assoc-size <sequence-hashtable> ] keep assoc-union! ;
37 M: sequence-hashtable new-assoc drop <sequence-hashtable> ;
39 SYNTAX: SH{ \ } [ >sequence-hashtable ] parse-literal ;
41 { "hashtables.sequences" "prettyprint" } "hashtables.sequences.prettyprint" require-when