Skip to content

BartMassey/collhash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

collhash: demo of collection hashing w/ and w/o length

Bart Massey 2023

This little code snippet shows why it is necessary to hash in the length when hashing a collection.

When run without any feature flags, this program prints

 false
 false
 false
 false
 true
 true

The first four falses indicates that it is apparently not necessary to hash in the length for arrays of strs (probably because the length of each str is hashed in anyway). However, the fifth and sixth true indicate that different slices of unit hash identically (probably because each of these is a zero-sized type and thus no actual hashing is performed).

Run with --features=hash_len to show that hashing in the slice length fixes the problem.

License

This work is licensed under the "MIT License". Please see the file LICENSE.txt in this distribution for license terms.

About

demonstration of collection hashing without length

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages