11<?php
22
3- function arraycopy ($ srcArray , $ srcPos , $ destArray , $ destPos , $ length )
4- {
5- $ srcArrayToCopy = array_slice ($ srcArray , $ srcPos , $ length );
6- array_splice ($ destArray , $ destPos , $ length , $ srcArrayToCopy );
3+ if (!function_exists ('arraycopy ' )) {
4+ function arraycopy ($ srcArray , $ srcPos , $ destArray , $ destPos , $ length )
5+ {
6+ $ srcArrayToCopy = array_slice ($ srcArray , $ srcPos , $ length );
7+ array_splice ($ destArray , $ destPos , $ length , $ srcArrayToCopy );
78
8- return $ destArray ;
9+ return $ destArray ;
10+ }
911}
1012
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- }
13+ if (!function_exists ('hashCode ' )) {
14+ function hashCode ($ s )
15+ {
16+ $ h = 0 ;
17+ $ len = strlen ($ s );
18+ for ($ i = 0 ; $ i < $ len ; $ i ++) {
19+ $ h = (31 * $ h + ord ($ s [$ i ]));
20+ }
1821
19- return $ h ;
22+ return $ h ;
23+ }
2024}
2125
22- function numberOfTrailingZeros ($ i )
23- {
24- if ($ i == 0 ) return 32 ;
25- $ num = 0 ;
26- while (($ i & 1 ) == 0 ) {
27- $ i >>= 1 ;
28- $ num ++;
26+ if (!function_exists ('numberOfTrailingZeros ' )) {
27+ function numberOfTrailingZeros ($ i )
28+ {
29+ if ($ i == 0 ) return 32 ;
30+ $ num = 0 ;
31+ while (($ i & 1 ) == 0 ) {
32+ $ i >>= 1 ;
33+ $ num ++;
34+ }
35+
36+ return $ num ;
2937 }
30-
31- return $ num ;
3238}
3339
34- function uRShift ($ a , $ b )
35- {
36- static $ mask = (8 * PHP_INT_SIZE - 1 );
37- if ($ b === 0 ) {
38- return $ a ;
39- }
40+ if (!function_exists ('uRShift ' )) {
41+ function uRShift ($ a , $ b )
42+ {
43+ static $ mask = (8 * PHP_INT_SIZE - 1 );
44+ if ($ b === 0 ) {
45+ return $ a ;
46+ }
4047
41- return ($ a >> $ b ) & ~(1 << $ mask >> ($ b - 1 ));
48+ return ($ a >> $ b ) & ~(1 << $ mask >> ($ b - 1 ));
49+ }
4250}
4351
4452/*
@@ -56,31 +64,38 @@ function sdvig3($num,$count=1){//>>> 32 bit
5664}
5765*/
5866
59- function sdvig3 ($ a , $ b )
60- {
61- if ($ a >= 0 ) {
62- return bindec (decbin ($ a >> $ b )); //simply right shift for positive number
63- }
67+ if (!function_exists ('sdvig3 ' )) {
68+ function sdvig3 ($ a , $ b )
69+ {
70+ if ($ a >= 0 ) {
71+ return bindec (decbin ($ a >> $ b )); //simply right shift for positive number
72+ }
6473
65- $ bin = decbin ($ a >> $ b );
74+ $ bin = decbin ($ a >> $ b );
6675
67- $ bin = substr ($ bin , $ b ); // zero fill on the left side
76+ $ bin = substr ($ bin , $ b ); // zero fill on the left side
6877
69- return bindec ($ bin );
78+ return bindec ($ bin );
79+ }
7080}
7181
72- function floatToIntBits ($ float_val )
73- {
74- $ int = unpack ('i ' , pack ('f ' , $ float_val ));
82+ if (!function_exists ('floatToIntBits ' )) {
83+ function floatToIntBits ($ float_val )
84+ {
85+ $ int = unpack ('i ' , pack ('f ' , $ float_val ));
7586
76- return $ int [1 ];
87+ return $ int [1 ];
88+ }
7789}
7890
79- function fill_array ($ index , $ count , $ value )
80- {
81- if ($ count <= 0 ) {
82- return [0 ];
83- }
8491
85- return array_fill ($ index , $ count , $ value );
92+ if (!function_exists ('fill_array ' )) {
93+ function fill_array ($ index , $ count , $ value )
94+ {
95+ if ($ count <= 0 ) {
96+ return [0 ];
97+ }
98+
99+ return array_fill ($ index , $ count , $ value );
100+ }
86101}
0 commit comments