From fd91d9766c0eeaa27568c4b0d33bab6a517ba543 Mon Sep 17 00:00:00 2001 From: Iman Abbasi Date: Mon, 20 Feb 2023 18:20:02 +0330 Subject: [PATCH] Update README.md for add calculateWithoutSave examples --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index d569c6a..88dae9f 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,15 @@ $permutation->setRepetitions(true); $permutation->calculate(); $result = $permutation->getPossibilities(); // [ ['a', 'a'], ['a', 'b'], ['b','a'], ['b','b'] ] $count = $permutation->countPossibilities(); // 4 + +// Permutation for huge dataset, for avoid memory leak +$permutation = new Permutation(); +$permutation->setItems(range(1,100)); // [1, 2, 3, ..., 100] +$permutation->setSelection(10); +$generator = $permutation->calculateWithoutSave(); +foreach ($generator as $possibility){ // // loop over Factorial(100) / Factorial(100 - 10) + print_r($possibility); // start from [1,2,3,4,5,6,7,8,9,10] to [100,99,98,97,96,95,94,93,92,91] +} ``` ### Combination @@ -94,6 +103,15 @@ $combination->setRepetitions(true); $combination->calculate(); $result = $combination->getPossibilities(); // [ ['a', 'a'], ['a', 'b'], ['b','b'] ] $count = $combination->countPossibilities(); // 3 + +// Combination for huge dataset, for avoid memory leak +$combination = new Combination(); +$combination->setItems(range(1,100)); // [1, 2, 3, ..., 100] +$combination->setSelection(10); +$generator = $combination->calculateWithoutSave(); +foreach ($generator as $possibility){ // loop over Factorial(100) / ( Factorial(100 - 10) * Factorial(10) ) + print_r($possibility); // start from [1,2,3,4,5,6,7,8,9,10] to [100,99,98,97,96,95,94,93,92,91] +} ``` ## License