forked from OpenSpace100/blockchain-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestArray.sol
More file actions
76 lines (59 loc) · 1.62 KB
/
Copy pathtestArray.sol
File metadata and controls
76 lines (59 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma solidity ^0.8.0;
contract testArray {
// 定长 、storage 位置
uint[10] tens;
// 变长
// uint[] public numbers;
uint[] public numbers = [1, 2, 5, 5, 6 ,6 , 9, 19, 3, 10, 12, 23];
uint[] public arr1 = new uint[](1);
function modifyOnTens(uint x) public {
tens[0] = x;
// tens.push(x); // error;
}
function add(uint x) public {
arr1.push(x);
}
function arr1Len() public view returns (uint len) {
return arr1.length;
}
function copy(uint[] calldata arrs) public returns (uint len) {
numbers = arrs; // copy
return numbers.length;
}
function modifyNumbers() public {
uint[] storage y = numbers; // 不copy,指向同一个数据
y[0] = 1;
}
function test(uint len) public {
// 内存 位置
string[4] memory adaArr = ["This", "is", "an", "array"];
uint[] memory c = new uint[](len);
// c.push(1);
c[0] = 1;
}
uint public total;
uint calced;
function sum(uint end) public {
if (end > calced) {
for (uint i = calced; i < end; i++) {
total += numbers[i];
}
calced = end;
}
}
// gas issue 58388
function dosome() public {
uint leng = numbers.length;
for (uint i = 0; i < leng; i++) {
// do...
total += numbers[i];
}
}
//
function dosome2(uint start, uint len) public {
for (uint i = start; i < start + len; i++) {
// do...
total += numbers[i];
}
}
}