Igor Rudenko created COLLECTIONS-897:
----------------------------------------
Summary: Add lexicographic, duplicate-aware permutation iterator
(Knuth Algorithm L)
Key: COLLECTIONS-897
URL: https://issues.apache.org/jira/browse/COLLECTIONS-897
Project: Commons Collections
Issue Type: New Feature
Components: Collection, Iterator
Reporter: Igor Rudenko
h3. Problem
o.a.c.c4.iterators.PermutationIterator uses Steinhaus-Johnson-Trotter and is
positional, not value-aware: for ["A","A","B"] it emits 6 lists, each distinct
arrangement twice. There is currently no way in Commons Collections to iterate
the distinct permutations of a multiset, nor to iterate in lexicographic order.
h3. Proposal
Add LexicographicPermutationIterator<E> implementing Iterator<List<E>>, using
Knuth's Algorithm L (TAOCP Vol. 4A, 7.2.1.2). Existing PermutationIterator is
unchanged.
{code:java}
public LexicographicPermutationIterator(Collection<? extends E> coll) // E
extends Comparable
public LexicographicPermutationIterator(Collection<? extends E> coll,
Comparator<? super E> cmp)
{code}
Discussion on [email protected], 2026-07-28:
https://lists.apache.org/thread/jg95m5wqbqt1vgv8dnzg8h3qs448lo7d
--
This message was sent by Atlassian Jira
(v8.20.10#820010)