DanielT / autosar-data

A rust crate to work with Autosar data (arxml) files
Apache License 2.0
32 stars 10 forks source link

Sorting enhancements #20

Closed christianhecht86 closed 4 weeks ago

christianhecht86 commented 4 weeks ago

Hi Daniel,

I tried out the sorting functionality of autosar-data. My use case is, I like to compare my newly generated ARXML files using autosar-data with ARXML files generated by legacy toolings.

Here I miss sorting for reference lists like:

<I-SIGNAL-TRIGGERING>
  <SHORT-NAME>ST_Name</SHORT-NAME>
  <I-SIGNAL-PORT-REFS>
    <I-SIGNAL-PORT-REF DEST="I-SIGNAL-PORT">/somepackagea/bla/bla/portx</I-SIGNAL-PORT-REF>
    <I-SIGNAL-PORT-REF DEST="I-SIGNAL-PORT">/somepackagea/bla/bla/porty</I-SIGNAL-PORT-REF>
  </I-SIGNAL-PORT-REFS>
</I-SIGNAL-TRIGGERING>

But also for the wrapped lists like:

<SYSTEM>
  <SHORT-NAME>System</SHORT-NAME>
  <FIBEX-ELEMENTS>
    <FIBEX-ELEMENT-REF-CONDITIONAL>
      <FIBEX-ELEMENT-REF DEST="ECU-INSTANCE">/somepackagea/ecu1</FIBEX-ELEMENT-REF>
    </FIBEX-ELEMENT-REF-CONDITIONAL>
    <FIBEX-ELEMENT-REF-CONDITIONAL>
      <FIBEX-ELEMENT-REF DEST="ECU-INSTANCE">/somepackageb/ecu2</FIBEX-ELEMENT-REF>
    </FIBEX-ELEMENT-REF-CONDITIONAL>
  </FIBEX-ELEMENTS>
</SYSTEM>

May be also some customization possibility of the sorting would be nice, to sort for example SocketConnections inside of SocketConnectionBundles by socket-address name or SocketConnectionIPduIdentifier by headerId or pdu-triggering name.

It would be also nice to have some sorted_insert function, to not need to sort the model afterwards.

Thanks

Christian

DanielT commented 4 weeks ago

Thanks for the suggestions.

The first one makes a lot of sense and would be simple to add, so I will definitely do that.

For the second I agree that it would be useful, but I'll have to see if I can come up with a sensible implementation.

The third suggestion is probably better handled by custom code. The function move_element_here_at can be used to move items within a parent element. Example: parent_element.move_element_here_at(sub_element, 2) would move the sub_element to position 2 inside the parent.

Finally, regarding sorted_insert: I don't see the benefit of continuously sorting, compared to just doing it once at the end. At best the performance would be equal, but more likely it would be worse. Meanwhile it would increase the complexity of the API of the crate. If you are able to determine the order of the inserted elements in advance, you could use create_sub_element_at to directly create each element at the correct "sorted" position.