Skip to content

Searching by partial key after removing a full key that also contained that partial key fails #6

@adamlemmon

Description

@adamlemmon

After I remove a key via the .Remove method, calling TryGetValuesByPartialKey with a key that was contained in the full key throws an exception. There are still legitimate matching keys in the dictionary, but the method fails instead of returning them.

After removing an item by a full key, all operations should continue to work for the remaining items.

I have confirmed that the other items were returned correctly before the remove call.

I have a sample test below. Uncomment the TestMethod and Asserts and it is in valid MsTest syntax:

//[TestMethod]
public void RemoveByFullKeyTests()
{
    IMultiKeyMap<string, IEnumerable<string>, string> dict = MultiKeyMaps.CreateMultiKeyDictionary<string, IEnumerable<string>, string>();
    dict.Add(new[] { "first", "crazy", "1st" }, "one");
    dict.Add(new[] { "first", "other" }, "one again");
    dict.Add(new[] { "first", "something else" }, "one a third time");

    IEnumerable<string> values;
    //Assert.IsTrue(dict.TryGetValuesByPartialKey(new[] { "first" }, out values));
    //Assert.AreEqual(3, values.Count());

    IEnumerable<IEnumerable<string>> fullKeys = new[] { new[] { "first", "crazy", "1st" } };
    bool removedAny = false;
    foreach (var fullKey in fullKeys)
    {
        removedAny |= dict.Remove(fullKey);
    }

    //Assert.IsTrue(removedAny);

    var tryGetValuesByPartialKey = dict.TryGetValuesByPartialKey(new[] { "first" }, out values); // Fails here even though the dictionary still contains two values that should match this partial key
    //Assert.IsTrue(tryGetValuesByPartialKey);
    //Assert.AreEqual(2, values.Count());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions