go-hep / hep

hep is the mono repository holding all of go-hep.org/x/hep packages and tools
https://go-hep.org
BSD 3-Clause "New" or "Revised" License
231 stars 35 forks source link

groot: robust interop w/ C++ std::set and std::map #909

Open sbinet opened 2 years ago

sbinet commented 2 years ago

right now, we represent std::set<T> and std::map<K,V> (and their multiX and unordered_X equivalents) as map[T]struct{} and map[K]V.

however, e.g. std::set<std::vector<T>> breaks this conversion: map[[]T]struct{} isn't a valid Go type ([]T isn't hashable). same issue for, say, std::map<std::vector<T>, V>.

there are 2 use cases:

obviously, the latter isn't impacted by this issue. to tackle the former, a possible avenue would be to implement dedicated types mimicking C++ semantics:

type Map[K, V any] struct { ... }
type Set[T any] struct { ... }
type MultiMap[K, V any] struct { ... }
type MultiSet[T any] struct { ... }
type UnorderedMap[K, V any] struct { ... }
type UnorderedSet[T any] struct { ... }
type UnorderedMultiMap[K, V any] struct { ... }
type UnorderedMultiSet[T any] struct { ... }

ultimately, this might be better resolved by implementing on-the-fly conversions between on-disk and in-memory representations: