summary refs log tree commit diff stats
path: root/README
Commit message (Expand)AuthorAgeFilesLines
* README: updatedhut2010-05-241-6/+18
* README: minor changehut2010-05-151-2/+2
* README: rewritehut2010-05-151-115/+47
* Fixed bug #65 by adding flag "--fail-if-run"hut2010-04-261-1/+1
* README: Removed finished parts of roadmaphut2010-04-191-2/+0
* README: slightly improved Roadmaphut2010-04-131-1/+2
* README: added Roadmaphut2010-04-131-0/+18
* Fixed suggested cd-after-exit-script for zshhut2010-04-131-1/+1
* README: updatedhut2010-03-291-1/+1
* removed the cd-after-exit hackhut2010-03-291-0/+13
* README: Removed the reference to code/keys.rb >_<hut2010-03-291-2/+2
* incremented verison number v1.0.4hut2010-03-121-2/+2
* README: typohut2010-03-121-2/+2
* more documentationhut2010-03-121-3/+10
* README: slightly changed introductionhut2010-03-121-3/+3
* README: changed introductionhut2010-03-121-8/+10
* README: updatedhut2010-03-121-16/+19
* incremented version number and updated pydoc html files v1.0.3hut2010-02-161-2/+2
* readme: normalized letter casing in headingshut2010-02-151-2/+2
* updated READMEhut2010-02-151-29/+40
* made configuration more simplehut2010-01-251-6/+2
* README: corrected bad instructionshut2010-01-241-2/+2
* readme: improvedhut2010-01-201-6/+13
* 1.0.2! v1.0.2hut2010-01-141-2/+2
* readme: added part "customizing ranger"hut2010-01-141-0/+16
* readme: removed ugly sentencehut2010-01-141-3/+1
* new minor version v1.0.1hut2010-01-021-2/+2
* readme: updatedhut2010-01-011-4/+77
* decided to use python from now onhut2009-11-221-1/+1
* Initial commithut2009-11-161-0/+11
='n318' href='#n318'>318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
44b250 ^
d059fe74 ^
4690ce81 ^
dcc060c7 ^




4690ce81 ^
a654e4ec ^
2f02189d ^
4690ce81 ^
2f02189d ^
d059fe74 ^
2f02189d ^
d990e8f0 ^
dcc060c7 ^





4690ce81 ^
44c1aeef ^
a654e4ec ^

d059fe74 ^
2f02189d ^
4690ce81 ^
dcc060c7 ^







4690ce81 ^
44c1aeef ^

a654e4ec ^
2f02189d ^
dcc060c7 ^
4690ce81 ^
44c1aeef ^
dcc060c7 ^




4690ce81 ^
dcc060c7 ^










3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^




3e1349d2 ^
a654e4ec ^
f344b250 ^
dcc060c7 ^
3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^




3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^







3e1349d2 ^
f344b250 ^

dcc060c7 ^





3e1349d2 ^
f344b250 ^


dcc060c7 ^



3e1349d2 ^
f344b250 ^









dcc060c7 ^



3e1349d2 ^

f344b250 ^

3e1349d2 ^
f344b250 ^


dcc060c7 ^




3e1349d2 ^

f344b250 ^


dcc060c7 ^
f344b250 ^



dcc060c7 ^




3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^




3e1349d2 ^
f344b250 ^


dcc060c7 ^
3e1349d2 ^

f344b250 ^



3e1349d2 ^
f344b250 ^




dcc060c7 ^




3e1349d2 ^
f344b250 ^

a654e4ec ^
dcc060c7 ^
3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^




3e1349d2 ^
a654e4ec ^
f344b250 ^
dcc060c7 ^
3e1349d2 ^
f344b250 ^

dcc060c7 ^
3e1349d2 ^
dcc060c7 ^
f344b250 ^

dcc060c7 ^
f344b250 ^


dcc060c7 ^








3e1349d2 ^
f344b250 ^



dcc060c7 ^







4690ce81 ^

c842d90b ^
dcc060c7 ^

f344b250 ^

dcc060c7 ^




4690ce81 ^
f344b250 ^
4690ce81 ^
dcc060c7 ^
d059fe74 ^
4690ce81 ^
dcc060c7 ^














a654e4ec ^
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422



                                                                                          
                              

                                                
                                  

                                                                                         

                       
                                                                                                 
                                                                                            
                                      
                             
                            
                             
                                  
                            

                              
                               
                                                                           
                           
                                  

        





                               

       
                         














                                                                                                                                                                                                      

                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            




                                                                                         
                                                                       
                                                                                                                                                                                                                                                           







                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                     
                                                                            
                                                                                                                                                                                           
                                                                                                                                                           
                                                                                                                                                                                 
                                                                                                                                                              
                                                                                                                                                                                
                                                                                                                                                             
                                                                                                                                                                               
                                                                                                                                                            
                                                                                                                                                                                   
                                                                                                                                                                
                                                                                                                                                                                             



                                                                                                                                                                          


                                                                                                                                                                                                                                                                                                                               

                                

                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                        


                                                                                                                                                                                                                                                                                                                                                                 
                                  
                                                                                                                                                                    


                                                                                                                                                 
                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                               




                                                                                                            
                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                    
                                                                                                                                                 
                                                                                                             
                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                     
                                                                                                                        





                                                                                                                                                      
                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                         

                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                          







                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                    

                                                                                                                                                                     
                                                                                                                                                                                         
                                                                                                                                                                                                                                     
                                                                                    
                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                                                                   




                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                          










                                                                                                                 
                                           

                                                                
 
                                        
                                                                                                                                                                                  

                                                                                                                 
                                                                                                                                                                                  


                                                                                                                                                                                                                   




                                                                                       
                                                     
                                   
                                   
 
                                           

                                   
 
                                        
                                                                                                                                                                                                                                                  

                                                                                                                 
                                                                                                                                                                                                                                                  


                                                                                                                                                                                                                   




                                                                             
                                           

                                                                                                            
 
                                        
                                                                                                                                                                                  

                                                                                                                 
                                                                                                                                                                                  


                                                                                                                                                                                                                   







                                                                                                    
                                        

                                                                                                                       





                                                                                                         
                                        


                                                                                                                                                                                                                   



                                                                       
                                        









                                                                                                                                                                                                                   



                                                                     

                                                                                                                                                        

                                                                                                                       
                                                                                                                                                        


                                                                                                                                                                                                                   




                                                                                                                   

                                                                                                                                                        


                                                                                                                       
                                                   



                                                                                                                                                                                                                   




                                                                                  
                                           

                                                                
 
                                           

                                                                
 
                                        
                                                                                                                                                                                  

                                                                                                                 
                                                                                                                                                                                  


                                                                                                                                                                                                                   




                                                                                         
                                           


                                                                
 

                                                                                                                                                        



                                                                                                                                                                                                                                                            
                                                                                                                                                        




                                                                                                                                                                                                                                                            




                                                                                                
                                           

                                                                
                                   
 
                                           

                                   
 
                                        
                                                                                                                                                                                                                                                                                                                    

                                                                                                                 
                                                                                                                                                                                                                                                                                                                    


                                                                                                                                                                                                                     




                                                                                                
                                                     
                                   
                                   
 
                                           

                                   
 
                                        
                                                                                                                                                                                                                                                  

                                                                                                                 
                                                                                                                                                                                


                                                                                                                                                                                                                   








                                                                                                    
                                        



                                                                                                                                                                                                                   







                                                                                                                                                                                                              

                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

                                                                         

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     




                                                                                         
                                                                           
                                                                                                                                                                                                                                                                                                             
                                                                                                         
 
                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                    














                                                                                                                                                                                                                       
                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 069hash.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 12pt; font-size: 1em; }
.Constant { color: #00a0a0; }
.Special { color: #c00000; }
.muRecipe { color: #ff8700; }
.traceContains { color: #008000; }
.Comment { color: #9090ff; }
.Delimiter { color: #800080; }
.cSpecial { color: #008000; }
.Identifier { color: #c0a020; }
.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; }
.muData { color: #ffff00; }
.CommentedCode { color: #6c6c6c; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">// A universal hash function that can handle objects of any type.</span>
<span class="Comment">//</span>
<span class="Comment">// The way it's currently implemented, two objects will have the same hash if</span>
<span class="Comment">// all their non-address fields (all the way down) expand to the same sequence</span>
<span class="Comment">// of scalar values. In particular, a container with all zero addresses hashes</span>
<span class="Comment">// to 0. Hopefully this won't be an issue because we are usually hashing</span>
<span class="Comment">// objects of a single type in any given hash table.</span>
<span class="Comment">//</span>
<span class="Comment">// Based on <a href="http://burtleburtle.net/bob/hash/hashfaq.html">http://burtleburtle.net/bob/hash/hashfaq.html</a></span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
HASH<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;hash&quot;</span><span class="Delimiter">,</span> HASH<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> HASH: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'hash' takes exactly one ingredient rather than '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> HASH: <span class="Delimiter">{</span>
  <span class="Normal">const</span> reagent&amp; input = current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>hash<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> input<span class="Delimiter">));</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Comment">//: in all the code below, the intermediate results of hashing are threaded through 'h'</span>

<span class="Delimiter">:(code)</span>
<span class="Normal">size_t</span> hash<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  canonize<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_text<span class="Delimiter">(</span>r<span class="Delimiter">))</span>  <span class="Comment">// optimization</span>
    <span class="Identifier">return</span> hash_mu_text<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_address<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
    <span class="Identifier">return</span> hash_mu_address<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_scalar<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
    <span class="Identifier">return</span> hash_mu_scalar<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_array<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
    <span class="Identifier">return</span> hash_mu_array<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_container<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
    <span class="Identifier">return</span> hash_mu_container<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>is_mu_exclusive_container<span class="Delimiter">(</span>r<span class="Delimiter">))</span>
    <span class="Identifier">return</span> hash_mu_exclusive_container<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_scalar<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">double</span> input = is_literal<span class="Delimiter">(</span>r<span class="Delimiter">)</span> ? r<span class="Delimiter">.</span>value : get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
  <span class="Identifier">return</span> hash_iter<span class="Delimiter">(</span>h<span class="Delimiter">,</span> <span class="Normal">static_cast</span>&lt;<span class="Normal">size_t</span>&gt;<span class="Delimiter">(</span>input<span class="Delimiter">));</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_address<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>value == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span>
  trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;location &quot;</span> &lt;&lt; r<span class="Delimiter">.</span>value &lt;&lt; <span class="Constant">&quot; is &quot;</span> &lt;&lt; no_scientific<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">))</span> &lt;&lt; end<span class="Delimiter">();</span>
  r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">));</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>value != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    trace<span class="Delimiter">(</span><span class="Constant">9999</span><span class="Delimiter">,</span> <span class="Constant">&quot;mem&quot;</span><span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;skipping refcount at &quot;</span> &lt;&lt; r<span class="Delimiter">.</span>value &lt;&lt; end<span class="Delimiter">();</span>
    r<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>r<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">);</span>  <span class="Comment">// skip refcount</span>
  <span class="Delimiter">}</span>
  drop_from_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">&quot;address&quot;</span><span class="Delimiter">);</span>
  <span class="Identifier">return</span> hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> r<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_text<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  string input = read_mu_text<span class="Delimiter">(</span>get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">));</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>input<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    h = hash_iter<span class="Delimiter">(</span>h<span class="Delimiter">,</span> <span class="Normal">static_cast</span>&lt;<span class="Normal">size_t</span>&gt;<span class="Delimiter">(</span>input<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)));</span>
<span class="CommentedCode">//?     cerr &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; h &lt;&lt; '\n';</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> h<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_array<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">int</span> size = get_or_insert<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
  reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> elem = r<span class="Delimiter">;</span>
  <span class="Normal">delete</span> elem<span class="Delimiter">.</span>type<span class="Delimiter">;</span>
  elem<span class="Delimiter">.</span>type = copy_array_element<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i=<span class="Constant">0</span><span class="Delimiter">,</span> address = r<span class="Delimiter">.</span>value+<span class="Constant">1</span><span class="Delimiter">;</span>  i &lt; size<span class="Delimiter">;</span>  ++i<span class="Delimiter">,</span> address += size_of<span class="Delimiter">(</span>elem<span class="Delimiter">))</span> <span class="Delimiter">{</span>
    reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> tmp = elem<span class="Delimiter">;</span>
    tmp<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address<span class="Delimiter">);</span>
    h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> tmp<span class="Delimiter">);</span>
<span class="CommentedCode">//?     cerr &lt;&lt; i &lt;&lt; &quot; (&quot; &lt;&lt; address &lt;&lt; &quot;): &quot; &lt;&lt; h &lt;&lt; '\n';</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> h<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_container<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  type_info&amp; info = get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-&gt;</span>value<span class="Delimiter">);</span>
  <span class="Normal">int</span> address = r<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
  <span class="Normal">int</span> offset = <span class="Constant">0</span><span class="Delimiter">;</span>
  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> element = element_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">,</span> i<span class="Delimiter">);</span>
    <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>element<span class="Delimiter">,</span> <span class="Constant">&quot;ignore-for-hash&quot;</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span>
    element<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>address+offset<span class="Delimiter">);</span>
    h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> element<span class="Delimiter">);</span>
<span class="CommentedCode">//?     cerr &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; h &lt;&lt; '\n';</span>
    offset += size_of<span class="Delimiter">(</span>info<span class="Delimiter">.</span>elements<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>type<span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> h<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_mu_exclusive_container<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  <span class="Normal">const</span> type_tree* type = root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span>
  assert<span class="Delimiter">(</span>type<span class="Delimiter">-&gt;</span>value<span class="Delimiter">);</span>
  <span class="Normal">int</span> tag = get<span class="Delimiter">(</span>Memory<span class="Delimiter">,</span> r<span class="Delimiter">.</span>value<span class="Delimiter">);</span>
  reagent<span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> variant = variant_type<span class="Delimiter">(</span>r<span class="Delimiter">,</span> tag<span class="Delimiter">);</span>
  <span class="Comment">// todo: move this error to container definition time</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>variant<span class="Delimiter">,</span> <span class="Constant">&quot;ignore-for-hash&quot;</span><span class="Delimiter">))</span>
    raise &lt;&lt; get<span class="Delimiter">(</span>Type<span class="Delimiter">,</span> type<span class="Delimiter">-&gt;</span>value<span class="Delimiter">).</span>name &lt;&lt; <span class="Constant">&quot;: /ignore-for-hash won't work in exclusive containers</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
  variant<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>r<span class="Delimiter">.</span>value + <span class="Comment">/*</span><span class="Comment">skip tag</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">);</span>
  h = hash<span class="Delimiter">(</span>h<span class="Delimiter">,</span> variant<span class="Delimiter">);</span>
  <span class="Identifier">return</span> h<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Normal">size_t</span> hash_iter<span class="Delimiter">(</span><span class="Normal">size_t</span> h<span class="Delimiter">,</span> <span class="Normal">size_t</span> input<span class="Delimiter">)</span> <span class="Delimiter">{</span>
  h += input<span class="Delimiter">;</span>
  h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">10</span><span class="Delimiter">);</span>
  h ^= <span class="Delimiter">(</span>h&gt;&gt;<span class="Constant">6</span><span class="Delimiter">);</span>

  h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">3</span><span class="Delimiter">);</span>
  h ^= <span class="Delimiter">(</span>h&gt;&gt;<span class="Constant">11</span><span class="Delimiter">);</span>
  h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">15</span><span class="Delimiter">);</span>
  <span class="Identifier">return</span> h<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario hash_container_checks_all_elements)</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">3</span>:num
  <span class="Constant">4</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">98</span>/a
  <span class="Constant">6</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">4</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">6</span>:num
  <span class="Constant">7</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">3</span>:num<span class="Delimiter">,</span> <span class="Constant">6</span>:num
]
<span class="Comment"># hash on containers includes all elements</span>
<span class="traceContains">+mem: storing 0 in location 7</span>

<span class="Delimiter">:(scenario hash_exclusive_container_checks_all_elements)</span>
<span class="muData">exclusive-container</span> foo [
  <span class="Normal">x</span>:bar
  <span class="Normal">y</span>:num
]
<span class="muData">container</span> bar [
  <span class="Normal">a</span>:num
  <span class="Normal">b</span>:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">4</span>:num
  <span class="Constant">5</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">36</span>
  <span class="Constant">8</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">5</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">8</span>:num
  <span class="Constant">9</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">4</span>:num<span class="Delimiter">,</span> <span class="Constant">8</span>:num
]
<span class="Comment"># hash on containers includes all elements</span>
<span class="traceContains">+mem: storing 0 in location 9</span>

<span class="Delimiter">:(scenario hash_can_ignore_container_elements)</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>/ignore-<span class="Normal">for</span>-hash
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">3</span>:num
  <span class="Constant">4</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">98</span>/a
  <span class="Constant">6</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">4</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">6</span>:num
  <span class="Constant">7</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">3</span>:num<span class="Delimiter">,</span> <span class="Constant">6</span>:num
]
<span class="Comment"># hashes match even though y is different</span>
<span class="traceContains">+mem: storing 1 in location 7</span>

<span class="Comment">//: These properties aren't necessary for hash, they just test that the</span>
<span class="Comment">//: current implementation works like we think it does.</span>

<span class="Delimiter">:(scenario hash_of_zero_address)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:&amp;:num
]
<span class="traceContains">+mem: storing 0 in location 2</span>

<span class="Comment">//: This is probably too aggressive, but we need some way to avoid depending</span>
<span class="Comment">//: on the precise bit pattern of a floating-point number.</span>
<span class="Delimiter">:(scenario hash_of_numbers_ignores_fractional_part)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1.5</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>
  <span class="Constant">3</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">1</span>:num<span class="Delimiter">,</span> <span class="Constant">2</span>:num
]
<span class="traceContains">+mem: storing 1 in location 3</span>

<span class="Delimiter">:(scenario hash_of_array_same_as_string)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">10</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">3</span>
  <span class="Constant">11</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">97</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">98</span>
  <span class="Constant">13</span>:num<span class="Special"> &lt;- </span>copy <span class="Constant">99</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">10</span>:@:num/unsafe
  <span class="Identifier">return</span>-unless <span class="Constant">2</span>:num
  <span class="Constant">3</span>:text<span class="Special"> &lt;- </span><span class="Normal">new</span> [abc]
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">3</span>:text
  <span class="Identifier">return</span>-unless <span class="Constant">4</span>:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="traceContains">+mem: storing 1 in location 5</span>

<span class="Delimiter">:(scenario hash_ignores_address_value)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  *<span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:&amp;:num
  <span class="Constant">3</span>:&amp;:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  *<span class="Constant">3</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">3</span>:&amp;:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="Comment"># different addresses hash to the same result as long as the values the point to do so</span>
<span class="traceContains">+mem: storing 1 in location 5</span>

<span class="Delimiter">:(scenario hash_ignores_address_refcount)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  *<span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:&amp;:num
  <span class="Identifier">return</span>-unless <span class="Constant">2</span>:num
  <span class="Comment"># increment refcount</span>
  <span class="Constant">3</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">1</span>:&amp;:num
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">3</span>:&amp;:num
  <span class="Identifier">return</span>-unless <span class="Constant">4</span>:num
  <span class="Constant">5</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">4</span>:num
]
<span class="Comment"># hash doesn't change when refcount changes</span>
<span class="traceContains">+mem: storing 1 in location 5</span>

<span class="Delimiter">:(scenario hash_container_depends_only_on_elements)</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>
]
<span class="muData">container</span> bar [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">3</span>:num
  <span class="Constant">4</span>:bar<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a
  <span class="Constant">6</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">4</span>:bar
  <span class="Identifier">return</span>-unless <span class="Constant">6</span>:num
  <span class="Constant">7</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">3</span>:num<span class="Delimiter">,</span> <span class="Constant">6</span>:num
]
<span class="Comment"># containers with identical elements return identical hashes</span>
<span class="traceContains">+mem: storing 1 in location 7</span>

<span class="Delimiter">:(scenario hash_container_depends_only_on_elements_2)</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>
  <span class="Normal">z</span>:&amp;:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  *<span class="Constant">1</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">2</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">1</span>:&amp;:num
  <span class="Constant">5</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">2</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">5</span>:num
  <span class="Constant">6</span>:&amp;:num<span class="Special"> &lt;- </span><span class="Normal">new</span> <span class="Constant">number:type</span>
  *<span class="Constant">6</span>:&amp;:num<span class="Special"> &lt;- </span>copy <span class="Constant">34</span>
  <span class="Constant">7</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">6</span>:&amp;:num
  <span class="Constant">10</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">7</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">10</span>:num
  <span class="Constant">11</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">5</span>:num<span class="Delimiter">,</span> <span class="Constant">10</span>:num
]
<span class="Comment"># containers with identical 'leaf' elements return identical hashes</span>
<span class="traceContains">+mem: storing 1 in location 11</span>

<span class="Delimiter">:(scenario hash_container_depends_only_on_elements_3)</span>
<span class="muData">container</span> foo [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:<span class="Normal">char</span>
  <span class="Normal">z</span>:bar
]
<span class="muData">container</span> bar [
  <span class="Normal">x</span>:num
  <span class="Normal">y</span>:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">47</span><span class="Delimiter">,</span> <span class="Constant">48</span>
  <span class="Constant">6</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">6</span>:num
  <span class="Constant">7</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">97</span>/a<span class="Delimiter">,</span> <span class="Constant">47</span><span class="Delimiter">,</span> <span class="Constant">48</span>
  <span class="Constant">12</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">7</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">12</span>:num
  <span class="Constant">13</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">6</span>:num<span class="Delimiter">,</span> <span class="Constant">12</span>:num
]
<span class="Comment"># containers with identical 'leaf' elements return identical hashes</span>
<span class="traceContains">+mem: storing 1 in location 13</span>

<span class="Delimiter">:(scenario hash_exclusive_container_ignores_tag)</span>
<span class="muData">exclusive-container</span> foo [
  <span class="Normal">x</span>:bar
  <span class="Normal">y</span>:num
]
<span class="muData">container</span> bar [
  <span class="Normal">a</span>:num
  <span class="Normal">b</span>:num
]
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:foo<span class="Special"> &lt;- </span>merge <span class="Constant">0</span>/x<span class="Delimiter">,</span> <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
  <span class="Constant">4</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:foo
  <span class="Identifier">return</span>-unless <span class="Constant">4</span>:num
  <span class="Constant">5</span>:bar<span class="Special"> &lt;- </span>merge <span class="Constant">34</span><span class="Delimiter">,</span> <span class="Constant">35</span>
  <span class="Constant">7</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">5</span>:bar
  <span class="Identifier">return</span>-unless <span class="Constant">7</span>:num
  <span class="Constant">8</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">4</span>:num<span class="Delimiter">,</span> <span class="Constant">7</span>:num
]
<span class="Comment"># hash on containers includes all elements</span>
<span class="traceContains">+mem: storing 1 in location 8</span>

<span class="Comment">//: An older version that supported only strings.</span>
<span class="Comment">//: Hash functions are subtle and easy to get wrong, so we keep the old</span>
<span class="Comment">//: version around and check that the new one is consistent with it.</span>

<span class="Delimiter">:(scenario hash_matches_old_version)</span>
<span class="muRecipe">def</span> main [
  <span class="Constant">1</span>:text<span class="Special"> &lt;- </span><span class="Normal">new</span> [abc]
  <span class="Constant">2</span>:num<span class="Special"> &lt;- </span>hash <span class="Constant">1</span>:text
  <span class="Constant">3</span>:num<span class="Special"> &lt;- </span>hash_old <span class="Constant">1</span>:text
  <span class="Constant">4</span>:<span class="Normal">bool</span><span class="Special"> &lt;- </span>equal <span class="Constant">2</span>:num<span class="Delimiter">,</span> <span class="Constant">3</span>:num
]
<span class="traceContains">+mem: storing 1 in location 4</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
HASH_OLD<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span> <span class="Constant">&quot;hash_old&quot;</span><span class="Delimiter">,</span> HASH_OLD<span class="Delimiter">);</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Checks&quot;)</span>
<span class="Normal">case</span> HASH_OLD: <span class="Delimiter">{</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">)</span> != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'hash_old' takes exactly one ingredient rather than '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Normal">if</span> <span class="Delimiter">(</span>!is_mu_text<span class="Delimiter">(</span>inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> <span class="Delimiter">{</span>
    raise &lt;&lt; maybe<span class="Delimiter">(</span>get<span class="Delimiter">(</span>Recipe<span class="Delimiter">,</span> r<span class="Delimiter">).</span>name<span class="Delimiter">)</span> &lt;&lt; <span class="Constant">&quot;'hash_old' currently only supports texts (address array character), but got '&quot;</span> &lt;&lt; inst<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>original_string &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
    <span class="Identifier">break</span><span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
<span class="Normal">case</span> HASH_OLD: <span class="Delimiter">{</span>
  string input = read_mu_text<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
  <span class="Normal">size_t</span> h = <span class="Constant">0</span> <span class="Delimiter">;</span>

  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span>  i &lt; SIZE<span class="Delimiter">(</span>input<span class="Delimiter">);</span>  ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    h += <span class="Normal">static_cast</span>&lt;<span class="Normal">size_t</span>&gt;<span class="Delimiter">(</span>input<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span>
    h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">10</span><span class="Delimiter">);</span>
    h ^= <span class="Delimiter">(</span>h&gt;&gt;<span class="Constant">6</span><span class="Delimiter">);</span>

    h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">3</span><span class="Delimiter">);</span>
    h ^= <span class="Delimiter">(</span>h&gt;&gt;<span class="Constant">11</span><span class="Delimiter">);</span>
    h += <span class="Delimiter">(</span>h&lt;&lt;<span class="Constant">15</span><span class="Delimiter">);</span>
  <span class="Delimiter">}</span>

  products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span>
  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>h<span class="Delimiter">);</span>
  <span class="Identifier">break</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->