Fast IFS using RPN notation
python
c
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpn_if_mutate.c 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2020,2023 Weber Yann
  3. *
  4. * This file is part of pyrpn.
  5. *
  6. * pyrpn is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * pyrpn is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "rpn_if_mutate.h"
  20. int if_mutation(rpn_if_t *rif, rnd_t *weights, size_t n_mut,
  21. rpn_mutation_params_t *mut_params)
  22. {
  23. for(size_t i=0; i<n_mut; i++)
  24. {
  25. size_t rpn_num;
  26. if(_rpn_random_choice(rif->params->rpn_sz, weights,
  27. &rpn_num) < 0)
  28. {
  29. return -1;
  30. }
  31. if(rpn_mutation(&(rif->rpn[rpn_num].toks),
  32. mut_params) < 0)
  33. {
  34. return -1;
  35. }
  36. }
  37. for(size_t i=0; i<rif->params->rpn_sz; i++)
  38. {
  39. rpn_expr_tokens_updated(&(rif->rpn[i]));
  40. }
  41. return 0;
  42. }