Skip to content

LurchTable Insertion Order Not Working #12

Open
@NightOwl888

Description

@NightOwl888

You have advertised LurchTable as a replacement for LinkedHashMap. Per this answer on StackOverflow:

LinkedHashMap will iterate in the order in which the entries were put into the map

Basically, the primary purpose of LinkedHashMap is to keep the insertion order regardless of deletions and re-additions, so I would expect this replacement for it should function the same way, but doesn't. Since there is an insertion order in the enumeration, but it doesn't function, I suspect this is a bug.

    class Program
    {
        static void Main(string[] args)
        {
            var lurchTable = new LurchTable<string, string>(16, LurchTableOrder.Insertion);

            for (int i = 0; i < 20; i++)
            {
                string entry = "entry" + i;
                lurchTable.Add(entry, entry);
            }

            foreach (var entry in lurchTable)
            {
                Console.WriteLine(entry.Key);
            }

            Console.ReadKey();
        }
    }

Results:

entry4
entry13
entry8
entry1
entry19
entry17
entry5
entry12
entry9
entry2
entry16
entry11
entry18
entry6
entry15
entry3
entry10
entry7
entry0
entry14

Unfortunately, it seems that .NET doesn't contain a dictionary that guarantees the results will be iterated in insertion order. Well, there is OrderedDictionary, but it is not generic.

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