11prolog ' ./gdic.ijs'
2- NB. addon/dictionary
2+ NB. addon/dict
33
4- load ' dictionary '
4+ load ' dict '
55
6- d =: (' hash' , & < ' valueshape' ; 0 ) conew ' jdictionary '
6+ d =: (' hash' , & < ' valueshape' ; 0 ) conew ' jdict '
77' ' put__d i. 1000
88techo ' hash ' ,": 100 (6 !: 2 ) ' has__d f."0 k' [ k =. 10 # i. 1000
99destroy__d ' '
1010
11- d =: (' tree' , & < ' valueshape' ; 0 ) conew ' jdictionary '
11+ d =: (' tree' , & < ' valueshape' ; 0 ) conew ' jdict '
1212' ' put__d i. 1000
1313techo ' tree ' ,": 100 (6 !: 2 ) ' has__d f."0 k' [ k =. 10 # i. 1000
1414destroy__d ' '
@@ -28,16 +28,16 @@ u :: (<:@(13!:11)@'' >@{ 9!:8@'')
2828}}
2929
3030{{
31- assert. ' length error' -: ' jdictionary ' conew~ GetError y , < ' keyshape' ; 2 0 2
32- assert. ' length error' -: ' jdictionary ' conew~ GetError y , < ' keyshape' ; 0
33- assert. ' length error' -: ' jdictionary ' conew~ GetError y , < ' valueshape' ; 7 0
34- assert. ' length error' -: ' jdictionary ' conew~ GetError y , < ' valueshape' ; 0 0
31+ assert. ' length error' -: ' jdict ' conew~ GetError y , < ' keyshape' ; 2 0 2
32+ assert. ' length error' -: ' jdict ' conew~ GetError y , < ' keyshape' ; 0
33+ assert. ' length error' -: ' jdict ' conew~ GetError y , < ' valueshape' ; 7 0
34+ assert. ' length error' -: ' jdict ' conew~ GetError y , < ' valueshape' ; 0 0
3535coreset ' '
36- jdict =. ' jdictionary ' conew~ ' hash' , & < ' keyhash' , & < _1 " 0 ` ' '
36+ jdict =. ' jdict ' conew~ ' hash' , & < ' keyhash' , & < _1 " 0 ` ' '
3737' domain error' -: put__jdict GetError~ 7
3838destroy__jdict ' '
3939params =. y , < ' valueshape' ; 5
40- jdict =. params conew ' jdictionary '
40+ jdict =. params conew ' jdict '
4141assert. ' domain error' -: (i. 5 ) put__jdict GetError 2.3 3.4
4242assert. ' domain error' -: (2 5 $ ' abcde' ) put__jdict GetError 0 1
4343assert. ' domain error' -: (3 5 $ 3.14 ) put__jdict GetError 2 3 4
@@ -53,8 +53,8 @@ NB. BASIC.
5353
5454test_basic1 =: {{
5555' index_type keyhash keycompare' =. < " 0 y
56- params =. index_type , < (' keyhash' , & < keyhash) , (' keycompare' , & < keycompare) , (' initcapacity' ; 4 ) , (' keytype ' ; ' integer' ) , (' valueshape ' ; 3 ) , (' keyshape ' ; 2 ) ,: (' valuetype ' ; 4 )
57- mydict =. params conew ' jdictionary '
56+ params =. index_type , < (' keyhash' , & < keyhash) , (' keycompare' , & < keycompare) , (' initcapacity' ; 4 ) , (' kt ' ; ' integer' ) , (' vs ' ; 3 ) , (' ks ' ; 2 ) ,: (' vt ' ; 4 )
57+ mydict =. params conew ' jdict '
5858assert. 0 -: count__mydict ' '
59591 2 3 put__mydict 2 3
6060assert. 1 2 3 -: get__mydict 2 3
@@ -108,7 +108,7 @@ EMPTY
108108test_basic2 =: {{
109109' index_type keyhash keycompare' =. < " 0 y
110110params =. index_type , < (' keyhash' , & < keyhash) , (' keycompare' , & < keycompare) , (' initcapacity' ; 4 ) , (' keytype' ; ' boxed' ) , (' valueshape' ; 3 ) , (' keyshape' ; 2 ) ,: (' valuetype' ; 4 )
111- mydict =. params conew ' jdictionary '
111+ mydict =. params conew ' jdict '
1121121 2 3 put__mydict < " (0 ) 2 3
113113assert. 1 2 3 -: get__mydict < " (0 ) 2 3
1141144 5 6 put__mydict < " (0 ) 1 3
@@ -145,11 +145,11 @@ test_basic2 COMBINATIONS
145145NB. INTERNAL RANK.
146146
147147{{
148- d =. y conew ' jdictionary '
148+ d =. y conew ' jdict '
1491497 put__d i. 3
150150assert. 7 7 7 -: get__d i. 3
151151destroy__d ' '
152- d =. ' jdictionary ' conew~ y , & < (' keyshape' ; 2 ) ,: ' valueshape' ; 3 3
152+ d =. ' jdict ' conew~ y , & < (' keyshape' ; 2 ) ,: ' valueshape' ; 3 3
153153(i. 3 3 ) put__d i. 3 2
154154assert. (2 3 3 $ i. 9 ) -: get__d i. 2 2
155155destroy__d ' '
@@ -158,7 +158,7 @@ destroy__d ''
158158NB. DESTROY.
159159
160160{{
161- jdict =. y conew ' jdictionary '
161+ jdict =. y conew ' jdict '
162162put__jdict~ i. 7
163163assert. ' rank error' -: destroy__jdict GetError 0
164164assert. ' untimely request' -: get__jdict GetError 0
@@ -174,7 +174,7 @@ NB. CUSTOM KEYHASH & KEYCOMPARE
174174
175175{{
176176params =. y , < (' keycompare' , & < 13 !: 8 @ 16 ` ' ' ) ,: (' keyhash' , & < 13 !: 8 @ 16 ` ' ' ) NB. Return spelling error.
177- jdict =. params conew ' jdictionary '
177+ jdict =. params conew ' jdict '
17817842 put__jdict GetError 7 NB. No comparison for empty tree dictionary.
179179assert. ' spelling error' -: 43 put__jdict GetError 8
180180assert. ' spelling error' -: get__jdict GetError 7
@@ -186,7 +186,7 @@ EMPTY
186186
187187{{
188188params =. y , < (' keycompare' , & < 0: ` ' ' ) ,: (' keyhash' , & < 0 " 0 ` ' ' )
189- mydict =. params conew ' jdictionary '
189+ mydict =. params conew ' jdict '
190190put__mydict~ i. 5 [ put__mydict~ 2 3 [ put__mydict~ 1
191191assert. 1 -: count__mydict ' '
192192destroy__mydict ' '
@@ -198,7 +198,7 @@ NB. EMPTY.
198198{{
199199' index_type keyshape valshape' =. y
200200params =. index_type , & < (' keyshape' ; keyshape) ,: (' valueshape' ; valshape)
201- mydict =. params conew ' jdictionary '
201+ mydict =. params conew ' jdict '
202202frames =. 0 0 ; 0 2 ; 2 0 3 4 ; , 0
203203' keys vals' =. < " 1 frames (0 $ ~ , )&. > " _ 0 keyshape ; valshape
204204assert. frames (-: $ @: has__mydict)& > keys
@@ -216,8 +216,8 @@ NB. SPARSE ARRAYS.
216216
217217{{
218218' index_type sparsetype' =. y
219- assert. ' domain error' -: ' jdictionary ' conew~ GetError index_type , & < ' keytype' ; sparsetype
220- assert. ' domain error' -: ' jdictionary ' conew~ GetError index_type , & < ' valuetype' ; sparsetype
219+ assert. ' domain error' -: ' jdict ' conew~ GetError index_type , & < ' keytype' ; sparsetype
220+ assert. ' domain error' -: ' jdict ' conew~ GetError index_type , & < ' valuetype' ; sparsetype
221221EMPTY
222222}}" 1 INDEX_TYPES (, < )" 0 " _ 0 ] 2 ^ 10 + i. 6
223223
@@ -325,50 +325,50 @@ n_iter =. QKTEST{10 1
325325
326326keyshape =. 3 2
327327valueshape =. 0: ^: x 5 8
328- params =. y , < (' keytype ' ; ' boolean' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
329- jdict =. params conew ' jdictionary '
328+ params =. y , < (' kt ' ; ' boolean' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
329+ jdict =. params conew ' jdict '
330330jdict test_type rand_boolean` ' ' ; rand_integer` ' ' ; keyshape ; valueshape ; 5 25 ; n_iter
331331
332332keyshape =. 2 3
333333valueshape =. 0: ^: x 4 5 4
334- params =. y , < (' valuetype ' ; ' floating' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
335- jdict =. params conew ' jdictionary '
334+ params =. y , < (' vt ' ; ' floating' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
335+ jdict =. params conew ' jdict '
336336jdict test_type rand_integer` ' ' ; rand_floating` ' ' ; keyshape ; valueshape ; 100 ; n_iter
337337
338338keyshape =. 7 1
339339valueshape =. 0: ^: x 1 7
340- params =. y , < (' keytype ' ; ' floating' ) , (' valuetype ' ; ' complex' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
341- jdict =. params conew ' jdictionary '
340+ params =. y , < (' kt ' ; ' floating' ) , (' vt ' ; ' complex' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
341+ jdict =. params conew ' jdict '
342342jdict test_type rand_floating` ' ' ; rand_complex` ' ' ; keyshape ; valueshape ; 10 10 ; n_iter
343343
344344keyshape =. 3 3
345345valueshape =. 0: ^: x 2 2 2
346- params =. y , < (' keytype ' ; ' complex' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
347- jdict =. params conew ' jdictionary '
346+ params =. y , < (' kt ' ; ' complex' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
347+ jdict =. params conew ' jdict '
348348jdict test_type rand_complex` ' ' ; rand_integer` ' ' ; keyshape ; valueshape ; 2 3 4 5 ; n_iter
349349
350350keyshape =. 9
351351valueshape =. 0: ^: x 10
352- params =. y , < (' keytype ' ; ' extended' ) , (' valuetype ' ; ' rational' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
353- jdict =. params conew ' jdictionary '
352+ params =. y , < (' kt ' ; ' extended' ) , (' vt ' ; ' rational' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
353+ jdict =. params conew ' jdict '
354354jdict test_type rand_extended` ' ' ; rand_rational` ' ' ; keyshape ; valueshape ; 7 7 ; n_iter
355355
356356keyshape =. 5
357357valueshape =. 0: ^: x 6
358- params =. y , < (' keytype ' ; ' rational' ) , (' valuetype ' ; ' literal' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
359- jdict =. params conew ' jdictionary '
358+ params =. y , < (' kt ' ; ' rational' ) , (' vt ' ; ' literal' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
359+ jdict =. params conew ' jdict '
360360jdict test_type rand_rational` ' ' ; rand_byte` ' ' ; keyshape ; valueshape ; 3 2 ; n_iter
361361
362362keyshape =. 8
363363valueshape =. 0: ^: x 5 5
364- params =. y , < (' keytype ' ; ' literal' ) , (' valuetype ' ; ' extended' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
365- jdict =. params conew ' jdictionary '
364+ params =. y , < (' kt ' ; ' literal' ) , (' vt ' ; ' extended' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
365+ jdict =. params conew ' jdict '
366366jdict test_type rand_byte` ' ' ; rand_extended` ' ' ; keyshape ; valueshape ; 100 ; n_iter
367367
368368keyshape =. 2 2
369369valueshape =. 0: ^: x 2 4
370- params =. y , < (' keytype ' ; ' boxed' ) , (' valuetype ' ; ' boxed' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
371- jdict =. params conew ' jdictionary '
370+ params =. y , < (' kt ' ; ' boxed' ) , (' vt ' ; ' boxed' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
371+ jdict =. params conew ' jdict '
372372jdict test_type rand_boxed` ' ' ; rand_boxed` ' ' ; keyshape ; valueshape ; 25 2 ; n_iter
373373}}" 0 " _ 0 INDEX_TYPES
374374
@@ -377,50 +377,50 @@ n_iter =. QKTEST{300 1
377377
378378keyshape =. 3 2
379379valueshape =. 0: ^: x 5 8
380- params =. y , < (' keytype ' ; ' boolean' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
381- jdict =. params conew ' jdictionary '
380+ params =. y , < (' kt ' ; ' boolean' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
381+ jdict =. params conew ' jdict '
382382jdict test_type rand_boolean` ' ' ; rand_integer` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
383383
384384keyshape =. 2 3
385385valueshape =. 0: ^: x 4 5 4
386- params =. y , < (' valuetype ' ; ' floating' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
387- jdict =. params conew ' jdictionary '
386+ params =. y , < (' vt ' ; ' floating' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
387+ jdict =. params conew ' jdict '
388388jdict test_type rand_integer` ' ' ; rand_floating` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
389389
390390keyshape =. 7 1
391391valueshape =. 0: ^: x 1 7
392- params =. y , < (' keytype ' ; ' floating' ) , (' valuetype ' ; ' complex' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
393- jdict =. params conew ' jdictionary '
392+ params =. y , < (' kt ' ; ' floating' ) , (' vt ' ; ' complex' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
393+ jdict =. params conew ' jdict '
394394jdict test_type rand_floating` ' ' ; rand_complex` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
395395
396396keyshape =. 3 3
397397valueshape =. 0: ^: x 2 2 2
398- params =. y , < (' keytype ' ; ' complex' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
399- jdict =. params conew ' jdictionary '
398+ params =. y , < (' kt ' ; ' complex' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
399+ jdict =. params conew ' jdict '
400400jdict test_type rand_complex` ' ' ; rand_integer` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
401401
402402keyshape =. 9
403403valueshape =. 0: ^: x 10
404- params =. y , < (' keytype ' ; ' extended' ) , (' valuetype ' ; ' rational' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
405- jdict =. params conew ' jdictionary '
404+ params =. y , < (' kt ' ; ' extended' ) , (' vt ' ; ' rational' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
405+ jdict =. params conew ' jdict '
406406jdict test_type rand_extended` ' ' ; rand_rational` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
407407
408408keyshape =. 5
409409valueshape =. 0: ^: x 6
410- params =. y , < (' keytype ' ; ' rational' ) , (' valuetype ' ; ' literal' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
411- jdict =. params conew ' jdictionary '
410+ params =. y , < (' kt ' ; ' rational' ) , (' vt ' ; ' literal' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
411+ jdict =. params conew ' jdict '
412412jdict test_type rand_rational` ' ' ; rand_byte` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
413413
414414keyshape =. 8
415415valueshape =. 0: ^: x 5 5
416- params =. y , < (' keytype ' ; ' literal' ) , (' valuetype ' ; ' extended' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
417- jdict =. params conew ' jdictionary '
416+ params =. y , < (' kt ' ; ' literal' ) , (' vt ' ; ' extended' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
417+ jdict =. params conew ' jdict '
418418jdict test_type rand_byte` ' ' ; rand_extended` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
419419
420420keyshape =. 2 2
421421valueshape =. 0: ^: x 2 4
422- params =. y , < (' keytype ' ; ' boxed' ) , (' valuetype ' ; ' boxed' ) , (' keyshape ' ; keyshape) ,: (' valueshape ' ; valueshape)
423- jdict =. params conew ' jdictionary '
422+ params =. y , < (' kt ' ; ' boxed' ) , (' vt ' ; ' boxed' ) , (' ks ' ; keyshape) ,: (' vs ' ; valueshape)
423+ jdict =. params conew ' jdict '
424424jdict test_type rand_boxed` ' ' ; rand_boxed` ' ' ; keyshape ; valueshape ; (i. 0 ) ; n_iter
425425}}" 0 " _ 0 INDEX_TYPES
426426
@@ -447,7 +447,7 @@ test_batches =: {{)d
447447' initsz n_iter sz mx' =. y
448448refdict =. conew ' refdictionary'
449449params =. x , < (' initcapacity' ; initsz) ,: (' keytype' ; ' boxed' )
450- jdict =. params conew ' jdictionary '
450+ jdict =. params conew ' jdict '
451451for. i. n_iter do.
452452 keys =. < @ ": " 0 vals =. sz ? @ $ mx NB. Keys, vals for put.
453453 keys (> @ [ set__refdict ] )" 0 vals
@@ -508,7 +508,7 @@ NB. x is boxed name of index type.
508508NB. y is number of iterations , number of worker threads , number of keys and values.
509509test_multithreading1 =: {{)d
510510' n_iter n_threads sz' =. y
511- jdict =. (x , < ' ' ) conew ' jdictionary '
511+ jdict =. (x , < ' ' ) conew ' jdict '
512512' keys vals' =. ? ~ , ~ sz
513513NB. smoutput'put init',' ',":{.3 T.''
514514vals put__jdict keys
@@ -545,7 +545,7 @@ NB. y is number of rows , number of columns , number of threads
545545test_multithreading2 =: {{)d
546546' rows cols n_threads' =. y
547547params =. x , < (' valueshape' ; 2 ) ,: ' valuetype' ; ' boxed'
548- jdict =. params conew ' jdictionary '
548+ jdict =. params conew ' jdict '
549549(16 & T. " 0 (rows , 2 ) $ 0 ) put__jdict i. rows
550550row_sums =: rows $ 0
551551magic =: {{ (2 * x + 3 ) + 3 * y + 7 }}
@@ -579,7 +579,7 @@ NB. x is boxed name of index type.
579579NB. y is number of iterations , number of worker threads.
580580test_multithreading3 =: {{)d
581581' n_iter n_threads' =. y
582- jdict =. (x , < ' ' ) conew ' jdictionary '
582+ jdict =. (x , < ' ' ) conew ' jdict '
583583NB. x is jdict
584584NB. y is number of iterations
585585prog =: {{)d
@@ -616,7 +616,7 @@ NB. Result is array of two boxes:
616616NB. * array of shortest-path distances from the source to every vertex
617617NB. * predecessor array for shortest-path tree.
618618dijkstra =: {{
619- q =. conew& ' jdictionary ' ' tree' , & < (' keyshape' ; 2 ) ,: ' valueshape' ; 0
619+ q =. conew& ' jdict ' ' tree' , & < (' keyshape' ; 2 ) ,: ' valueshape' ; 0
620620 ' ds ps' =. ($ & _ ; $ & _1 )@ # x NB. Initialize distances and predecessors.
621621 ' ' put__q 0 , y [ ds =. 0 y } ds NB. Distance to source is 0.
622622 while. 0 < count__q ' ' do.
@@ -705,7 +705,7 @@ partition =: {{
705705 NB. * l is x-coord of platform left end
706706 NB. * h is y-coord of platform
707707 NB. * id is unique platform ID.
708- s =. ' jdictionary ' conew~ ' tree concurrent' , & < (' keytype' ; datatype y ) , (' valuetype' ; ' boxed' ) ,: ' valueshape' ; 2
708+ s =. ' jdict ' conew~ ' tree concurrent' , & < (' keytype' ; datatype y ) , (' valuetype' ; ' boxed' ) ,: ' valueshape' ; 2
709709 NB. Is key r in y greater then l from value ((l , h) ; id) in x.
710710 NB. This tells whether entry represents non-empty platform.
711711 ok =. (> (0 ; 0 )& {:: )~
@@ -768,8 +768,8 @@ f =: {.@[ 1r2&*@:+ (* {:)~ NB. (12).
768768NB. x is D.
769769NB. y is x(1 - D, T).
770770enc =: {{
771- ' a b' =. ' jdictionary ' (conew , & < conew)~ ' hash' , & < ' keytype' ; ' extended'
772- ' pe pw' =. ' jdictionary ' (conew , & < conew)~ ' hash' , & < (' keytype' ; ' extended' ) ,: ' valuetype' ; ' rational'
771+ ' a b' =. ' jdict ' (conew , & < conew)~ ' hash' , & < ' keytype' ; ' extended'
772+ ' pe pw' =. ' jdict ' (conew , & < conew)~ ' hash' , & < (' keytype' ; ' extended' ) ,: ' valuetype' ; ' rational'
773773B =. 0x
774774for_bit. x }. y do.
775775 idxs =. (bit_index ,: x ) (1x , 1x & (] F::(+ +: )));. 0 y
@@ -800,8 +800,8 @@ dec =: {{
800800' T c' =. y
801801F =. + / @: (* 1r2 ^ # \ ) c NB. (35).
802802D =. # x
803- ' a b' =. ' jdictionary ' (conew , & < conew)~ ' hash' , & < ' keytype' ; ' extended'
804- ' pe pw' =. ' jdictionary ' (conew , & < conew)~ ' hash' , & < (' keytype' ; ' extended' ) ,: ' valuetype' ; ' rational'
803+ ' a b' =. ' jdict ' (conew , & < conew)~ ' hash' , & < ' keytype' ; ' extended'
804+ ' pe pw' =. ' jdict ' (conew , & < conew)~ ' hash' , & < (' keytype' ; ' extended' ) ,: ' valuetype' ; ' rational'
805805B =. 0x
806806for. i. T do.
807807 idxs =. 1x , 1x ] F::(+ +: ) (- D) {. x
0 commit comments