Skip to content

More robust data structures - #6

Merged
oconnor0 merged 1 commit into
masterfrom
master-doug-expand-data-structures
Jul 8, 2026
Merged

More robust data structures#6
oconnor0 merged 1 commit into
masterfrom
master-doug-expand-data-structures

Conversation

@doug-jacob

Copy link
Copy Markdown

In order to smooth over transitions from the old Transit framework to the new one, some changes have been implemented for data structures.

NullKeyDictionary now implements IDictionary<object, object> and IReadOnlyDictionary<object, object> to make it more similar to the type it replaces from the old Transit, System.Collections.Immutable.ImmutableDictionary<object, object>. Callsites that originally used the old Transit expected to be able to use dictionary-related methods and extensions that are not all available from the System.Collections.IDictionary interface. This allows said callsites to simply change the type they cast values read from Transit from ImmutableDictionary<object, object> to IDictionary<object, object> without needing to change any other logic.

A wrapper class ListWrapper has also been added to preserve serialization information. Lists we receive from environments like Clojure would normally most closely be represented by LinkedLists in C#, but we prefer to use List for performance. Therefore, this wrapper class is used so that if we need to roundtrip data back to the original environment, the original type of the list is maintained in the data we send. Similarly to the situation with dictionaries, the old Transit read lists as ImmutableList<object>, and so for simplicity and to minimize impact on callsites, the wrapper class inherits from List<object>.

…ips; implemented IDictionary<object, object> interface on NullKeyDictionary to expose more methods that will minimize the impact that switching from old Transit to new Transit.Net will have
@doug-jacob
doug-jacob requested review from isaksky and oconnor0 July 8, 2026 21:23
public object Current => Entry;

KeyValuePair<object?, object?> IEnumerator<KeyValuePair<object?, object?>>.Current => _onNull
? new KeyValuePair<object?, object?>(null!, _dict._nullValue)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why null! when you're producing a value of object??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, whoops. This was copied verbatim from a few lines above, where we create a DictionaryEntry object for similar reasons, and the signature of the DictionaryEntry constructor takes a non-null object for a key

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK, was hoping it wasn't some required C# thing because of the context or generic arguments or something.

@oconnor0 oconnor0 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaksky, did you want to review this before I merge?

@isaksky

isaksky commented Jul 8, 2026

Copy link
Copy Markdown
Member

It looks ok, but I see a test fails:

  Failed TestVerifyExemplarFiles [6 ms]
  Error Message:
   Assert.IsNotNull failed. Could not find transit-format exemplar directory
  Stack Trace:
     at Transit.Net.Tests.TransitTest.TestVerifyExemplarFiles() in /home/runner/work/transit-csharp/transit-csharp/src/Transit.Tests/TransitTest.cs:line 2265
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

@oconnor0

oconnor0 commented Jul 8, 2026

Copy link
Copy Markdown

Yeah, that's why #5 is still unmerged too.

@isaksky

isaksky commented Jul 8, 2026

Copy link
Copy Markdown
Member

Ok. To answer the question more generally, no need to wait for me when you're ready to merge on this stuff.

@oconnor0
oconnor0 merged commit df2f0fb into master Jul 8, 2026
1 check failed
@oconnor0
oconnor0 deleted the master-doug-expand-data-structures branch July 8, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants