YashasSamaga

Untitled

Feb 8th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 63.24 KB | None | 0 0
  1. //native bool:ibsearch(key, array[], &idx, size = sizeof(array));
  2.     cell AMX_NATIVE_CALL algo_ibsearch(AMX* amx, cell* params)
  3.     {
  4.         error_if(!check_params(4), "[PLE] algorithm>> ibsearch: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  5.  
  6.         cell key = params[1];
  7.  
  8.         cell* arr = NULL;
  9.         amx_GetAddr(amx, params[2], &arr);
  10.  
  11.         cell* idx_addr = NULL;
  12.         amx_GetAddr(amx, params[3], &idx_addr);
  13.  
  14.         size_t size = params[4];
  15.         error_if(size < 0, "[PLE] algorithm>> ibsearch: 'size' paramter (%d) below zero", size);
  16.  
  17.         int low = 0, high = size - 1, mid = 0;
  18.         while (low <= high)
  19.         {
  20.             mid = low + (high - low) / 2;
  21.  
  22.             if (arr[mid] > key)
  23.                 high = mid - 1;
  24.             else if (arr[mid] < key)
  25.                 low = mid + 1;
  26.             else
  27.             {
  28.                 *idx_addr = mid;
  29.                 return true;
  30.             }
  31.         }
  32.         return false;
  33.     }
  34.     //native bool:fbsearch(Float:key, Float:array[], &idx, Float:error = 0.01, size = sizeof(array));
  35.     cell AMX_NATIVE_CALL algo_fbsearch(AMX* amx, cell* params)
  36.     {
  37.         error_if(!check_params(5), "[PLE] algorithm>> fbsearch: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  38.  
  39.         float key = amx_ctof(params[1]);
  40.  
  41.         cell* arr = NULL;
  42.         amx_GetAddr(amx, params[2], &arr);
  43.  
  44.         cell* idx_addr = NULL;
  45.         amx_GetAddr(amx, params[3], &idx_addr);
  46.  
  47.         float error = amx_ctof(params[4]);
  48.         error_if(error < 0.0, "[PLE] algorithm>> fbsearch: 'error' paramter (%f) below zero", error);
  49.  
  50.         float key_lower = key - error;
  51.         float key_upper = key + error;
  52.  
  53.         size_t size = params[5];
  54.         error_if(size < 0, "[PLE] algorithm>> fbsearch: 'size' paramter (%d) below zero", size);
  55.  
  56.         int low = 0, high = size - 1, mid = 0;
  57.         while (low <= high)
  58.         {
  59.             mid = low + (high - low) / 2;
  60.  
  61.             if (key_lower < amx_ctof(arr[mid]) && key_upper > amx_ctof(arr[mid]))
  62.             {
  63.                 *idx_addr = mid;
  64.                 return true;
  65.             }
  66.             else if (amx_ctof(arr[mid]) > key)
  67.                 high = mid - 1;
  68.             else
  69.                 low = mid + 1;
  70.         }
  71.         return false;
  72.     }
  73.     //native bool:sbsearch(search[], source[][], &idx, size_major = sizeof(source), size_minor = sizeof(source[]));
  74.     cell AMX_NATIVE_CALL algo_sbsearch(AMX* amx, cell* params)
  75.     {
  76.         error_if(!check_params(5), "[PLE] algorithm>> sbsearch: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  77.  
  78.         cell* search_str = NULL;
  79.         amx_GetAddr(amx, params[1], &search_str);
  80.  
  81.         cell* source_arr = NULL;
  82.         amx_GetAddr(amx, params[2], &source_arr);
  83.  
  84.         cell* idx = NULL;
  85.         amx_GetAddr(amx, params[3], &idx);
  86.  
  87.         size_t size_major = static_cast<size_t>(params[4]);
  88.         error_if(size_major < 0, "[PLE] algorithm>> sbsearch: 'size_major' paramter (%d) below zero", size_major);
  89.  
  90.         size_t size_minor = static_cast<size_t>(params[5]);
  91.         error_if(size_minor < 0, "[PLE] algorithm>> sbsearch: 'size_minor' paramter (%d) below zero", size_minor);
  92.  
  93.         source_arr += size_major - size_minor;
  94.  
  95.         int first = 0, last = size_major - 1, mid, result;
  96.         while (first <= last)
  97.         {
  98.             mid = (first + last) / 2;
  99.  
  100.             cell *str = source_arr + mid*size_minor;
  101.  
  102.             result = strcmp4b(str, search_str);
  103.  
  104.             if (result > 0)
  105.                 last = mid - 1;
  106.             else if (result < 0)
  107.                 first = mid + 1;
  108.             else
  109.             {
  110.                 *idx = mid - 1;
  111.                 return true;
  112.             }
  113.         }
  114.         return false;
  115.     }
  116.  
  117.     //native bool:all_of(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  118.     cell AMX_NATIVE_CALL algo_all_of(AMX* amx, cell* params)
  119.     {
  120.         error_if(!check_params(3), "[PLE] algorithm>> all_of: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  121.  
  122.         cell* start = NULL;
  123.         amx_GetAddr(amx, params[1], &start);
  124.  
  125.         cell* end = start + params[2];
  126.         error_if(end < start, "[PLE] algorithm>> all_of: 'numcells' paramter (%d) below zero", params[2]);
  127.  
  128.         cell* func = NULL;
  129.         amx_GetAddr(amx, params[3], &func);
  130.         functionID fid(func);
  131.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> all_of: function object 'func' is not valid");
  132.  
  133.         while (start != end)
  134.         {
  135.             if (!ExecuteFunctionCC1O2(amx, &fid, *start)) return false;
  136.             start++;
  137.         }
  138.         return true;
  139.     }
  140.     //native bool:any_of(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  141.     cell AMX_NATIVE_CALL algo_any_of(AMX* amx, cell* params)
  142.     {
  143.         error_if(!check_params(3), "[PLE] algorithm>> any_of: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  144.  
  145.         cell* start = NULL;
  146.         amx_GetAddr(amx, params[1], &start);
  147.  
  148.         cell* end = start + params[2];
  149.         error_if(end < start, "[PLE] algorithm>> any_of: 'numcells' paramter (%d) below zero", params[2]);
  150.  
  151.         cell* func = NULL;
  152.         amx_GetAddr(amx, params[3], &func);
  153.         functionID fid(func);
  154.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> any_of: function object 'func' is not valid");
  155.  
  156.         while (start != end)
  157.         {
  158.             if (ExecuteFunctionCC1O2(amx, &fid, *start)) return true;
  159.             start++;
  160.         }
  161.         return false;
  162.     }
  163.     //native bool:none_of(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  164.     cell AMX_NATIVE_CALL algo_none_of(AMX* amx, cell* params)
  165.     {
  166.         error_if(!check_params(3), "[PLE] algorithm>> none_of: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  167.  
  168.         cell* start = NULL;
  169.         amx_GetAddr(amx, params[1], &start);
  170.  
  171.         cell* end = start + params[2];
  172.         error_if(end < start, "[PLE] algorithm>> none_of: 'numcells' paramter (%d) below zero", params[2]);
  173.  
  174.         cell* func = NULL;
  175.         amx_GetAddr(amx, params[3], &func);
  176.         functionID fid(func);
  177.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> none_of: function object 'func' is not valid");
  178.  
  179.         while (start != end)
  180.         {
  181.             if (ExecuteFunctionCC1O2(amx, &fid, *start)) return false;
  182.             start++;
  183.         }
  184.         return true;
  185.     }
  186.     //native noret:for_each(range[], numcells, func[FTSIZE]);
  187.     cell AMX_NATIVE_CALL algo_for_each(AMX* amx, cell* params)
  188.     {
  189.         error_if(!check_params(3), "[PLE] algorithm>> for_each: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  190.  
  191.         cell* start = NULL;
  192.         amx_GetAddr(amx, params[1], &start);
  193.  
  194.         cell* end = start + params[2];
  195.         error_if(end < start, "[PLE] algorithm>> for_each: 'numcells' paramter (%d) below zero", params[2]);
  196.  
  197.         cell* func = NULL;
  198.         amx_GetAddr(amx, params[3], &func);
  199.         functionID fid(func);
  200.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> for_each: function object 'func' is not valid");
  201.  
  202.         while (start != end)
  203.         {
  204.             ExecuteFunctionCC1O2(amx, &fid, *start);
  205.             start++;
  206.         }
  207.         return true;
  208.     }
  209.     //native find(range[], numcells, search_value);
  210.     cell AMX_NATIVE_CALL algo_find(AMX* amx, cell* params)
  211.     {
  212.         error_if(!check_params(3), "[PLE] algorithm>> find: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  213.  
  214.         cell* start = NULL;
  215.         amx_GetAddr(amx, params[1], &start);
  216.  
  217.         cell* end = start + params[2];
  218.         error_if(end < start, "[PLE] algorithm>> find: 'numcells' paramter (%d) below zero", params[2]);
  219.  
  220.         cell value = params[3];
  221.  
  222.         cell* pos = start;
  223.         while (pos != end)
  224.         {
  225.             if (*pos == value) return pos - start;
  226.             pos++;
  227.         }
  228.         return params[2];
  229.     }
  230.     //native find_if(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  231.     cell AMX_NATIVE_CALL algo_find_if(AMX* amx, cell* params)
  232.     {
  233.         error_if(!check_params(3), "[PLE] algorithm>> find_if: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  234.  
  235.         cell* start = NULL;
  236.         amx_GetAddr(amx, params[1], &start);
  237.  
  238.         cell* end = start + params[2];
  239.         error_if(end < start, "[PLE] algorithm>> find_if: 'numcells' paramter (%d) below zero", params[2]);
  240.  
  241.         cell* func = NULL;
  242.         amx_GetAddr(amx, params[3], &func);
  243.         functionID fid(func);
  244.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> find_if: function object 'func' is not valid");
  245.  
  246.         cell *pos = start;
  247.         while (pos != end)
  248.         {
  249.             if (ExecuteFunctionCC1O2(amx, &fid, *pos)) return pos - start;
  250.             pos++;
  251.         }
  252.         return params[2];
  253.     }
  254.     //native find_if_not(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  255.     cell AMX_NATIVE_CALL algo_find_if_not(AMX* amx, cell* params)
  256.     {
  257.         error_if(!check_params(3), "[PLE] algorithm>> find_if_not: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  258.  
  259.         cell* start = NULL;
  260.         amx_GetAddr(amx, params[1], &start);
  261.  
  262.         cell* end = start + params[2];
  263.         error_if(end < start, "[PLE] algorithm>> find_if_not: 'numcells' paramter (%d) below zero", params[2]);
  264.  
  265.         cell* func = NULL;
  266.         amx_GetAddr(amx, params[3], &func);
  267.         functionID fid(func);
  268.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> find_if_not: function object 'func' is not valid");
  269.  
  270.         cell *pos = start;
  271.         while (pos != end)
  272.         {
  273.             if (!ExecuteFunctionCC1O2(amx, &fid, *pos)) return pos - start;
  274.             pos++;
  275.         }
  276.         return false;
  277.     }
  278.     //native find_end(range1[], numcells1, range2[], numcells2, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  279.     cell AMX_NATIVE_CALL algo_find_end(AMX* amx, cell* params)
  280.     {
  281.         error_if(!check_params(5), "[PLE] algorithm>> find_end: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  282.  
  283.         cell* start1 = NULL;
  284.         amx_GetAddr(amx, params[1], &start1);
  285.         cell* end1 = start1 + params[2];
  286.         error_if(end1 < start1, "[PLE] algorithm>> find_end: 'numcells1' paramter (%d) below zero", params[2]);
  287.  
  288.         cell* start2 = NULL;
  289.         amx_GetAddr(amx, params[3], &start2);
  290.         cell* end2 = start2 + params[4];
  291.         error_if(end2 < start2, "[PLE] algorithm>> find_end: 'numcells2' paramter (%d) below zero", params[4]);
  292.  
  293.         cell* func = NULL;
  294.         amx_GetAddr(amx, params[5], &func);
  295.         functionID fid(func);
  296.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> find_end: function object 'func' is not valid");
  297.  
  298.         if (start2 == end2) return params[2];
  299.  
  300.         cell *ret = end1, *pos1 = start1;
  301.         while (pos1 != end1)
  302.         {
  303.             cell *it1 = pos1, *it2 = start2;
  304.             while (ExecuteFunctionCC1C2(amx, &fid, *it1, *it2))
  305.             {
  306.                 it1++;
  307.                 it2++;
  308.                 if (it2 == end2)
  309.                 {
  310.                     ret = pos1;
  311.                     break;
  312.                 }
  313.                 if (it1 == end1) return ret - start1;
  314.             }
  315.             pos1++;
  316.         }
  317.         return ret - start1;
  318.     }
  319.     //native find_first_of(range1[], numcells1, range2[], numcells2, {func_bool2, func_cell2, _}:func[FTSIZE]) = fixed_functions::equal_to;
  320.     cell AMX_NATIVE_CALL algo_find_first_of(AMX* amx, cell* params)
  321.     {
  322.         error_if(!check_params(5), "[PLE] algorithm>> find_first_of: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  323.  
  324.         cell* start1 = NULL;
  325.         amx_GetAddr(amx, params[1], &start1);
  326.         cell* end1 = start1 + params[2];
  327.         error_if(end1 < start1, "[PLE] algorithm>> find_first_of: 'numcells1' paramter (%d) below zero", params[2]);
  328.  
  329.         cell* start2 = NULL;
  330.         amx_GetAddr(amx, params[3], &start2);
  331.         cell* end2 = start2 + params[4];
  332.         error_if(end2 < start2, "[PLE] algorithm>> find_first_of: 'numcells2' paramter (%d) below zero", params[4]);
  333.  
  334.         cell* func = NULL;
  335.         amx_GetAddr(amx, params[5], &func);
  336.         functionID fid(func);
  337.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> find_first_of: function object 'func' is not valid");
  338.  
  339.         if (start2 == end2) return params[2];
  340.  
  341.         cell *pos = start1;
  342.         while (pos != end1)
  343.         {
  344.             for (cell* it = start2; it != end2; ++it)
  345.             {
  346.                 if (ExecuteFunctionCC1C2(amx, &fid, *it, *pos))
  347.                     return pos - start1;
  348.             }
  349.             pos++;
  350.         }
  351.         return params[2];
  352.     }
  353.     //native adjacent_find(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  354.     cell AMX_NATIVE_CALL algo_adjacent_find(AMX* amx, cell* params)
  355.     {
  356.         error_if(!check_params(3), "[PLE] algorithm>> adjacent_find: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  357.  
  358.         cell* start = NULL;
  359.         amx_GetAddr(amx, params[1], &start);
  360.         cell* end = start + params[2];
  361.         error_if(end < start, "[PLE] algorithm>> adjacent_find: 'numcells' paramter (%d) below zero", params[2]);
  362.  
  363.         cell* func = NULL;
  364.         amx_GetAddr(amx, params[3], &func);
  365.         functionID fid(func);
  366.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> adjacent_find: function object 'func' is not valid");
  367.  
  368.         cell* pos = start;
  369.         if (pos != end)
  370.         {
  371.             cell *next = pos + 1;
  372.             while (next != end)
  373.             {
  374.                 if (ExecuteFunctionCC1C2(amx, &fid, *pos, *next))
  375.                     return pos - start;
  376.                 ++pos;
  377.                 ++next;
  378.             }
  379.         }
  380.         return params[2];
  381.     }
  382.     //native count(range[], numcells, value);
  383.     cell AMX_NATIVE_CALL algo_count(AMX* amx, cell* params)
  384.     {
  385.         error_if(!check_params(3), "[PLE] algorithm>> count: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  386.  
  387.         cell* start = NULL;
  388.         amx_GetAddr(amx, params[1], &start);
  389.         cell* end = start + params[2];
  390.         error_if(end < start, "[PLE] algorithm>> count: 'numcells' paramter (%d) below zero", params[2]);
  391.  
  392.         cell value = params[3];
  393.  
  394.         int count = 0;
  395.         while (start != end)
  396.             if (*start++ == value) count++;
  397.  
  398.         return count;
  399.     }
  400.     //native count_if(range[], numcells, { func_bool1, func_cell1, _ }:func[FTSIZE]);
  401.     cell AMX_NATIVE_CALL algo_count_if(AMX* amx, cell* params)
  402.     {
  403.         error_if(!check_params(3), "[PLE] algorithm>> count_if: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  404.  
  405.         cell* start = NULL;
  406.         amx_GetAddr(amx, params[1], &start);
  407.         cell* end = start + params[2];
  408.         error_if(end < start, "[PLE] algorithm>> count_if: 'numcells' paramter (%d) below zero", params[2]);
  409.  
  410.         cell* func = NULL;
  411.         amx_GetAddr(amx, params[3], &func);
  412.         functionID fid(func);
  413.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> count_if: function object 'func' is not valid");
  414.  
  415.         int count = 0;
  416.         while (start != end)
  417.         {
  418.             if (ExecuteFunctionCC1O2(amx, &fid, *start)) count++;
  419.             start++;
  420.         }
  421.         return count;
  422.     }
  423.     //native mismatch(range1[], numcells1, range2[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  424.     cell AMX_NATIVE_CALL algo_mismatch(AMX* amx, cell* params)
  425.     {
  426.         error_if(!check_params(4), "[PLE] algorithm>> mismatch: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  427.  
  428.         cell* start1 = NULL;
  429.         amx_GetAddr(amx, params[1], &start1);
  430.         cell* end1 = start1 + params[2];
  431.         error_if(end1 < start1, "[PLE] algorithm>> mismatch: 'numcells1' paramter (%d) below zero", params[2]);
  432.  
  433.         cell* start2 = NULL;
  434.         amx_GetAddr(amx, params[3], &start2);
  435.  
  436.         cell* func = NULL;
  437.         amx_GetAddr(amx, params[4], &func);
  438.         functionID fid(func);
  439.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> mismatch: function object 'func' is not valid");
  440.  
  441.         cell *pos1 = start1, *pos2 = start2;
  442.         while ((pos1 != end1) && ExecuteFunctionCC1C2(amx, &fid, *pos1, *pos2))
  443.         {
  444.             ++pos1;
  445.             ++pos2;
  446.         }
  447.         return pos1 - start1;
  448.     }
  449.     //native bool:equal(range1[], numcells1, range2[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  450.     cell AMX_NATIVE_CALL algo_equal(AMX* amx, cell* params)
  451.     {
  452.         error_if(!check_params(4), "[PLE] algorithm>> equal: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  453.  
  454.         cell* start1 = NULL;
  455.         amx_GetAddr(amx, params[1], &start1);
  456.         cell* end1 = start1 + params[2];
  457.         error_if(end1 < start1, "[PLE] algorithm>> equal: 'numcells1' paramter (%d) below zero", params[2]);
  458.  
  459.         cell* start2 = NULL;
  460.         amx_GetAddr(amx, params[3], &start2);
  461.  
  462.         cell* func = NULL;
  463.         amx_GetAddr(amx, params[4], &func);
  464.         functionID fid(func);
  465.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> equal: function object 'func' is not valid");
  466.  
  467.         cell *pos1 = start1, *pos2 = start2;
  468.         while (pos1 != end1)
  469.         {
  470.             if (!ExecuteFunctionCC1C2(amx, &fid, *pos1, *pos2)) return false;
  471.             ++pos1;
  472.             ++pos2;
  473.         }
  474.         return true;
  475.     }
  476.     //native bool:is_permutation(range1[], numcells1, range2[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  477.     cell AMX_NATIVE_CALL algo_is_permutation(AMX* amx, cell* params)
  478.     {
  479.         error_if(!check_params(4), "[PLE] algorithm>> is_permutation: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  480.  
  481.         cell* start1 = NULL;
  482.         amx_GetAddr(amx, params[1], &start1);
  483.         cell* end1 = start1 + params[2];
  484.         error_if(end1 < start1, "[PLE] algorithm>> is_permutation: 'numcells1' paramter (%d) below zero", params[2]);
  485.  
  486.         cell* start2 = NULL;
  487.         amx_GetAddr(amx, params[3], &start2);
  488.  
  489.         cell* func = NULL;
  490.         amx_GetAddr(amx, params[4], &func);
  491.         functionID fid(func);
  492.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> is_permutation: function object 'func' is not valid");
  493.  
  494.         return std::is_permutation(start1, end1, start2, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  495.     }
  496.     //native search(range1[], numcells1, range2[], numcells2, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  497.     cell AMX_NATIVE_CALL algo_search(AMX* amx, cell* params)
  498.     {
  499.         error_if(!check_params(5), "[PLE] algorithm>> search: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  500.  
  501.         cell* start1 = NULL;
  502.         amx_GetAddr(amx, params[1], &start1);
  503.         cell* end1 = start1 + params[2];
  504.         error_if(end1 < start1, "[PLE] algorithm>> search: 'numcells1' paramter (%d) below zero", params[2]);
  505.  
  506.         cell* start2 = NULL;
  507.         amx_GetAddr(amx, params[3], &start2);
  508.         cell* end2 = start2 + params[4];
  509.         error_if(end2 < start2, "[PLE] algorithm>> search: 'numcells2' paramter (%d) below zero", params[4]);
  510.  
  511.         cell* func = NULL;
  512.         amx_GetAddr(amx, params[5], &func);
  513.         functionID fid(func);
  514.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> search: function object 'func' is not valid");
  515.  
  516.         return std::search(start1, end1, start2, end2, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - start1;
  517.     }
  518.     //native search_n(range[], numcells, n, value, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  519.     cell AMX_NATIVE_CALL algo_search_n(AMX* amx, cell* params)
  520.     {
  521.         error_if(!check_params(5), "[PLE] algorithm>> search_n: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  522.  
  523.         cell* start = NULL;
  524.         amx_GetAddr(amx, params[1], &start);
  525.         cell* end = start + params[2];
  526.         error_if(end < start, "[PLE] algorithm>> search_n: 'numcells' paramter (%d) below zero", params[2]);
  527.  
  528.         cell n = params[3];
  529.         error_if(n < 0, "[PLE] algorithm>> search_n: 'n' paramter (%d) below zero", n);
  530.  
  531.         cell val = params[4];
  532.  
  533.         cell* func = NULL;
  534.         amx_GetAddr(amx, params[5], &func);
  535.         functionID fid(func);
  536.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> search_n: function object 'func' is not valid");
  537.  
  538.         return std::search_n(start, end, n, val, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - start;
  539.     }
  540.  
  541.     //native noret:copy(source[], numcells, dest[]);
  542.     cell AMX_NATIVE_CALL algo_copy(AMX* amx, cell* params)
  543.     {
  544.         error_if(!check_params(3), "[PLE] algorithm>> copy: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  545.  
  546.         cell* start1 = NULL;
  547.         amx_GetAddr(amx, params[1], &start1);
  548.         cell* end1 = start1 + params[2];
  549.         error_if(end1 < start1, "[PLE] algorithm>> copy: 'numcells' paramter (%d) below zero", params[2]);
  550.  
  551.         cell* start2 = NULL;
  552.         amx_GetAddr(amx, params[3], &start2);
  553.        
  554.         std::copy(start1, end1, start2);
  555.         return true;
  556.     }
  557.     //native noret:copy_if(source[], numcells, dest[], {func_bool1, func_cell1, _}:func[FTSIZE]);
  558.     cell AMX_NATIVE_CALL algo_copy_if(AMX* amx, cell* params)
  559.     {
  560.         error_if(!check_params(4), "[PLE] algorithm>> copy_if: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  561.  
  562.         cell* start1 = NULL;
  563.         amx_GetAddr(amx, params[1], &start1);
  564.         cell* end1 = start1 + params[2];
  565.         error_if(end1 < start1, "[PLE] algorithm>> copy_if: 'numcells' paramter (%d) below zero", params[2]);
  566.  
  567.         cell* start2 = NULL;
  568.         amx_GetAddr(amx, params[3], &start2);
  569.  
  570.         cell* func = NULL;
  571.         amx_GetAddr(amx, params[4], &func);
  572.         functionID fid(func);
  573.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> copy_if: function object 'func' is not valid");
  574.  
  575.         std::copy_if(start1, end1, start2, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x);  });
  576.         return true;
  577.     }
  578.     //native noret:copy_backward(source[], numcells, dest_end[]);
  579.     cell AMX_NATIVE_CALL algo_copy_backward(AMX* amx, cell* params)
  580.     {
  581.         error_if(!check_params(3), "[PLE] algorithm>> copy_backward: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  582.  
  583.         cell* start1 = NULL;
  584.         amx_GetAddr(amx, params[1], &start1);
  585.         cell* end1 = start1 + params[2];
  586.         error_if(end1 < start1, "[PLE] algorithm>> copy_backward: 'numcells' paramter (%d) below zero", params[2]);
  587.  
  588.         cell* end2 = NULL;
  589.         amx_GetAddr(amx, params[3], &end2);
  590.  
  591.         std::copy_backward(start1, end1, end2 + 1);
  592.         return true;
  593.     }
  594.  
  595.     //native noret:swap(&val1, &val2);
  596.     cell AMX_NATIVE_CALL algo_swap(AMX* amx, cell* params)
  597.     {
  598.         error_if(!check_params(2), "[PLE] algorithm>> swap: expected 2 parameters but found %d parameters.", params[0] / sizeof(cell));
  599.  
  600.         cell* val1 = NULL;
  601.         amx_GetAddr(amx, params[1], &val1);
  602.  
  603.         cell* val2 = NULL;
  604.         amx_GetAddr(amx, params[2], &val2);
  605.  
  606.         cell tmp = *val1;
  607.         *val1 = *val2;
  608.         *val2 = tmp;
  609.         return true;
  610.     }
  611.     //native noret:swap_ranges(range1[], numcells1, range2[]);
  612.     cell AMX_NATIVE_CALL algo_swap_ranges(AMX* amx, cell* params)
  613.     {
  614.         error_if(!check_params(3), "[PLE] algorithm>> swap_ranges: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  615.  
  616.         cell* start1 = NULL;
  617.         amx_GetAddr(amx, params[1], &start1);
  618.         cell* end1 = start1 + params[2];
  619.         error_if(end1 < start1, "[PLE] algorithm>> swap_ranges: 'numcells1' paramter (%d) below zero", params[2]);
  620.  
  621.         cell* start2 = NULL;
  622.         amx_GetAddr(amx, params[3], &start2);
  623.  
  624.         std::swap_ranges(start1, end1, start2);
  625.         return true;
  626.     }
  627.     //native noret:transform(range[], numcells, dest[], {func_bool1, func_cell1, _}:func[FTSIZE]);
  628.     cell AMX_NATIVE_CALL algo_transform(AMX* amx, cell* params)
  629.     {
  630.         error_if(!check_params(4), "[PLE] algorithm>> transform: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  631.  
  632.         cell* start1 = NULL;
  633.         amx_GetAddr(amx, params[1], &start1);
  634.         cell* end1 = start1 + params[2];
  635.         error_if(end1 < start1, "[PLE] algorithm>> transform: 'numcells' paramter (%d) below zero", params[2]);
  636.  
  637.         cell* start2 = NULL;
  638.         amx_GetAddr(amx, params[3], &start2);
  639.  
  640.         cell* func = NULL;
  641.         amx_GetAddr(amx, params[4], &func);
  642.         functionID fid(func);
  643.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> transform: function object 'func' is not valid");
  644.  
  645.         cell* pos1 = start1, *pos2 = start2;
  646.         while (pos1 != end1)
  647.         {
  648.             *pos2 = ExecuteFunctionCC1O2(amx, &fid, *pos1);
  649.             ++pos2;
  650.             ++pos1;
  651.         }
  652.         return true;
  653.     }
  654.     //native noret:transform2(range1[], numcells1, range2[], dest[], {func_bool2, func_cell2, _}:func[FTSIZE]);
  655.     cell AMX_NATIVE_CALL algo_transform2(AMX* amx, cell* params)
  656.     {
  657.         error_if(!check_params(5), "[PLE] algorithm>> transform2: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  658.  
  659.         cell* start1 = NULL;
  660.         amx_GetAddr(amx, params[1], &start1);
  661.         cell* end1 = start1 + params[2];
  662.         error_if(end1 < start1, "[PLE] algorithm>> transform2: 'numcells1' paramter (%d) below zero", params[2]);
  663.  
  664.         cell* start2 = NULL;
  665.         amx_GetAddr(amx, params[3], &start2);
  666.  
  667.         cell* start3 = NULL;
  668.         amx_GetAddr(amx, params[4], &start3);
  669.  
  670.         cell* func = NULL;
  671.         amx_GetAddr(amx, params[5], &func);
  672.         functionID fid(func);
  673.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> transform2: function object 'func' is not valid");
  674.  
  675.         cell* pos1 = start1, *pos2 = start2, *pos3 = start3;
  676.         while (pos1 != end1)
  677.         {
  678.             *pos3 = ExecuteFunctionCC1C2(amx, &fid, *pos1, *pos2);
  679.             ++pos3;
  680.             ++pos2;
  681.             ++pos1;
  682.         }
  683.         return true;
  684.     }
  685.     //native replace(range[], numcells, search_value, replace_value);
  686.     cell AMX_NATIVE_CALL algo_replace(AMX* amx, cell* params)
  687.     {
  688.         error_if(!check_params(4), "[PLE] algorithm>> replace: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  689.  
  690.         cell* start = NULL;
  691.         amx_GetAddr(amx, params[1], &start);
  692.         cell* end = start + params[2];
  693.         error_if(end < start, "[PLE] algorithm>> replace: 'numcells' paramter (%d) below zero", params[2]);
  694.  
  695.         cell search_value = params[3];
  696.         cell replace_value = params[4];
  697.  
  698.         int count = 0;
  699.         while (start != end)
  700.         {
  701.             if (*start == search_value)
  702.             {
  703.                 *start = replace_value;
  704.                 count++;
  705.             }
  706.             start++;
  707.         }
  708.         return count;
  709.     }
  710.     //native replace_if(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE], replace_value);
  711.     cell AMX_NATIVE_CALL algo_replace_if(AMX* amx, cell* params)
  712.     {
  713.         error_if(!check_params(4), "[PLE] algorithm>> replace_if: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  714.  
  715.         cell* start = NULL;
  716.         amx_GetAddr(amx, params[1], &start);
  717.         cell* end = start + params[2];
  718.         error_if(end < start, "[PLE] algorithm>> replace_if: 'numcells' paramter (%d) below zero", params[2]);
  719.  
  720.         cell* func = NULL;
  721.         amx_GetAddr(amx, params[3], &func);
  722.         functionID fid(func);
  723.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> replace_if: function object 'func' is not valid");
  724.  
  725.         cell replace_value = params[4];
  726.  
  727.         int count = 0;
  728.         while (start != end)
  729.         {
  730.             if (ExecuteFunctionCC1O2(amx, &fid, *start))
  731.             {
  732.                 *start = replace_value;
  733.                 count++;
  734.             }
  735.             start++;
  736.         }
  737.         return count;
  738.     }
  739.     //native replace_copy(range[], numcells, dest[], search_value, replace_value);
  740.     cell AMX_NATIVE_CALL algo_replace_copy(AMX* amx, cell* params)
  741.     {
  742.         error_if(!check_params(5), "[PLE] algorithm>> replace_copy: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  743.  
  744.         cell* start1 = NULL;
  745.         amx_GetAddr(amx, params[1], &start1);
  746.         cell* end1 = start1 + params[2];
  747.         error_if(end1 < start1, "[PLE] algorithm>> replace_copy: 'numcells' paramter (%d) below zero", params[2]);
  748.  
  749.         cell* start2 = NULL;
  750.         amx_GetAddr(amx, params[3], &start2);
  751.  
  752.         cell search_value = params[4];
  753.         cell replace_value = params[5];
  754.  
  755.         int count = 0;
  756.         cell* pos1 = start1, *pos2 = start2;
  757.         while (pos1 != end1)
  758.         {
  759.             if (*pos1 == search_value)
  760.             {
  761.                 *pos2 = replace_value;
  762.                 count++;
  763.             }
  764.             else *pos2 = *pos1;
  765.            
  766.             pos1++;
  767.             pos2++;
  768.         }
  769.         return count;
  770.     }
  771.     //native replace_copy_if(range[], numcells, dest[], {func_bool1, func_cell1, _}:func[FTSIZE], replace_value);
  772.     cell AMX_NATIVE_CALL algo_replace_copy_if(AMX* amx, cell* params)
  773.     {
  774.         error_if(!check_params(5), "[PLE] algorithm>> replace_copy_if: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  775.  
  776.         cell* start1 = NULL;
  777.         amx_GetAddr(amx, params[1], &start1);
  778.         cell* end1 = start1 + params[2];
  779.         error_if(end1 < start1, "[PLE] algorithm>> replace_copy_if: 'numcells' paramter (%d) below zero", params[2]);
  780.  
  781.         cell* start2 = NULL;
  782.         amx_GetAddr(amx, params[3], &start2);
  783.  
  784.         cell* func = NULL;
  785.         amx_GetAddr(amx, params[4], &func);
  786.         functionID fid(func);
  787.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> copy_if: function object 'func' is not valid");
  788.  
  789.         cell replace_value = params[5];
  790.  
  791.         int count = 0;
  792.         cell* pos1 = start1, *pos2 = start2;
  793.         while (pos1 != end1)
  794.         {
  795.             if (ExecuteFunctionCC1O2(amx, &fid, *pos1))
  796.             {
  797.                 *pos2 = replace_value;
  798.                 count++;
  799.             }
  800.             else *pos2 = *pos1;
  801.  
  802.             pos1++;
  803.             pos2++;
  804.         }
  805.         return count;
  806.     }
  807.     //native notret:fill(range[], numcells, value);
  808.     cell AMX_NATIVE_CALL algo_fill(AMX* amx, cell* params)
  809.     {
  810.         error_if(!check_params(3), "[PLE] algorithm>> fill: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  811.  
  812.         cell* start = NULL;
  813.         amx_GetAddr(amx, params[1], &start);
  814.         cell* end = start + params[2];
  815.         error_if(end < start, "[PLE] algorithm>> fill: 'numcells' paramter (%d) below zero", params[2]);
  816.  
  817.         cell fill_value = params[3];
  818.  
  819.         while (start != end)
  820.         {
  821.             *start = fill_value;
  822.             start++;
  823.         }
  824.         return true;
  825.     }
  826.     //fill_n = fill
  827.     //native noret:generate(range[], numcells, {func_bool0, func_cell0, _}:func[FTSIZE]);
  828.     cell AMX_NATIVE_CALL algo_generate(AMX* amx, cell* params)
  829.     {
  830.         error_if(!check_params(3), "[PLE] algorithm>> generate: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  831.  
  832.         cell* start = NULL;
  833.         amx_GetAddr(amx, params[1], &start);
  834.         cell* end = start + params[2];
  835.         error_if(end < start, "[PLE] algorithm>> generate: 'numcells' paramter (%d) below zero", params[2]);
  836.  
  837.         cell* func = NULL;
  838.         amx_GetAddr(amx, params[3], &func);
  839.         functionID fid(func);
  840.         error_if(!fid.IsFunctionValid(0), "[PLE] algorithm>> generate: function object 'func' is not valid");
  841.  
  842.         while (start != end)
  843.         {
  844.             *start = ExecuteFunctionCO1O2(amx, &fid);
  845.             start++;
  846.         }
  847.         return true;
  848.     }
  849.     //generate_n = generate
  850.     //native remove(range[], numcells, value);
  851.     cell AMX_NATIVE_CALL algo_remove(AMX* amx, cell* params)
  852.     {
  853.         error_if(!check_params(3), "[PLE] algorithm>> remove: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  854.  
  855.         cell* start = NULL;
  856.         amx_GetAddr(amx, params[1], &start);
  857.         cell* end = start + params[2];
  858.         error_if(end < start, "[PLE] algorithm>> remove: 'numcells' paramter (%d) below zero", params[2]);
  859.  
  860.         cell value = params[3];
  861.  
  862.         return std::remove(start, end, value) - start;
  863.     }
  864.     //native remove_if(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  865.     cell AMX_NATIVE_CALL algo_remove_if(AMX* amx, cell* params)
  866.     {
  867.         error_if(!check_params(3), "[PLE] algorithm>> remove_if: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  868.  
  869.         cell* start = NULL;
  870.         amx_GetAddr(amx, params[1], &start);
  871.         cell* end = start + params[2];
  872.         error_if(end < start, "[PLE] algorithm>> remove_if: 'numcells' paramter (%d) below zero", params[2]);
  873.  
  874.         cell* func = NULL;
  875.         amx_GetAddr(amx, params[3], &func);
  876.         functionID fid(func);
  877.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> remove_if: function object 'func' is not valid");
  878.  
  879.         return std::remove_if(start, end, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); }) - start;
  880.     }
  881.     //native remove_copy(range[], numcells, dest[], value);
  882.     cell AMX_NATIVE_CALL algo_remove_copy(AMX* amx, cell* params)
  883.     {
  884.         error_if(!check_params(4), "[PLE] algorithm>> remove_copy: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  885.  
  886.         cell* start1 = NULL;
  887.         amx_GetAddr(amx, params[1], &start1);
  888.         cell* end1 = start1 + params[2];
  889.         error_if(end1 < start1, "[PLE] algorithm>> remove_copy: 'numcells' paramter (%d) below zero", params[2]);
  890.  
  891.         cell* start2 = NULL;
  892.         amx_GetAddr(amx, params[3], &start2);
  893.  
  894.         cell value = params[4];
  895.  
  896.         cell* pos1 = start1, *pos2 = start2;
  897.         while (pos1 != end1)
  898.         {
  899.             if (*pos1 != value)
  900.             {
  901.                 *pos2 = *pos1;
  902.                 pos2++;
  903.             }
  904.             pos1++;
  905.         }
  906.         return pos2 - start2;
  907.     }
  908.     //native remove_copy_if(range[], numcells, dest[], {func_bool1, func_cell1, _}:func[FTSIZE]);
  909.     cell AMX_NATIVE_CALL algo_remove_copy_if(AMX* amx, cell* params)
  910.     {
  911.         error_if(!check_params(4), "[PLE] algorithm>> remove_copy_if: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  912.  
  913.         cell* start1 = NULL;
  914.         amx_GetAddr(amx, params[1], &start1);
  915.         cell* end1 = start1 + params[2];
  916.         error_if(end1 < start1, "[PLE] algorithm>> remove_copy_if: 'numcells' paramter (%d) below zero", params[2]);
  917.  
  918.         cell* start2 = NULL;
  919.         amx_GetAddr(amx, params[3], &start2);
  920.  
  921.         cell* func = NULL;
  922.         amx_GetAddr(amx, params[4], &func);
  923.         functionID fid(func);
  924.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> copy_if: function object 'func' is not valid");
  925.  
  926.         cell* pos1 = start1, *pos2 = start2;
  927.         while (pos1 != end1)
  928.         {
  929.             if (!ExecuteFunctionCC1O2(amx, &fid, *pos1))
  930.             {
  931.                 *pos2 = *pos1;
  932.                 pos2++;
  933.             }
  934.             pos1++;
  935.         }
  936.         return pos2 - start2;
  937.     }
  938.     //native unique(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE] = fixed_functions::equal_to);
  939.     cell AMX_NATIVE_CALL algo_unique(AMX* amx, cell* params)
  940.     {
  941.         error_if(!check_params(3), "[PLE] algorithm>> unique: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  942.  
  943.         cell* start = NULL;
  944.         amx_GetAddr(amx, params[1], &start);
  945.         cell* end = start + params[2];
  946.         error_if(end < start, "[PLE] algorithm>> unique: 'numcells' paramter (%d) below zero", params[2]);
  947.  
  948.         cell* func = NULL;
  949.         amx_GetAddr(amx, params[3], &func);
  950.         functionID fid(func);
  951.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> unique: function object 'func' is not valid");
  952.  
  953.         return std::unique(start, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y);  }) - start;
  954.     }
  955.     //native unique_copy(range[], numcells, dest[], {func_bool1, func_cell1, _}:func[FTSIZE] = fixed_functions::equal_to);
  956.     cell AMX_NATIVE_CALL algo_unique_copy(AMX* amx, cell* params)
  957.     {
  958.         error_if(!check_params(4), "[PLE] algorithm>> unique_copy: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  959.  
  960.         cell* start1 = NULL;
  961.         amx_GetAddr(amx, params[1], &start1);
  962.         cell* end1 = start1 + params[2];
  963.         error_if(end1 < start1, "[PLE] algorithm>> unique_copy: 'numcells' paramter (%d) below zero", params[2]);
  964.  
  965.         cell* start2 = NULL;
  966.         amx_GetAddr(amx, params[3], &start2);
  967.  
  968.         cell* func = NULL;
  969.         amx_GetAddr(amx, params[4], &func);
  970.         functionID fid(func);
  971.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> unique_copy: function object 'func' is not valid");
  972.  
  973.         if (start1 == end1) return 0;
  974.  
  975.         cell *pos1 = start1, *pos2 = start2;
  976.         *pos2 = *start1;
  977.         while (++pos1 != end1)
  978.         {
  979.             if (!ExecuteFunctionCC1C2(amx, &fid, *pos2, *pos1))
  980.             {
  981.                 pos2++;
  982.                 *pos2 = *pos1;
  983.             }
  984.         }
  985.         return pos2 - start2 + 1;
  986.     }
  987.     //native noret:reverse(range[], numcells);
  988.     cell AMX_NATIVE_CALL algo_reverse(AMX* amx, cell* params)
  989.     {
  990.         error_if(!check_params(2), "[PLE] algorithm>> reverse: expected 2 parameters but found %d parameters.", params[0] / sizeof(cell));
  991.  
  992.         cell* start = NULL;
  993.         amx_GetAddr(amx, params[1], &start);
  994.         cell* end = start + params[2];
  995.         error_if(end < start, "[PLE] algorithm>> reverse: 'numcells' paramter (%d) below zero", params[2]);
  996.  
  997.         while ((start != end) && (start != --end))
  998.         {
  999.             cell val = *start;
  1000.             *start = *end;
  1001.             *end = val;
  1002.             ++start;
  1003.         }
  1004.         return true;
  1005.     }
  1006.     //native noret:reverse_copy(range[], numcells, dest[]);
  1007.     cell AMX_NATIVE_CALL algo_reverse_copy(AMX* amx, cell* params)
  1008.     {
  1009.         error_if(!check_params(3), "[PLE] algorithm>> reverse_copy: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1010.  
  1011.         cell* start1 = NULL;
  1012.         amx_GetAddr(amx, params[1], &start1);
  1013.         cell* end1 = start1 + params[2];
  1014.         error_if(end1 < start1, "[PLE] algorithm>> reverse_copy: 'numcells' paramter (%d) below zero", params[2]);
  1015.  
  1016.         cell* start2 = NULL;
  1017.         amx_GetAddr(amx, params[3], &start2);
  1018.  
  1019.         cell *pos1 = start1, *pos2 = start2;
  1020.         while (pos1 != end1)
  1021.         {
  1022.             --end1;
  1023.             *pos2 = *end1;
  1024.             ++pos2;
  1025.         }
  1026.         return true;
  1027.     }
  1028.     //native noret:rotate(range[], middle, end);
  1029.     cell AMX_NATIVE_CALL algo_rotate(AMX* amx, cell* params)
  1030.     {
  1031.         error_if(!check_params(3), "[PLE] algorithm>> rotate: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1032.  
  1033.         cell* start = NULL;
  1034.         amx_GetAddr(amx, params[1], &start);
  1035.         cell* middle = start + params[2];
  1036.         error_if(middle < start, "[PLE] algorithm>> rotate: 'middle' paramter (%d) below zero", params[2]);
  1037.         cell* end = start + params[3];
  1038.         error_if(end < start, "[PLE] algorithm>> rotate: 'end' paramter (%d) below zero", params[3]);
  1039.  
  1040.         error_if(end < middle, "[PLE] algorithm>> rotate: 'middle' paramter (%d) is more than 'end' parameter (%d)", params[2], params[3]);
  1041.  
  1042.         std::rotate(start, middle, end);
  1043.         return true;
  1044.     }
  1045.     //native noret:rotate_copy(range[], middle, end, dest[]);
  1046.     cell AMX_NATIVE_CALL algo_rotate_copy(AMX* amx, cell* params)
  1047.     {
  1048.         error_if(!check_params(4), "[PLE] algorithm>> rotate_copy: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1049.  
  1050.         cell* start1 = NULL;
  1051.         amx_GetAddr(amx, params[1], &start1);
  1052.         cell* middle1 = start1 + params[2];
  1053.         error_if(middle1 < start1, "[PLE] algorithm>> rotate_copy: 'middle' paramter (%d) below zero", params[2]);
  1054.         cell* end1 = start1 + params[3];
  1055.         error_if(end1 < start1, "[PLE] algorithm>> rotate_copy: 'end' paramter (%d) below zero", params[3]);
  1056.  
  1057.         error_if(end1 < middle1, "[PLE] algorithm>> rotate_copy: 'middle' paramter (%d) is more than 'end' parameter (%d)", params[2], params[3]);
  1058.  
  1059.         cell* start2 = NULL;
  1060.         amx_GetAddr(amx, params[4], &start2);
  1061.  
  1062.         std::rotate_copy(start1, middle1, end1, start2);
  1063.         return true;
  1064.     }
  1065.     //random_shuffle won't be implemented (removed from C++17)
  1066.     //shuffle
  1067.     //sample
  1068.  
  1069.     //native bool:is_partitioned(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  1070.     cell AMX_NATIVE_CALL algo_is_partitioned(AMX* amx, cell* params)
  1071.     {
  1072.         error_if(!check_params(3), "[PLE] algorithm>> is_partitioned: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1073.  
  1074.         cell* start = NULL;
  1075.         amx_GetAddr(amx, params[1], &start);
  1076.         cell* end = start + params[2];
  1077.         error_if(end < start, "[PLE] algorithm>> is_partitioned: 'numcells' paramter (%d) below zero", params[2]);
  1078.  
  1079.         cell* func = NULL;
  1080.         amx_GetAddr(amx, params[3], &func);
  1081.         functionID fid(func);
  1082.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> is_partitioned: function object 'func' is not valid");
  1083.  
  1084.         return std::is_partitioned(start, end, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); });
  1085.     }
  1086.     //native partition(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  1087.     cell AMX_NATIVE_CALL algo_partition(AMX* amx, cell* params)
  1088.     {
  1089.         error_if(!check_params(3), "[PLE] algorithm>> partition: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1090.  
  1091.         cell* start = NULL;
  1092.         amx_GetAddr(amx, params[1], &start);
  1093.         cell* end = start + params[2];
  1094.         error_if(end < start, "[PLE] algorithm>> partition: 'numcells' paramter (%d) below zero", params[2]);
  1095.  
  1096.         cell* func = NULL;
  1097.         amx_GetAddr(amx, params[3], &func);
  1098.         functionID fid(func);
  1099.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> partition: function object 'func' is not valid");
  1100.  
  1101.         return std::partition(start, end, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); }) - start;
  1102.     }
  1103.     //native stable_partition(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  1104.     cell AMX_NATIVE_CALL algo_stable_partition(AMX* amx, cell* params)
  1105.     {
  1106.         error_if(!check_params(3), "[PLE] algorithm>> stable_partition: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1107.  
  1108.         cell* start = NULL;
  1109.         amx_GetAddr(amx, params[1], &start);
  1110.         cell* end = start + params[2];
  1111.         error_if(end < start, "[PLE] algorithm>> stable_partition: 'numcells' paramter (%d) below zero", params[2]);
  1112.  
  1113.         cell* func = NULL;
  1114.         amx_GetAddr(amx, params[3], &func);
  1115.         functionID fid(func);
  1116.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> stable_partition: function object 'func' is not valid");
  1117.  
  1118.         return std::stable_partition(start, end, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); }) - start;
  1119.     }
  1120.     //native noret:partition_copy(range[], numcells, dest1[], dest2[], {func_bool1, func_cell1, _}:func[FTSIZE]);
  1121.     cell AMX_NATIVE_CALL algo_partition_copy(AMX* amx, cell* params)
  1122.     {
  1123.         error_if(!check_params(5), "[PLE] algorithm>> partition_copy: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  1124.  
  1125.         cell* start1 = NULL;
  1126.         amx_GetAddr(amx, params[1], &start1);
  1127.         cell* end1 = start1 + params[2];
  1128.         error_if(end1 < start1, "[PLE] algorithm>> partition_copy: 'numcells' paramter (%d) below zero", params[2]);
  1129.  
  1130.         cell* start2 = NULL;
  1131.         amx_GetAddr(amx, params[3], &start2);
  1132.  
  1133.         cell* start3 = NULL;
  1134.         amx_GetAddr(amx, params[4], &start3);
  1135.  
  1136.         cell* func = NULL;
  1137.         amx_GetAddr(amx, params[5], &func);
  1138.         functionID fid(func);
  1139.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> partition_copy: function object 'func' is not valid");
  1140.  
  1141.         std::partition_copy(start1, end1, start2, start3, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); });
  1142.         return true;
  1143.     }
  1144.     //native partition_point(range[], numcells, {func_bool1, func_cell1, _}:func[FTSIZE]);
  1145.     cell AMX_NATIVE_CALL algo_partition_point(AMX* amx, cell* params)
  1146.     {
  1147.         error_if(!check_params(3), "[PLE] algorithm>> partition_point: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1148.  
  1149.         cell* start = NULL;
  1150.         amx_GetAddr(amx, params[1], &start);
  1151.         cell* end = start + params[2];
  1152.         error_if(end < start, "[PLE] algorithm>> partition_point: 'numcells' paramter (%d) below zero", params[2]);
  1153.  
  1154.         cell* func = NULL;
  1155.         amx_GetAddr(amx, params[3], &func);
  1156.         functionID fid(func);
  1157.         error_if(!fid.IsFunctionValid(1), "[PLE] algorithm>> partition_point: function object 'func' is not valid");
  1158.  
  1159.         return std::partition_point(start, end, [&amx, &fid, &func](cell x) { return ExecuteFunctionCC1O2(amx, &fid, x); }) - start;
  1160.     }
  1161.  
  1162.     //native noret:sort(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1163.     cell AMX_NATIVE_CALL algo_sort(AMX* amx, cell* params)
  1164.     {
  1165.         error_if(!check_params(3), "[PLE] algorithm>> sort: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1166.  
  1167.         cell* start = NULL;
  1168.         amx_GetAddr(amx, params[1], &start);
  1169.         cell* end = start + params[2];
  1170.         error_if(end < start, "[PLE] algorithm>> sort: 'numcells' paramter (%d) below zero", params[2]);
  1171.  
  1172.         cell* func = NULL;
  1173.         amx_GetAddr(amx, params[3], &func);
  1174.         functionID fid(func);
  1175.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> sort: function object 'func' is not valid");
  1176.  
  1177.         std::sort(start, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1178.         return true;
  1179.     }
  1180.     //native noret:sort(range[], middle, end, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1181.     cell AMX_NATIVE_CALL algo_partial_sort(AMX* amx, cell* params)
  1182.     {
  1183.         error_if(!check_params(4), "[PLE] algorithm>> partial_sort: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1184.  
  1185.         cell* start = NULL;
  1186.         amx_GetAddr(amx, params[1], &start);
  1187.         cell* middle = start + params[2];
  1188.         error_if(middle < start, "[PLE] algorithm>> partial_sort:'middle' paramter (%d) below zero", params[2]);
  1189.         cell* end = start + params[3];
  1190.         error_if(end < start, "[PLE] algorithm>> partial_sort: 'end' paramter (%d) below zero", params[3]);
  1191.  
  1192.         error_if(end < middle, "[PLE] algorithm>> partial_sort: 'middle' paramter (%d) is more than end parameter (%d)", params[2], params[2]);
  1193.  
  1194.         cell* func = NULL;
  1195.         amx_GetAddr(amx, params[4], &func);
  1196.         functionID fid(func);
  1197.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> partial_sort: function object 'func' is not valid");
  1198.  
  1199.         std::partial_sort(start, middle, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1200.         return true;
  1201.     }
  1202.     //native partial_sort_copy(range[], range_numcells, dest[], dest_numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1203.     cell AMX_NATIVE_CALL algo_partial_sort_copy(AMX* amx, cell* params)
  1204.     {
  1205.         error_if(!check_params(5), "[PLE] algorithm>> partial_sort_copy: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  1206.  
  1207.         cell* start1 = NULL;
  1208.         amx_GetAddr(amx, params[1], &start1);
  1209.         cell* end1 = start1 + params[2];
  1210.         error_if(end1 < start1, "[PLE] algorithm>> partial_sort_copy: 'range_numcells' paramter (%d) below zero", params[2]);
  1211.  
  1212.         cell* start2 = NULL;
  1213.         amx_GetAddr(amx, params[3], &start2);
  1214.         cell* end2 = start2 + params[4];
  1215.         error_if(end2 < start2, "[PLE] algorithm>> partial_sort_copy: 'dest_numcells' paramter (%d) below zero", params[4]);
  1216.  
  1217.         cell* func = NULL;
  1218.         amx_GetAddr(amx, params[5], &func);
  1219.         functionID fid(func);
  1220.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> partial_sort_copy: function object 'func' is not valid");
  1221.  
  1222.         return std::partial_sort_copy(start1, end1, start2, end2, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - start2;
  1223.     }
  1224.     //native bool:is_sorted(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1225.     cell AMX_NATIVE_CALL algo_is_sorted(AMX* amx, cell* params)
  1226.     {
  1227.         error_if(!check_params(3), "[PLE] algorithm>> is_sorted: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1228.  
  1229.         cell* start = NULL;
  1230.         amx_GetAddr(amx, params[1], &start);
  1231.         cell* end = start + params[2];
  1232.         error_if(end < start, "[PLE] algorithm>> is_sorted: 'numcells' paramter (%d) below zero", params[2]);
  1233.  
  1234.         cell* func = NULL;
  1235.         amx_GetAddr(amx, params[3], &func);
  1236.         functionID fid(func);
  1237.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> is_sorted: function object 'func' is not valid");
  1238.  
  1239.         return std::is_sorted(start, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1240.     }
  1241.     //native noret:nth_element(range[], nth, end, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1242.     cell AMX_NATIVE_CALL algo_nth_element(AMX* amx, cell* params)
  1243.     {
  1244.         error_if(!check_params(4), "[PLE] algorithm>> nth_element: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1245.  
  1246.         cell* start = NULL;
  1247.         amx_GetAddr(amx, params[1], &start);
  1248.         cell* nth = start + params[2];
  1249.         error_if(nth < start, "[PLE] algorithm>> nth_element: 'nth' paramter (%d) below zero", params[2]);
  1250.         cell* end = start + params[3];
  1251.         error_if(end < start, "[PLE] algorithm>> nth_element: 'end' paramter (%d) below zero", params[3]);
  1252.  
  1253.         error_if((end < nth), "[PLE] algorithm>> nth_element: 'nth' paramter (%d) is more than or equal to 'end' parameter (%d)", params[2], params[3]);
  1254.  
  1255.         cell* func = NULL;
  1256.         amx_GetAddr(amx, params[4], &func);
  1257.         functionID fid(func);
  1258.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> nth_element: function object 'func' is not valid");
  1259.  
  1260.         std::nth_element(start, nth, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1261.         return true;
  1262.     }
  1263.  
  1264.     //native lower_bound(range[], numcells, value, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1265.     cell AMX_NATIVE_CALL algo_lower_bound(AMX* amx, cell* params)
  1266.     {
  1267.         error_if(!check_params(4), "[PLE] algorithm>> lower_bound: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1268.  
  1269.         cell* start = NULL;
  1270.         amx_GetAddr(amx, params[1], &start);
  1271.         cell* end = start + params[2];
  1272.         error_if(end < start, "[PLE] algorithm>> lower_bound: 'numcells' paramter (%d) below zero", params[2]);
  1273.  
  1274.         cell val = params[3];
  1275.  
  1276.         cell* func = NULL;
  1277.         amx_GetAddr(amx, params[4], &func);
  1278.         functionID fid(func);
  1279.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> lower_bound: function object 'func' is not valid");
  1280.  
  1281.         return std::lower_bound(start, end, val, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - start;
  1282.     }
  1283.     //native upper_bound(range[], numcells, value, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1284.     cell AMX_NATIVE_CALL algo_upper_bound(AMX* amx, cell* params)
  1285.     {
  1286.         error_if(!check_params(4), "[PLE] algorithm>> upper_bound: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1287.  
  1288.         cell* start = NULL;
  1289.         amx_GetAddr(amx, params[1], &start);
  1290.         cell* end = start + params[2];
  1291.         error_if(end < start, "[PLE] algorithm>> upper_bound: 'numcells' paramter (%d) below zero", params[2]);
  1292.  
  1293.         cell val = params[3];
  1294.  
  1295.         cell* func = NULL;
  1296.         amx_GetAddr(amx, params[4], &func);
  1297.         functionID fid(func);
  1298.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> upper_bound: function object 'func' is not valid");
  1299.  
  1300.         return std::upper_bound(start, end, val, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - start;
  1301.     }
  1302.     //native noret:equal_range(range[], numcells, value, &smallest, &largest, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1303.     cell AMX_NATIVE_CALL algo_equal_range(AMX* amx, cell* params)
  1304.     {
  1305.         error_if(!check_params(6), "[PLE] algorithm>> equal_range: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1306.  
  1307.         cell* start = NULL;
  1308.         amx_GetAddr(amx, params[1], &start);
  1309.         cell* end = start + params[2];
  1310.         error_if(end < start, "[PLE] algorithm>> equal_range: 'numcells' paramter (%d) below zero", params[2]);
  1311.  
  1312.         cell value = params[3];
  1313.  
  1314.         cell* smallest_addr = NULL;
  1315.         amx_GetAddr(amx, params[4], &smallest_addr);
  1316.  
  1317.         cell* largest_addr = NULL;
  1318.         amx_GetAddr(amx, params[5], &largest_addr);
  1319.  
  1320.         cell* func = NULL;
  1321.         amx_GetAddr(amx, params[6], &func);
  1322.         functionID fid(func);
  1323.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> equal_range: function object 'func' is not valid");
  1324.  
  1325.         auto pr = std::equal_range(start, end, value, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1326.  
  1327.         *smallest_addr = pr.first - start;
  1328.         *largest_addr = pr.second - start;
  1329.         return true;
  1330.     }
  1331.     //native bool:binary_search(range[], numcells, value, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1332.     cell AMX_NATIVE_CALL algo_binary_search(AMX* amx, cell* params)
  1333.     {
  1334.         error_if(!check_params(4), "[PLE] algorithm>> binary_search: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1335.  
  1336.         cell* start = NULL;
  1337.         amx_GetAddr(amx, params[1], &start);
  1338.         cell* end = start + params[2];
  1339.         error_if(end < start, "[PLE] algorithm>> binary_search: 'numcells' paramter (%d) below zero", params[2]);
  1340.  
  1341.         cell val = params[3];
  1342.  
  1343.         cell* func = NULL;
  1344.         amx_GetAddr(amx, params[4], &func);
  1345.         functionID fid(func);
  1346.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> binary_search: function object 'func' is not valid");
  1347.  
  1348.         return std::binary_search(start, end, val, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1349.     }
  1350.  
  1351.     //native merge(range1[], numcells1, range2[], numcells2, dest[], {_, func_bool2, func_cell2}:func[FTSIZE] = fixed_functions::less);
  1352.     cell AMX_NATIVE_CALL algo_merge(AMX* amx, cell* params)
  1353.     {
  1354.         error_if(!check_params(6), "[PLE] algorithm>> merge: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1355.  
  1356.         cell* start1 = NULL;
  1357.         amx_GetAddr(amx, params[1], &start1);
  1358.         cell* end1 = start1 + params[2];
  1359.         error_if(end1 < start1, "[PLE] algorithm>> merge: 'numcells1' paramter (%d) below zero", params[2]);
  1360.  
  1361.         cell* start2 = NULL;
  1362.         amx_GetAddr(amx, params[3], &start2);
  1363.         cell* end2 = start2 + params[4];
  1364.         error_if(end2 < start2, "[PLE] algorithm>> merge: 'numcells2' paramter (%d) below zero", params[4]);
  1365.  
  1366.         cell* result = NULL;
  1367.         amx_GetAddr(amx, params[5], &result);
  1368.  
  1369.         cell* func = NULL;
  1370.         amx_GetAddr(amx, params[6], &func);
  1371.         functionID fid(func);
  1372.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> merge: function object 'func' is not valid");
  1373.  
  1374.         return std::merge(start1, end1, start2, end2, result, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - result;
  1375.     }
  1376.     //native noret:inplace_merge(range[], middle, end, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1377.     cell AMX_NATIVE_CALL algo_inplace_merge(AMX* amx, cell* params)
  1378.     {
  1379.         error_if(!check_params(4), "[PLE] algorithm>> inplace_merge: expected 4 parameters but found %d parameters.", params[0] / sizeof(cell));
  1380.  
  1381.         cell* start = NULL;
  1382.         amx_GetAddr(amx, params[1], &start);
  1383.         cell* middle = start + params[2];
  1384.         error_if(middle < start, "[PLE] algorithm>> inplace_merge: 'middle' paramter (%d) below zero", params[2]);
  1385.         cell* end = start + params[3];
  1386.         error_if(end < start, "[PLE] algorithm>> inplace_merge: 'end' paramter (%d) below zero", params[4]);
  1387.  
  1388.         error_if((end < middle), "[PLE] algorithm>> inplace_merge: 'middle' paramter (%d) is more than or equal to 'end' parameter (%d)", params[2], params[3]);
  1389.  
  1390.         cell* func = NULL;
  1391.         amx_GetAddr(amx, params[4], &func);
  1392.         functionID fid(func);
  1393.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> inplace_merge: function object 'func' is not valid");
  1394.  
  1395.         std::inplace_merge(start, middle, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1396.         return true;
  1397.     }
  1398.     //native bool:includes(range1[], numcells1, range2[], numcells2, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::equal_to);
  1399.     cell AMX_NATIVE_CALL algo_includes(AMX* amx, cell* params)
  1400.     {
  1401.         error_if(!check_params(5), "[PLE] algorithm>> includes: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  1402.  
  1403.         cell* start1 = NULL;
  1404.         amx_GetAddr(amx, params[1], &start1);
  1405.         cell* end1 = start1 + params[2];
  1406.         error_if(end1 < start1, "[PLE] algorithm>> includes: 'numcells1' paramter (%d) below zero", params[2]);
  1407.  
  1408.         cell* start2 = NULL;
  1409.         amx_GetAddr(amx, params[3], &start2);
  1410.         cell* end2 = start2 + params[4];
  1411.         error_if(end2 < start2, "[PLE] algorithm>> includes: 'numcells2' paramter (%d) below zero", params[4]);
  1412.  
  1413.         cell* func = NULL;
  1414.         amx_GetAddr(amx, params[5], &func);
  1415.         functionID fid(func);
  1416.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> includes: function object 'func' is not valid");
  1417.  
  1418.         return std::includes(start1, end1, start2, end2, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1419.     }
  1420.     //native set_union(range1[], numcells1, range2[], numcells2, dest[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1421.     cell AMX_NATIVE_CALL algo_set_union(AMX* amx, cell* params)
  1422.     {
  1423.         error_if(!check_params(6), "[PLE] algorithm>> set_union: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1424.  
  1425.         cell* start1 = NULL;
  1426.         amx_GetAddr(amx, params[1], &start1);
  1427.         cell* end1 = start1 + params[2];
  1428.         error_if(end1 < start1, "[PLE] algorithm>> set_union: 'numcells1' paramter (%d) below zero", params[2]);
  1429.  
  1430.         cell* start2 = NULL;
  1431.         amx_GetAddr(amx, params[3], &start2);
  1432.         cell* end2 = start2 + params[4];
  1433.         error_if(end2 < start2, "[PLE] algorithm>> set_union: 'numcells2' paramter (%d) below zero", params[4]);
  1434.  
  1435.         cell* result = NULL;
  1436.         amx_GetAddr(amx, params[5], &result);
  1437.  
  1438.         cell* func = NULL;
  1439.         amx_GetAddr(amx, params[6], &func);
  1440.         functionID fid(func);
  1441.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> set_union: function object 'func' is not valid");
  1442.  
  1443.         return std::set_union(start1, end1, start2, end2, result, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - result;
  1444.     }
  1445.     //native set_intersection(range1[], numcells1, range2[], numcells2, dest[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1446.     cell AMX_NATIVE_CALL algo_set_intersection(AMX* amx, cell* params)
  1447.     {
  1448.         error_if(!check_params(6), "[PLE] algorithm>> set_intersection: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1449.  
  1450.         cell* start1 = NULL;
  1451.         amx_GetAddr(amx, params[1], &start1);
  1452.         cell* end1 = start1 + params[2];
  1453.         error_if(end1 < start1, "[PLE] algorithm>> set_intersection: 'numcells1' paramter (%d) below zero", params[2]);
  1454.  
  1455.         cell* start2 = NULL;
  1456.         amx_GetAddr(amx, params[3], &start2);
  1457.         cell* end2 = start2 + params[4];
  1458.         error_if(end2 < start2, "[PLE] algorithm>> set_intersection: 'numcells2' paramter (%d) below zero", params[4]);
  1459.  
  1460.         cell* result = NULL;
  1461.         amx_GetAddr(amx, params[5], &result);
  1462.  
  1463.         cell* func = NULL;
  1464.         amx_GetAddr(amx, params[6], &func);
  1465.         functionID fid(func);
  1466.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> set_intersection: function object 'func' is not valid");
  1467.  
  1468.         return std::set_intersection(start1, end1, start2, end2, result, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - result;
  1469.     }
  1470.     //native set_difference(range1[], numcells1, range2[], numcells2, dest[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1471.     cell AMX_NATIVE_CALL algo_set_difference(AMX* amx, cell* params)
  1472.     {
  1473.         error_if(!check_params(6), "[PLE] algorithm>> set_difference: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1474.  
  1475.         cell* start1 = NULL;
  1476.         amx_GetAddr(amx, params[1], &start1);
  1477.         cell* end1 = start1 + params[2];
  1478.         error_if(end1 < start1, "[PLE] algorithm>> set_difference: 'numcells1' paramter (%d) below zero", params[2]);
  1479.  
  1480.         cell* start2 = NULL;
  1481.         amx_GetAddr(amx, params[3], &start2);
  1482.         cell* end2 = start2 + params[4];
  1483.         error_if(end2 < start2, "[PLE] algorithm>> set_difference: 'numcells2' paramter (%d) below zero", params[4]);
  1484.  
  1485.         cell* result = NULL;
  1486.         amx_GetAddr(amx, params[5], &result);
  1487.  
  1488.         cell* func = NULL;
  1489.         amx_GetAddr(amx, params[6], &func);
  1490.         functionID fid(func);
  1491.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> set_difference: function object 'func' is not valid");
  1492.  
  1493.         return std::set_difference(start1, end1, start2, end2, result, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - result;
  1494.     }
  1495.     //native set_symmetric_difference(range1[], numcells1, range2[], numcells2, dest[], {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1496.     cell AMX_NATIVE_CALL algo_set_symmetric_difference(AMX* amx, cell* params)
  1497.     {
  1498.         error_if(!check_params(6), "[PLE] algorithm>> set_symmetric_difference: expected 6 parameters but found %d parameters.", params[0] / sizeof(cell));
  1499.  
  1500.         cell* start1 = NULL;
  1501.         amx_GetAddr(amx, params[1], &start1);
  1502.         cell* end1 = start1 + params[2];
  1503.         error_if(end1 < start1, "[PLE] algorithm>> set_symmetric_difference: 'numcells1' paramter (%d) below zero", params[2]);
  1504.  
  1505.         cell* start2 = NULL;
  1506.         amx_GetAddr(amx, params[3], &start2);
  1507.         cell* end2 = start2 + params[4];
  1508.         error_if(end2 < start2, "[PLE] algorithm>> set_symmetric_difference: 'numcells2' paramter (%d) below zero", params[4]);
  1509.  
  1510.         cell* result = NULL;
  1511.         amx_GetAddr(amx, params[5], &result);
  1512.  
  1513.         cell* func = NULL;
  1514.         amx_GetAddr(amx, params[6], &func);
  1515.         functionID fid(func);
  1516.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> set_symmetric_difference: function object 'func' is not valid");
  1517.  
  1518.         return std::set_symmetric_difference(start1, end1, start2, end2, result, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); }) - result;
  1519.     }
  1520.  
  1521.     //push_heap, pop_heap, make_heap, sort_heap, is_heap, is_heap_until not implemented
  1522.  
  1523.     //minmax not implemented
  1524.     //native noret:minmax_element(range[], numcells, &smallest, &largest, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1525.     cell AMX_NATIVE_CALL algo_minmax_element(AMX* amx, cell* params)
  1526.     {
  1527.         error_if(!check_params(5), "[PLE] algorithm>> minmax_element: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  1528.  
  1529.         cell* start = NULL;
  1530.         amx_GetAddr(amx, params[1], &start);
  1531.         cell* end = start + params[2];
  1532.         error_if(end < start, "[PLE] algorithm>> minmax_element: 'numcells' paramter (%d) below zero", params[2]);
  1533.  
  1534.         cell* smallest_addr = NULL;
  1535.         amx_GetAddr(amx, params[3], &smallest_addr);
  1536.  
  1537.         cell* largest_addr = NULL;
  1538.         amx_GetAddr(amx, params[4], &largest_addr);
  1539.  
  1540.         cell* func = NULL;
  1541.         amx_GetAddr(amx, params[5], &func);
  1542.         functionID fid(func);
  1543.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> minxmax_element: function object 'func' is not valid");
  1544.  
  1545.         cell *smallest = start, *largest = start, *pos = start;
  1546.         while (pos != end)
  1547.         {
  1548.             if (ExecuteFunctionCC1C2(amx, &fid, *pos, *smallest))   smallest = pos;
  1549.             if (ExecuteFunctionCC1C2(amx, &fid, *largest, *pos))    largest = pos;
  1550.             pos++;
  1551.         }
  1552.         *smallest_addr = smallest - start;
  1553.         *largest_addr = largest - start;
  1554.         return true;
  1555.     }
  1556.     //native min_element(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1557.     cell AMX_NATIVE_CALL algo_min_element(AMX* amx, cell* params)
  1558.     {
  1559.         error_if(!check_params(3), "[PLE] algorithm>> min_element: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1560.  
  1561.         cell* start = NULL;
  1562.         amx_GetAddr(amx, params[1], &start);
  1563.         cell* end = start + params[2];
  1564.         error_if(end < start, "[PLE] algorithm>> min_element: 'numcells' paramter (%d) below zero", params[2]);
  1565.  
  1566.         cell* func = NULL;
  1567.         amx_GetAddr(amx, params[3], &func);
  1568.         functionID fid(func);
  1569.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> min_element: function object 'func' is not valid");
  1570.  
  1571.         cell *pos = start, *smallest = start;
  1572.         while (pos != end)
  1573.         {
  1574.             if (ExecuteFunctionCC1C2(amx, &fid, *pos, *smallest))   smallest = pos;
  1575.             pos++;
  1576.         }
  1577.         return smallest - start;
  1578.     }
  1579.     //native max_element(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1580.     cell AMX_NATIVE_CALL algo_max_element(AMX* amx, cell* params)
  1581.     {
  1582.         error_if(!check_params(3), "[PLE] algorithm>> max_element: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1583.  
  1584.         cell* start = NULL;
  1585.         amx_GetAddr(amx, params[1], &start);
  1586.         cell* end = start + params[2];
  1587.         error_if(end < start, "[PLE] algorithm>> max_element: 'numcells' paramter (%d) below zero", params[2]);
  1588.  
  1589.         cell* func = NULL;
  1590.         amx_GetAddr(amx, params[3], &func);
  1591.         functionID fid(func);
  1592.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> max_element: function object 'func' is not valid");
  1593.  
  1594.         cell *pos = start, *largest = start;
  1595.         while (pos != end)
  1596.         {
  1597.             if (ExecuteFunctionCC1C2(amx, &fid, *largest, *pos))    largest = pos;
  1598.             pos++;
  1599.         }
  1600.         return largest - start;
  1601.     }
  1602.  
  1603.     //native bool:lexicographical_compare(range1[], numcells1, range2[], numcells2, {func_bool2, func_cell2, _}:func[FTSIZE]) = fixed_functions::less;
  1604.     cell AMX_NATIVE_CALL algo_lexicographical_compare(AMX* amx, cell* params)
  1605.     {
  1606.         error_if(!check_params(5), "[PLE] algorithm>> lexicographical_compare: expected 5 parameters but found %d parameters.", params[0] / sizeof(cell));
  1607.  
  1608.         cell* start1 = NULL;
  1609.         amx_GetAddr(amx, params[1], &start1);
  1610.         cell* end1 = start1 + params[2];
  1611.         error_if(end1 < start1, "[PLE] algorithm>> lexicographical_compare: 'numcells1' paramter (%d) below zero", params[2]);
  1612.  
  1613.         cell* start2 = NULL;
  1614.         amx_GetAddr(amx, params[3], &start2);
  1615.         cell* end2 = start2 + params[4];
  1616.         error_if(end2 < start2, "[PLE] algorithm>> lexicographical_compare: 'numcells2' paramter (%d) below zero", params[4]);
  1617.  
  1618.         cell* func = NULL;
  1619.         amx_GetAddr(amx, params[5], &func);
  1620.         functionID fid(func);
  1621.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> lexicographical_compare: function object 'func' is not valid");
  1622.  
  1623.         return std::lexicographical_compare(start1, end1, start2, end2, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1624.     }
  1625.     //native bool:prev_permutation(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1626.     cell AMX_NATIVE_CALL algo_next_permutation(AMX* amx, cell* params)
  1627.     {
  1628.         error_if(!check_params(3), "[PLE] algorithm>> next_permutation: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1629.  
  1630.         cell* start = NULL;
  1631.         amx_GetAddr(amx, params[1], &start);
  1632.         cell* end = start + params[2];
  1633.         error_if(end < start, "[PLE] algorithm>> prev_permutation: 'numcells' paramter (%d) below zero", params[2]);
  1634.  
  1635.         cell* func = NULL;
  1636.         amx_GetAddr(amx, params[3], &func);
  1637.         functionID fid(func);
  1638.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> next_permutation: function object 'func' is not valid");
  1639.  
  1640.         return std::next_permutation(start, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1641.     }
  1642.     //native bool:next_permutation(range[], numcells, {func_bool2, func_cell2, _}:func[FTSIZE] = fixed_functions::less);
  1643.     cell AMX_NATIVE_CALL algo_prev_permutation(AMX* amx, cell* params)
  1644.     {
  1645.         error_if(!check_params(3), "[PLE] algorithm>> prev_permutation: expected 3 parameters but found %d parameters.", params[0] / sizeof(cell));
  1646.  
  1647.         cell* start = NULL;
  1648.         amx_GetAddr(amx, params[1], &start);
  1649.         cell* end = start + params[2];
  1650.         error_if(end < start, "[PLE] algorithm>> prev_permutation: 'numcells' paramter (%d) below zero", params[2]);
  1651.  
  1652.         cell* func = NULL;
  1653.         amx_GetAddr(amx, params[3], &func);
  1654.         functionID fid(func);
  1655.         error_if(!fid.IsFunctionValid(2), "[PLE] algorithm>> prev_permutation: function object 'func' is not valid");
  1656.  
  1657.         return std::prev_permutation(start, end, [&amx, &fid](cell x, cell y) { return ExecuteFunctionCC1C2(amx, &fid, x, y); });
  1658.     }
Add Comment
Please, Sign In to add comment