File: hash-table0.thb

package info (click to toggle)
theme-d 7.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,036 kB
  • sloc: lisp: 9,625; sh: 5,321; makefile: 715; ansic: 477
file content (241 lines) | stat: -rw-r--r-- 7,318 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
;; -*-theme-d-*-

;; Copyright (C) 2015, 2021, 2024  Tommi Höynälänmaa

(define-body (standard-library hash-table0)

  (import (standard-library list-utilities))
  
  (add-method make-raw-hash-table
    (prim-proc make-hash-table () <raw-hash-table> pure))

  (add-method make-raw-hash-table-with-size
    (prim-proc make-hash-table-with-size (<integer>) <raw-hash-table> pure))

  (define-param-method make-hash-table (%key %value)
		     (((proc-hash (:hash-proc %key))
		       (proc-assoc (:assoc-proc %key %value)))
		      (:hash-table %key %value)
		      pure)
    (create (:hash-table %key %value)
	  (make-raw-hash-table) proc-hash proc-assoc))

  (define-param-method make-hash-table-with-size (%key %value)
		     (((proc-hash (:hash-proc %key))
		       (proc-assoc (:assoc-proc %key %value))
		       (i-size <integer>))
		      (:hash-table %key %value)
		      pure)
    (create (:hash-table %key %value)
	  (make-raw-hash-table-with-size i-size)
	  proc-hash proc-assoc))

  (define-param-method make-object-hash-table (%value)
		       (((dummy (:maybe %value)))
			(:object-hash-table %value) pure)
    (make-hash-table
     (static-cast (:hash-proc <object>) object-hash)
     (cast (:assoc-proc <object> %value)
	   (generic-proc-dispatch assoc-objects1
				  (<object> (:alist <object> %value))))))

  (define-param-method make-object-hash-table-with-size (%value)
		       (((dummy (:maybe %value)) (i-size <integer>))
			(:object-hash-table %value) pure)
    (make-hash-table-with-size
     (static-cast (:hash-proc <object>) object-hash)
     (cast (:assoc-proc <object> %value)
	   (generic-proc-dispatch assoc-objects1
				  (<object> (:alist <object> %value))))
     i-size))

  (define-param-method make-string-hash-table (%value)
		       (((dummy (:maybe %value)))
			(:string-hash-table %value) pure)
    (make-hash-table
     (static-cast (:hash-proc <string>) string-hash)
     (cast (:assoc-proc <string> %value)
	   (generic-proc-dispatch assoc-contents1
				  (<string> (:alist <string> %value))))))

  (define-param-method make-string-hash-table-with-size (%value)
		       (((dummy (:maybe %value)) (i-size <integer>))
			(:string-hash-table %value) pure)
    (make-hash-table-with-size
     (static-cast (:hash-proc <string>) string-hash)
     (cast (:assoc-proc <string> %value)
	   (generic-proc-dispatch assoc-contents1
				  (<string> (:alist <string> %value))))
     i-size))

  (define-param-method make-symbol-hash-table (%value)
		       (((dummy (:maybe %value)))
			(:symbol-hash-table %value) pure)
    (make-hash-table
     (static-cast (:hash-proc <symbol>) hashq)
     (cast (:assoc-proc <symbol> %value)
	   (generic-proc-dispatch assoc-values1
				  (<symbol> (:alist <symbol> %value))))))

  (define-param-method make-symbol-hash-table-with-size (%value)
		       (((dummy (:maybe %value)) (i-size <integer>))
			(:symbol-hash-table %value) pure)
    (make-hash-table-with-size
     (static-cast (:hash-proc <symbol>) hashq)
     (cast (:assoc-proc <symbol> %value)
	   (generic-proc-dispatch assoc-values1
				  (<symbol> (:alist <symbol> %value))))
     i-size))

  (add-method hashx-ref
    (param-prim-proc
     theme-hashx-ref
     (%key %value %default)
     ((:hash-proc %key) (:assoc-proc %key %value) <raw-hash-table>
      %key %default)
     (:union %value %default)
     pure))

  (add-method hashx-exists?
    (unchecked-param-prim-proc
     theme-hashx-exists?
     (%key %value)
     ((:hash-proc %key) (:assoc-proc %key %value) <raw-hash-table>
      %key)
     <boolean>
     pure))

  (add-method hashx-set!
    (param-prim-proc theme-hashx-set!
		     (%key %value)
		     ((:hash-proc %key) (:assoc-proc %key %value)
		      <raw-hash-table>
		      %key %value)
		     <none> nonpure))

  (add-method hashx-remove!
    (param-prim-proc theme-hashx-remove!
		     (%key %value)
		     ((:hash-proc %key) (:assoc-proc %key %value)
		      <raw-hash-table>
		      %key)
		     <none> nonpure))

  (define-param-method hash-ref (%key %value %default)
		     (((ht (:hash-table %key %value)) (o-key %key)
		       (o-default %default))
		      (:union %value %default) pure)
    (hashx-ref
     (field-ref ht 'proc-hash)
     (field-ref ht 'proc-assoc)
     (field-ref ht 'rawht)
     o-key
     o-default))

  (define-param-method hash-exists? (%key %value)
		     (((ht (:hash-table %key %value)) (o-key %key))
		      <boolean> pure)
    (hashx-exists?
     (field-ref ht 'proc-hash)
     (field-ref ht 'proc-assoc)
     (field-ref ht 'rawht)
     o-key))

  (define-param-method hash-set! (%key %value)
		     (((ht (:hash-table %key %value))
		       (o-key %key)
		       (o-value %value))
		      <none> nonpure)
    (hashx-set!
     (field-ref ht 'proc-hash)
     (field-ref ht 'proc-assoc)
     (field-ref ht 'rawht)
     o-key
     o-value))

  (define-param-method hash-remove! (%key %value)
		     (((ht (:hash-table %key %value)) (o-key %key))
		      <none> nonpure)
    (hashx-remove!
     (field-ref ht 'proc-hash)
     (field-ref ht 'proc-assoc)
     (field-ref ht 'rawht)
     o-key))

  (define _hash-count-elements
    (prim-proc hash-count-elements (<raw-hash-table>) <integer> pure))

  (define _hash-clear!
    (unchecked-prim-proc hash-clear! (<raw-hash-table>) <none> nonpure))
  
  (define-param-method hash-count-elements (%key %value)
		     (((ht (:hash-table %key %value)))
		      <integer> pure)
    (_hash-count-elements (field-ref ht 'rawht)))

  (add-method hashq
    (unchecked-prim-proc hashq (<object> <integer>) <integer> pure))
    
  (add-method hashv
    (unchecked-prim-proc hashv (<object> <integer>) <integer> pure))

  (add-method hash-contents
    (unchecked-prim-proc hash (<object> <integer>) <integer> pure))

  (add-method object-hash
    (unchecked-prim-proc hashv (<object> <integer>) <integer> pure))

  (add-method string-hash
    (unchecked-prim-proc string-hash (<string> <integer>) <integer> pure))

  (define-param-method assoc1
      (%type1 %type2)
      (((key %type1)
	(lst (:alist %type1 %type2)))
       (:union (:pair %type1 %type2) <boolean>)
       pure)
    (assoc key lst #f))

  (define-param-method assoc-values1
      (%type1 %type2)
      (((key %type1)
	(lst (:alist %type1 %type2)))
       (:union (:pair %type1 %type2) <boolean>)
       pure)
    (assoc-values key lst #f))
  
  (define-param-method assoc-objects1
      (%type1 %type2)
      (((key %type1)
	(lst (:alist %type1 %type2)))
       (:union (:pair %type1 %type2) <boolean>)
       pure)
    (assoc-objects key lst #f))

  (define-param-method assoc-contents1
      (%type1 %type2)
      (((key %type1)
	(lst (:alist %type1 %type2)))
       (:union (:pair %type1 %type2) <boolean>)
       pure)
    (assoc-contents key lst #f))

  (add-method hash-for-each-x
    (param-prim-proc
     theme-hash-for-each
     (%key %value)
     ((:procedure (%key %value) <none> nonpure)
      <raw-hash-table>)
     <none>
     nonpure))

  (define-param-method hash-for-each (%key %value)
		     (((pc (:procedure (%key %value) <none> nonpure))
		       (ht (:hash-table %key %value)))
		      <none>
		      nonpure)
    (hash-for-each-x pc (field-ref ht 'rawht)))

  (define-param-method hash-clear! (%key %value)
		     (((ht (:hash-table %key %value))) <none> nonpure)
    (_hash-clear! (field-ref ht 'rawht))))