I want to duplicate an instance of a data structure. Since go does not have any builtins, I am using a third party library:
For example, I may try use deep copy with a hash set.
var c, d hashset.Set c = *hashset.New() c.Add(1) deepcopy.Copy(d, c) c.Add(2) fmt.Println(c.Contains(2)) fmt.Println(d.Contains(2)) fmt.Println(c.Contains(1)) fmt.Println(d.Contains(1))
However, the content of the hash set is not copied at all. I know deep copy modules can't copy unexported values, but since there is no builtin "copy constructor" in the library, does it mean it is not possible to fully duplicate a data structure instance with the library without modifying its code? (Similar problem happens with some other libraries I looked into).
I am new to golang and does not feel right, since similar things can be easily achieved for example in C++. I know I could write my own version or modify their code, but it is too much work than expected and that's why I think there should be an idiomatic way.
PS: For people who may say "there is no need of such functionality", I am distributing some complex state with some data structures to parallel calculation threads, they use the states directly and must not interfere with each other.