-
Notifications
You must be signed in to change notification settings - Fork 211
/
sequences.factor
43 lines (27 loc) · 1.14 KB
/
sequences.factor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
! Copyright (C) 2011 John Benediktsson
! See https://factorcode.org/license.txt for BSD license
USING: accessors assocs hashtables hashtables.wrapped kernel
math parser sequences vocabs.loader ;
IN: hashtables.sequences
<PRIVATE
TUPLE: sequence-wrapper
{ underlying sequence read-only } ;
C: <sequence-wrapper> sequence-wrapper
M: sequence-wrapper equal?
over sequence-wrapper?
[ [ underlying>> ] bi@ sequence= ]
[ 2drop f ] if ; inline
M: sequence-wrapper hashcode*
underlying>> [ sequence-hashcode ] recursive-hashcode ; inline
PRIVATE>
TUPLE: sequence-hashtable < wrapped-hashtable ;
: <sequence-hashtable> ( n -- shashtable )
<hashtable> sequence-hashtable boa ; inline
M: sequence-hashtable wrap-key drop <sequence-wrapper> ;
M: sequence-hashtable clone
underlying>> clone sequence-hashtable boa ; inline
: >sequence-hashtable ( assoc -- shashtable )
[ assoc-size <sequence-hashtable> ] keep assoc-union! ;
M: sequence-hashtable new-assoc drop <sequence-hashtable> ;
SYNTAX: SH{ \ } [ >sequence-hashtable ] parse-literal ;
{ "hashtables.sequences" "prettyprint" } "hashtables.sequences.prettyprint" require-when