samedi 14 avril 2018

Better alternative to nesting dictionaries for lookup tables

When building lookup tables that exceed a single dimension I find myself nesting dictionaries a lot:

public class MyLookupTable
{
    IDictionary<T1, IDictionary<T2, ISet<T3>>> mapOfMapOfSequences;

    // Update the table
    public void AddItem(T3 myItem);

    // Access the table
    public IEnumerable<T3> GetItems(T1 key1, T2 key2);
}

This has been working great for me so far, despite needing to write some wordy ContainsKey conditionals to access/modify the table.

Recently I am writing a caching mechanism that has 5 keys, and the dictionary field definition is a little ridiculous.

Architecturally, is there a design pattern I am completely overlooking that would make this problem a little more manageable?

Aucun commentaire:

Enregistrer un commentaire