This project is read-only.
Using Structural Hashing

Category:
Equality, Comparison and Hashing
Description: F# supports structural hashing on values. Typically only F# record/union structured terms are traversed, though this can be customized on a per-type basis. This sample shows the results of some simple structural hashing operations.
Code:
let HashingSample2() =
let show a = printfn "hash(%A) : %d" a (hash a)
show 1;
show 2;
show "1"
show "2"
show "abb"
show "aBc" // case-sensitive
show None;
show (Some 1);
show (Some 0);
show [1;2;3];
show [1;2;3;4;5;6;7;8];
show [1;2;3;4;5;6;7;8;9;10;11];
show [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]

//--------------------------------------------------------

Execution Result:
hash(1) : 1
hash(2) : 2
hash("1") : -842352753
hash("2") : -842352754
hash("abb") : 2103075711
hash("aBc") : 539088922
hash() : 0
hash(Some 1) : -1640531462
hash(Some 0) : -1640531463
hash([1; 2; 3]) : 1956583134
hash([1; 2; 3; 4; 5; 6; 7; 8]) : 922428386
hash([1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11]) : 1771492728
hash([1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15]) : -926589492

Last edited Sep 14, 2011 at 3:57 AM by ttliu2000, version 1

Comments

No comments yet.