customFunctions.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. if (!function_exists('arraycopy')) {
  3. function arraycopy($srcArray, $srcPos, $destArray, $destPos, $length)
  4. {
  5. $srcArrayToCopy = array_slice($srcArray, $srcPos, $length);
  6. array_splice($destArray, $destPos, $length, $srcArrayToCopy);
  7. return $destArray;
  8. }
  9. }
  10. if (!function_exists('hashCode')) {
  11. function hashCode($s)
  12. {
  13. $h = 0;
  14. $len = strlen($s);
  15. for ($i = 0; $i < $len; $i++) {
  16. $h = (31 * $h + ord($s[$i]));
  17. }
  18. return $h;
  19. }
  20. }
  21. if (!function_exists('numberOfTrailingZeros')) {
  22. function numberOfTrailingZeros($i)
  23. {
  24. if ($i == 0) return 32;
  25. $num = 0;
  26. while (($i & 1) == 0) {
  27. $i >>= 1;
  28. $num++;
  29. }
  30. return $num;
  31. }
  32. }
  33. if (!function_exists('uRShift')) {
  34. function uRShift($a, $b)
  35. {
  36. static $mask = (8 * PHP_INT_SIZE - 1);
  37. if ($b === 0) {
  38. return $a;
  39. }
  40. return ($a >> $b) & ~(1 << $mask >> ($b - 1));
  41. }
  42. }
  43. /*
  44. function sdvig3($num,$count=1){//>>> 32 bit
  45. $s = decbin($num);
  46. $sarray = str_split($s,1);
  47. $sarray = array_slice($sarray,-32);//32bit
  48. for($i=0;$i<=1;$i++) {
  49. array_pop($sarray);
  50. array_unshift($sarray, '0');
  51. }
  52. return bindec(implode($sarray));
  53. }
  54. */
  55. if (!function_exists('sdvig3')) {
  56. function sdvig3($a, $b)
  57. {
  58. if ($a >= 0) {
  59. return bindec(decbin($a >> $b)); //simply right shift for positive number
  60. }
  61. $bin = decbin($a >> $b);
  62. $bin = substr($bin, $b); // zero fill on the left side
  63. return bindec($bin);
  64. }
  65. }
  66. if (!function_exists('floatToIntBits')) {
  67. function floatToIntBits($float_val)
  68. {
  69. $int = unpack('i', pack('f', $float_val));
  70. return $int[1];
  71. }
  72. }
  73. if (!function_exists('fill_array')) {
  74. function fill_array($index, $count, $value)
  75. {
  76. if ($count <= 0) {
  77. return [0];
  78. }
  79. return array_fill($index, $count, $value);
  80. }
  81. }