@@ -74,8 +74,11 @@ GetPerms (const Array<T>& ar_in, bool uniq_v = false)
74
74
// In practice, and because n must be very small, mutual comparison is
75
75
// typically faster and consumes less memory.
76
76
77
+ // Number of unique permutations is n! / (n_el1! * n_el2! * ...)
78
+ // where n_elX is the number of myvidx elements with value X.
77
79
for (octave_idx_type i = 0 ; i < m - 1 ; i++)
78
80
{
81
+ octave_idx_type count = 1 ;
79
82
for (octave_idx_type j = i + 1 ; j < m; j++)
80
83
{
81
84
bool isequal;
@@ -86,30 +89,15 @@ GetPerms (const Array<T>& ar_in, bool uniq_v = false)
86
89
isequal = (Ar[i] == Ar[j]);
87
90
88
91
if (myvidx[j] > myvidx[i] && isequal)
92
+ {
89
93
myvidx[j] = myvidx[i]; // not yet processed...
94
+ ++count;
95
+ }
90
96
}
97
+ nr /= Factorial (count);
91
98
}
92
99
93
100
// At this point, myvidx serves as a unique id of the elements.
94
- // Two elements having the same myvidx are equal.
95
-
96
- // Number of unique permutations is n! / (n_el1! * n_el2! * ...)
97
- // where n_elX is the number of myvidx elements with value X.
98
- // There can be no more than m different ids.
99
- octave_idx_type cumulative = 0 ;
100
- for (octave_idx_type i = 0 ; i < m; i++) // each possible id
101
- {
102
- octave_idx_type count = 0 ;
103
- for (octave_idx_type j = i; j < m; j++) // range for this id
104
- if (myvidx[j] == i)
105
- ++count;
106
-
107
- nr /= Factorial (count);
108
-
109
- cumulative += count;
110
- if (cumulative == m) // all elements accounted for, break early
111
- break ;
112
- }
113
101
}
114
102
115
103
// Sort vector indices for inverse lexicographic order later.
0 commit comments