ArraysMock.sol 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {Arrays} from "../utils/Arrays.sol";
  4. contract Uint256ArraysMock {
  5. using Arrays for uint256[];
  6. uint256[] private _array;
  7. constructor(uint256[] memory array) {
  8. _array = array;
  9. }
  10. function findUpperBound(uint256 value) external view returns (uint256) {
  11. return _array.findUpperBound(value);
  12. }
  13. function lowerBound(uint256 value) external view returns (uint256) {
  14. return _array.lowerBound(value);
  15. }
  16. function upperBound(uint256 value) external view returns (uint256) {
  17. return _array.upperBound(value);
  18. }
  19. function lowerBoundMemory(uint256[] memory array, uint256 value) external pure returns (uint256) {
  20. return array.lowerBoundMemory(value);
  21. }
  22. function upperBoundMemory(uint256[] memory array, uint256 value) external pure returns (uint256) {
  23. return array.upperBoundMemory(value);
  24. }
  25. function unsafeAccess(uint256 pos) external view returns (uint256) {
  26. return _array.unsafeAccess(pos).value;
  27. }
  28. function sort(uint256[] memory array) external pure returns (uint256[] memory) {
  29. return array.sort();
  30. }
  31. function sortReverse(uint256[] memory array) external pure returns (uint256[] memory) {
  32. return array.sort(_reverse);
  33. }
  34. function _reverse(uint256 a, uint256 b) private pure returns (bool) {
  35. return a > b;
  36. }
  37. }
  38. contract AddressArraysMock {
  39. using Arrays for address[];
  40. address[] private _array;
  41. constructor(address[] memory array) {
  42. _array = array;
  43. }
  44. function unsafeAccess(uint256 pos) external view returns (address) {
  45. return _array.unsafeAccess(pos).value;
  46. }
  47. function sort(address[] memory array) external pure returns (address[] memory) {
  48. return array.sort();
  49. }
  50. function sortReverse(address[] memory array) external pure returns (address[] memory) {
  51. return array.sort(_reverse);
  52. }
  53. function _reverse(address a, address b) private pure returns (bool) {
  54. return uint160(a) > uint160(b);
  55. }
  56. }
  57. contract Bytes32ArraysMock {
  58. using Arrays for bytes32[];
  59. bytes32[] private _array;
  60. constructor(bytes32[] memory array) {
  61. _array = array;
  62. }
  63. function unsafeAccess(uint256 pos) external view returns (bytes32) {
  64. return _array.unsafeAccess(pos).value;
  65. }
  66. function sort(bytes32[] memory array) external pure returns (bytes32[] memory) {
  67. return array.sort();
  68. }
  69. function sortReverse(bytes32[] memory array) external pure returns (bytes32[] memory) {
  70. return array.sort(_reverse);
  71. }
  72. function _reverse(bytes32 a, bytes32 b) private pure returns (bool) {
  73. return uint256(a) > uint256(b);
  74. }
  75. }