0

I'm converting some Java code to C#. Part of my code uses Google Guava TreeMultiMap to provide a mechanism to have the equivalent of a dictionary sorted by key and allows duplicate null keys).

Is there an equivalent or library available to match this, Dictionary doesn't seem to support duplicate and Lookup class doesn't seem a match either as I need to keep adding (Lookup is immutable) and I need to add null values and keep it sorted.

This is the kind of thing I'm doing with it:

//declaration section
Multimap<Location, Interconnect> interconnects;
interconnects = TreeMultimap.create(Ordering.natural(),
            Interconnect.ORDER_NATURAL_NULLCHECK);

//comparator provider
static final Ordering<Interconnect> ORDER_NATURAL_NULLCHECK = new Ordering<Interconnect>() {

    @Override
    public int compare(@Nullable final Interconnect arg0,
            @Nullable final Interconnect arg1) {
        return Ordering.natural().nullsFirst().compare(arg0, arg1);
    }
};

//and I can do kind of the following quite happily:
interconnects.put(new Location(), null);
interconnects.put(new Location(), null);
interconnects.put(new Location(), null);
interconnects.put(new Location(), new Interconnect("A"));
interconnects.put(new Location(), new Interconnect("A");
Neil Walker
  • 5,334
  • 10
  • 51
  • 75
  • The C# lookup would be the most appropriate analog, but there's no public implementation and that's mutable. – Jeff Mercado Oct 15 '18 at 17:53
  • 1
    Possible duplicate of [Duplicate keys in .NET dictionaries?](https://stackoverflow.com/questions/146204/duplicate-keys-in-net-dictionaries) – Fabjan Oct 15 '18 at 17:55
  • Well, a Lookup is immutable and I need to keep adding to the collection, plus I'm adding null values, I don't know if Lookup supports that? I guess the Tree part can be addressed by separately sorting... – Neil Walker Oct 15 '18 at 18:27

0 Answers0