Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sbinet opened this issue Feb 14, 2022 · 0 comments
Open

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

sbinet opened this issue Feb 14, 2022 · 0 comments

Comments

@sbinet
Copy link
Member

sbinet commented Feb 14, 2022

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:

  • read a ROOT file produced with C++/pyroot and thus generate equivalent Go types to hold these data
  • write a ROOT file from groot (so with hopefully already valid Go types)

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:

  • set<T> to/from []T
  • map<K,V> to/from []pair[K,V]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant