forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathArraysMock.sol
More file actions
127 lines (93 loc) · 3.31 KB
/
ArraysMock.sol
File metadata and controls
127 lines (93 loc) · 3.31 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Arrays} from "../utils/Arrays.sol";
contract Uint256ArraysMock {
using Arrays for uint256[];
uint256[] private _array;
constructor(uint256[] memory array) {
_array = array;
}
function findUpperBound(uint256 value) external view returns (uint256) {
return _array.findUpperBound(value);
}
function lowerBound(uint256 value) external view returns (uint256) {
return _array.lowerBound(value);
}
function upperBound(uint256 value) external view returns (uint256) {
return _array.upperBound(value);
}
function lowerBoundMemory(uint256[] memory array, uint256 value) external pure returns (uint256) {
return array.lowerBoundMemory(value);
}
function upperBoundMemory(uint256[] memory array, uint256 value) external pure returns (uint256) {
return array.upperBoundMemory(value);
}
function unsafeAccess(uint256 pos) external view returns (uint256) {
return _array.unsafeAccess(pos).value;
}
function sort(uint256[] memory array) external pure returns (uint256[] memory) {
return array.sort();
}
function sortReverse(uint256[] memory array) external pure returns (uint256[] memory) {
return array.sort(_reverse);
}
function _reverse(uint256 a, uint256 b) private pure returns (bool) {
return a > b;
}
function unsafeSetLength(uint256 newLength) external {
_array.unsafeSetLength(newLength);
}
function length() external view returns (uint256) {
return _array.length;
}
}
contract AddressArraysMock {
using Arrays for address[];
address[] private _array;
constructor(address[] memory array) {
_array = array;
}
function unsafeAccess(uint256 pos) external view returns (address) {
return _array.unsafeAccess(pos).value;
}
function sort(address[] memory array) external pure returns (address[] memory) {
return array.sort();
}
function sortReverse(address[] memory array) external pure returns (address[] memory) {
return array.sort(_reverse);
}
function _reverse(address a, address b) private pure returns (bool) {
return uint160(a) > uint160(b);
}
function unsafeSetLength(uint256 newLength) external {
_array.unsafeSetLength(newLength);
}
function length() external view returns (uint256) {
return _array.length;
}
}
contract Bytes32ArraysMock {
using Arrays for bytes32[];
bytes32[] private _array;
constructor(bytes32[] memory array) {
_array = array;
}
function unsafeAccess(uint256 pos) external view returns (bytes32) {
return _array.unsafeAccess(pos).value;
}
function sort(bytes32[] memory array) external pure returns (bytes32[] memory) {
return array.sort();
}
function sortReverse(bytes32[] memory array) external pure returns (bytes32[] memory) {
return array.sort(_reverse);
}
function _reverse(bytes32 a, bytes32 b) private pure returns (bool) {
return uint256(a) > uint256(b);
}
function unsafeSetLength(uint256 newLength) external {
_array.unsafeSetLength(newLength);
}
function length() external view returns (uint256) {
return _array.length;
}
}