emirpasic / gods

GoDS (Go Data Structures) - Sets, Lists, Stacks, Maps, Trees, Queues, and much more
Other
16.32k stars 1.77k forks source link

LinkedHashMap Sort? #228

Closed dylanhitt closed 1 year ago

dylanhitt commented 1 year ago

I was curious as to why the LinkedHashMap is not sortable with the underlying doublylinkedlist sort method?

If there is no reason particularly I would't mind implementing it. It seems relatively straightforward unless I'm missing something.

Thanks

emirpasic commented 1 year ago

Maybe I don't understand the question, but the LinkedHashMap by definition preserves the insertion order, and that's simply achieved by appending the keys to the underlying doubly linked list that holds those inserted keys in that order. As far as I understand it, there is no other sorting needed.

Please clarify if I misread your question.

Cheers

dylanhitt commented 1 year ago

Today I learned.

Apologies for my ignorance, in all my time I never knew that was a requirement for linkedhashmap. I will roll my own (thing).

emirpasic commented 1 year ago

No worries, I also double checked myself ;)