editoast: use type SupportedSignalingSystem everywhere - #16982
Conversation
c2c82f0 to
4eac28f
Compare
20656d0 to
dc89962
Compare
|
dc89962 to
204cb54
Compare
hhirtz
left a comment
There was a problem hiding this comment.
not sure adding more macro is a good step towards lower compilation times though... 🤔
204cb54 to
deee42f
Compare
8b3edd3 to
fb7c1a6
Compare
hhirtz
left a comment
There was a problem hiding this comment.
Thank you! more typing is good, but i think this solution is overengineered
first commit message says:
The function that hashes a
HashSet<SupportedSignalingSystemVariant>
is not trivial
but it is though? if you inline the discriminant functions you see it's just a 1-statement for loop and a call to hash. i don't think it calls for 4 tests with proptest... although i agree it's fun to play with, editoast isn't a playground for it
It looks like if we impl Ord for SupportedSignalingSystemVariant, we don't need the custom hashing function and the second commit becomes a lot simpler?
Also, on all the pathfinding API, we don’t need a full-fledge `SupportedSignalingSystem`, but only the variant is enough (for example, we don’t need the braking curves of ETCS). So we derive a `SignalingSystemVariant` for those API, with the help of `strum`. It will be used in a future commit. Also provides hashing functions that will be used to hash `HashSet<SupportedSignalingSystem>` (and the corresponding `*Variant`). We create a bitmask of all the present variants, using the discriminant of the variant’s enum. This should be unique, even if the order of the iteration is different. The function that hashes a `HashSet<SupportedSignalingSystemVariant>` is not trivial, and is supposed to respect a few properties. `proptest` is a library that basically do controlled fuzzing, which can help assert those properties. Signed-off-by: Jean SIMARD <woshilapin@tuziwo.info>
cadd7e4 to
6feda36
Compare
The reason I had the
I disagree. The complexity does not lie in the implementation itself (indeed, it’s a few lines of code), the complexity lies in the fact that this implementation does respect the properties a
I’m not comfortable implementing |
In some places, we were converting to `String` with no real added value. Let’s keep `HashSet<SupportedSignalingSystem>` everywhere, avoiding conversions. One of the inconvenient is the implementation of `Hash` for some of the `struct` that contains it (`HashSet` doesn’t implement `Hash`). With the help of `educe`, we can plug a custom function to hash such a `HashSet`. Signed-off-by: Jean SIMARD <woshilapin@tuziwo.info>
6feda36 to
82fbefc
Compare
In some places, we were converting to
Stringwith no real added value. Let’s keepHashSet<SupportedSignalingSystem>everywhere, avoiding conversions.One of the inconvenient is the implementation of
Hashfor some of thestructthat contains it (HashSetdoesn’t implementHash). With the help ofeduce, we can plug a custom function to hash such aHashSet. And we consider create a bitmask of all the present variant, using the discriminant of the variant’s enum. This should be unique, even if the order of the iteration is different.