Closed aler9 closed 5 years ago
Hashes should be passed by value to allow comparison for quality. They are more like strings in this regard.
Some struct types may still use pointers to TTH
, since the field may be optional.
So there is no contradiction here. It's done this way by design.
This is a low priority, secondary design issue for which there isn't a right answer.
In most programming languages, arrays are always passed by reference from function to function. In go there's a big exception, as slices are passed by reference, but fixed-size arrays are passed by value, ie they are deep-copied before the function call.
Regarding hashes import/export functions, we have:
I think hashes shall be passed, stored and returned always by reference, since every slice and every map is already passed and stored by reference.
the signature of TreeHash() could be changed to
func TreeHash(r io.Reader) (root *Hash, err error)
and hashes could be saved in messages by reference:
type MessageSomething struct { tth *TTH }
it would be possible to remote utility functions like this one:
func getTHPointer(s string) *tiger.Hash
and the library would be clearer, as TTH is saved by reference in some structs like:
type Search struct { *TTH }
and by value in some others:
type FileInfo struct { TTH adc.TTH }