Skip to content

Pushing a branch for adding the IndexedLinkedList.#664

Closed
coderodde wants to merge 5 commits intoapache:masterfrom
coderodde:add-indexed-linked-list
Closed

Pushing a branch for adding the IndexedLinkedList.#664
coderodde wants to merge 5 commits intoapache:masterfrom
coderodde:add-indexed-linked-list

Conversation

@coderodde
Copy link

This PR contains:

  1. IndexedLinkedList: the actual list implementation we try to propose for inclusion in Collections.
  2. ExtendedTreeList: the subclass of TreeList used in JMH benchmarking.
  3. The actual JMH benchmark (that supports our bold claim that ILL > TreeList)
  4. A couple of unit test files for testing.

Limitations so far:

  1. We cannot make our unit test files run.
  2. Our IDE (NetBeans) introduced two configuration files that failed the assumption of having the license in them.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @coderodde
PRs should not include IDE metadata. I've added these NetBean files to the /.gitignore file. If you rebase this PR on git master, these two files will be removed from the PR (but remain locally for you).

<artifactId>jmh-core</artifactId>
<version>${commons.jmh.version}</version>
<scope>test</scope>
<version>1.37</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these edits.


/**
*
* @author Rodion "rodde" Efremov
Copy link
Member

@garydgregory garydgregory Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove author and version tags. since tags are only needed for new public and protected elements under main.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @coderodde
The build fails because the new tests don't cover all of the new code. To see the code coverage, you can run mvn clean verify site and look at the JaCoCo report in the generated report in target/site/jacoco/index.html

@coderodde
Copy link
Author

coderodde commented Dec 7, 2025

Hello, @garydgregory

Are these correct instructions for rebasing the NetBeans related files:

https://chatgpt.com/s/t_693544c351308191a5467b6d20d0f856

?

@vlsi
Copy link

vlsi commented Dec 7, 2025

It would be great if the new data structure did not require pulling all the other commons-collections dependencies.
I am sure it is the right time to consider adding the new structure as a new (optional) module of commons-collections, so the users could select the bits they need.

@garydgregory
Copy link
Member

garydgregory commented Dec 7, 2025

Hello, @garydgregory

Are these correct instructions for rebasing the NetBeans related files:

https://chatgpt.com/s/t_693544c351308191a5467b6d20d0f856

?

Hello @coderodde

Thank you for your updates.

Unless you know git, you should go with a known and trusted source, for example:

HTH

* in benchmarking the actual {@code TreeList} against the
* {@link IndexedLinkedList}.
*/
public class ExtendedTreeList<E> extends TreeList<E> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @coderodde,

This class doesn't belong in main. Why is this needed at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @garydgregory ,

I had to roll ExtendedTreeList in order to provide such methods as getFirst() and friends for the actual JMH benchmark. Shall I remove it from the PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @coderodde

Thank you for your quick reply.

I think I see what's happening here: java.util.LinkedList<E> implements Deque<E> but org.apache.commons.collections4.list.TreeList<E> doesn't. It looks like ExtendedTreeList implements Deque methods but doesn't actually implement the interface with an implements Deque<E> in the code. Then I see IndexedLinkedList implements Deque. So we have a bit of a mismatch.

So:

  • It's good that IndexedLinkedList implements Deque<E>
  • It's not good that ExtendedTreeList doesn't

If all of that makes sense and you agree, do you think that org.apache.commons.collections4.list.TreeList<E> should implement Deque<E> first, then ExtendedTreeList would become superflous.

If you agree, you can create a PR that causes org.apache.commons.collections4.list.TreeList<E> to implement Deque<E>, with tests 😉

Another wrinkle is that IndexedLinkedList doesn't fit in the JRE's collection framework by extending java.util.AbstractSequentialList<E> or java.util.AbstractList<E>. Is there a reason to not fit it in?

Thank. you!

public class IndexedLinkedList<E> implements Deque<E>,
List<E>,
Cloneable,
java.io.Serializable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a fully qualified name java.io.Serializable -> Serializable.

Copy link
Member

@garydgregory garydgregory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @coderodde

Thank you for your update and for working through my questions and comments 😄

Is the intent to replace TreeList with your new implementation? We don't want 2 implementations of the same kind of class. It seems so to me, let me know.

If so, and the purpose of this PR, move ILL to the jmh package and call it TreeListNew. Then, if the new code proves better, we can just replace the old with the new in a secondary step.

Also, the TreeList Javadoc makes claims compared to ArrayList and LinkedList. I don't see JMH tests to support these claims, unfortunately. We don't want a new implementation to be worse compared to these existing claims.

Do you see an improvement or degradation there?

Thank you!

@coderodde coderodde closed this Dec 7, 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.

3 participants