Skip to content

Latest commit

 

History

History
65 lines (42 loc) · 1.38 KB

README.md

File metadata and controls

65 lines (42 loc) · 1.38 KB

Array Util

Library for Array


Lib for solidity arrays.

Installation

forge install grappafinance/[email protected] --no-commit

Add to remapping.txt

array-lib=lib/array-lib/src

Usage

Array Utils

import {UintArrayLib} from "array-lib/UintArrayLib.sol";

using UintArrayLib for uint256[];

function zeroSum(uint256[] memory arr) internal pure returns (bool) {
  return arr.sum() == 0;
}

Sorting

import {QuickSort} from "array-lib/sorting/QuickSort.sol";

using QuickSort for uint256[];

function calculateSomethingHard() internal pure returns (bool) {
  uint256[] memory arr = _getArr();

  // get a new sorting array
  uint256[] sorted = arr.getSorted();

  // sort in memory
  arr.sort();

  
}