diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-12-26 21:14:33 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-12-26 21:14:33 -0800 |
commit | ffc8e8c2695d61e97fd7b69fb658f6cb1d8e13a2 (patch) | |
tree | f37aedb5b7493c143a634c2d4a6aca5e11c7ad8c /y.tab.h.shipped | |
parent | b4cdcb7e64573a849f21a61a1c0438ddb72fd54f (diff) | |
download | txr-ffc8e8c2695d61e97fd7b69fb658f6cb1d8e13a2.tar.gz txr-ffc8e8c2695d61e97fd7b69fb658f6cb1d8e13a2.tar.bz2 txr-ffc8e8c2695d61e97fd7b69fb658f6cb1d8e13a2.zip |
comb: bug: missing combinations.
The comb function is broken; some combinations of items
are missing in the output. This is because the iteration
reset step in comb_gen_fun_common handles only one
column of the state, neglecting to reset the other
columns: what is now done by the for (j = i ...
loop. I'm changing the representation of the state from
a list of lists to a vector of lists. Moreover, it is not
reversed. This allows the loop in comb_gen_fun_common
to perform random access.
* combi.c (k_conses): Return a vector, that is not
reversed.
(comb_init): New helper function to slightly abstract
the use of k_conses.
(comb_while_fun): Termination now occurs if the state
vector is nil (degenerate case, like k items chosen
from n, when k > n), or if the vector has nil in
element zero (special flag situation).
(comb_gen_fun_common): Rewritten, with correction.
The logic is similar. Since we have random access,
we don't need the "prev" variable. When we reset
a column iterator, we now also populate all the
columns to the right of it. For instance, if a
given column resets to (a b c), the one to the right
must reset to (b c), and so on. In the broken function,
this is what was not done, resulting in missing
items due to, say, a column resetting to (a b c)
but the one next to it remaining at (c).
(comb_list_gen_fun): Drop nreverse.
(comb_vec_gen_fun, comb_str_gen_fun, comb_hash_gen_fun):
Use the same i iterator for the state and the output object,
accessing the vector directly.
(comb_list, comb_vec, comb_str, comb_hash): Use comb_init.
* tests/015/comb.tl: New file.
Diffstat (limited to 'y.tab.h.shipped')
0 files changed, 0 insertions, 0 deletions