Skip to content

linkedliststack not longer requires T to be comparable#288

Open
oliverdain wants to merge 1 commit into
emirpasic:masterfrom
oliverdain:simple-list
Open

linkedliststack not longer requires T to be comparable#288
oliverdain wants to merge 1 commit into
emirpasic:masterfrom
oliverdain:simple-list

Conversation

@oliverdain
Copy link
Copy Markdown

I had a use case for a stack with a type that's not comparable. I noticed that none of the methods on linkedliststack.Stack actually requires T to be comparable. It seems the requirement stems from the fact that linkedliststack is based on singlylinkedlist which has 3 methods (IndexOf, Contains, and Sort) which Stack doesn't use.

This refactors singlylinkedlist.List into a singlylinkedlist.SimpleList which has a T any generic type. And then singlylinkedlist.List embeds SimpleList and adds those 3 methods. Then Stack is based on a SimpleList[T any] and it no longer requires comparable.

If you like the general approach here I suspect you'd want additional changes like an interface for simple lists, maybe all stacks no longer require comparable, etc. I wanted to get some early feedback to see if you're on board with this direction and, if so, where you'd want to take this.

has all methods except `Contains`, `IndexOf`, and `Sort` so `T` no
longer has to be a comparable. Then I changed `linkedliststack` to be
based on `SimpleList` instead of `List` so it no longer requires `T` to
be a comparable.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Sep 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant