summaryrefslogtreecommitdiffstats
path: root/tests/015/comb.tl
Commit message (Collapse)AuthorAgeFilesLines
* perm, rperm, comb, rcomb: test generic sequences, bugfixes.Kaz Kylheku2023-12-271-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | perm doesn't generate items of the right type. We need to add the original sequence to the state vector and use make_like. The new generic sequence support in rperm is broken, too. * combi.c (perm_while_fun, perm_gen_fun_common): Rename p variable to vec. (perm_init_common): Rename to perm_init. Take one more argument and store in new fourth element of state vector. (perm_vec, perm_list, perm_str): Pass nil to new parameter of perm_init. (perm_seq_gen_fun): Use perm_list_gen_fun to get list permutations, and coerce each one to the same type as the sequence with make_like. (rcomb_seq_gen_fun): Remove redundant call to rcomb_gen_fun_common. The rcomb_list_gen_fun function is called, which does this already, so we lose every other sequence element. * tests/015/comb.tl: New tests.
* rcomb, perm, rperm: test.Kaz Kylheku2023-12-271-0/+317
| | | | * tests/015/comb.tl: New tests.
* comb: bug: missing combinations.Kaz Kylheku2023-12-261-0/+116
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.