f35805c2c5/library/data/aa.retro

e42c7ed4519520155d7f614052f669b4479ad9d0f35805c2c56c0dc7b89bf5c8b341f450093fa7c9
4
( Copyright [c] 2010, Marc Simpson                             )
4
( Copyright [c] 2010, Marc Simpson                             )
5
( License: ISC                                                 )
5
( License: ISC                                                 )
6
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
6
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
7
( NOTE:                                                        )
8
( -----                                                        )
9
(                                                              )
10
( Since altering 'hash-prime' would affect previously written  )
11
( tables, we shall introduce the following condition: you may  )
12
( modify 'hash-prime' before creating hash-tables, but once    )
13
( this has been done, do NOT change its value afterward.       )
14
(                                                              )
15
( Of course, we could make 'hash' more flexible and have it    )
16
( read a prime value [or define a second word that respects a  )
17
( stack value for modding].  For now, let's just regard our    )
18
( stipulation as well justified; either tweak the provided     )
19
( hashing routines _before_ use, or leave them be.             )
20
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
7
21
8
include library/data/ll.retro
22
include library/data/ll.retro
9
include library/data/hash.retro
23
include library/data/hash.retro
24
include library/data/arrays.retro
10
25
11
' hashing open
26
' hashing open
12
27
...
...
47
  : @"   (  t"- ) compiler @ if
62
  : @"   (  t"- ) compiler @ if
48
                  ahead " keepString here rot ! literal, else "
63
                  ahead " keepString here rot ! literal, else "
49
                  then ` swap ` get-entry ; immediate
64
                  then ` swap ` get-entry ; immediate
65
66
  : 'type'   ( $- ) char: ' emit type char: ' emit space ;
67
68
  {{
69
    : bkt-keys ( l- ) repeat 0; dup 1+ @ @ , @ again drop ;
70
    : (keys)   ( t- ) hash-prime @ for @+ bkt-keys next drop ;
71
    ---reveal---
72
    : keys  ( t-a )
73
      here 0 , swap  (keys)  here over - 1- over ! ;
74
  }}
75
76
  : keys{ ( R: t- ) ` keys  ` dup ` push `  foreach{ ; compile-only
77
  : }keys ( R:  - ) ` }loop ` pop ` here ` - ` allot ; compile-only
78
79
  : .keys ( t-  )
80
    char: { emit space  keys{ 'type' }keys  char: } emit ;
81
82
  ( xyz -> xyzx: like 'rot', but _copies_ rotated item )
83
  : rover ` push ` over ` pop ` swap ; compile-only
84
85
  : .table ( t- )
86
    dup
87
    keys{ dup cr 'type' ." => " rover get-entry drop . }keys
88
    drop ;
50
))
89
))
51
90
52
' hashing shut
91
' hashing shut