1
1
<?php
2
2
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 );
7
8
8
- return $ destArray ;
9
+ return $ destArray ;
10
+ }
9
11
}
10
12
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
+ }
18
21
19
- return $ h ;
22
+ return $ h ;
23
+ }
20
24
}
21
25
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 ;
29
37
}
30
-
31
- return $ num ;
32
38
}
33
39
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
+ }
40
47
41
- return ($ a >> $ b ) & ~(1 << $ mask >> ($ b - 1 ));
48
+ return ($ a >> $ b ) & ~(1 << $ mask >> ($ b - 1 ));
49
+ }
42
50
}
43
51
44
52
/*
@@ -56,31 +64,38 @@ function sdvig3($num,$count=1){//>>> 32 bit
56
64
}
57
65
*/
58
66
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
+ }
64
73
65
- $ bin = decbin ($ a >> $ b );
74
+ $ bin = decbin ($ a >> $ b );
66
75
67
- $ bin = substr ($ bin , $ b ); // zero fill on the left side
76
+ $ bin = substr ($ bin , $ b ); // zero fill on the left side
68
77
69
- return bindec ($ bin );
78
+ return bindec ($ bin );
79
+ }
70
80
}
71
81
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 ));
75
86
76
- return $ int [1 ];
87
+ return $ int [1 ];
88
+ }
77
89
}
78
90
79
- function fill_array ($ index , $ count , $ value )
80
- {
81
- if ($ count <= 0 ) {
82
- return [0 ];
83
- }
84
91
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
+ }
86
101
}
0 commit comments