From d986887949aee2a674e77babc715840ed490088e Mon Sep 17 00:00:00 2001 From: dovgopoly <69435717+dovgopoly@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:50:38 +0200 Subject: [PATCH] Added lib docs (#27) * added docs * fix --- .../guides/libs/arrays/array-helper.md | 14 ++ .../guides/libs/arrays/set-helper.md | 124 +++++++++++++++++- 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/guides/libs/arrays/array-helper.md b/docs/getting-started/guides/libs/arrays/array-helper.md index a92c128..f9cecab 100644 --- a/docs/getting-started/guides/libs/arrays/array-helper.md +++ b/docs/getting-started/guides/libs/arrays/array-helper.md @@ -146,6 +146,12 @@ function reverse( ) internal pure returns (address[] memory reversed_); ``` +```solidity +function reverse( + bool[] memory arr_ +) internal pure returns (address[] memory reversed_); +``` + ```solidity function reverse( string[] memory arr_ @@ -197,6 +203,14 @@ function insert( ) internal pure returns (uint256); ``` +```solidity +function insert( + bool[] memory to_, + uint256 index_, + bool[] memory what_ +) internal pure returns (uint256); +``` + ```solidity function insert( string[] memory to_, diff --git a/docs/getting-started/guides/libs/arrays/set-helper.md b/docs/getting-started/guides/libs/arrays/set-helper.md index 5b2e76b..f290bc8 100644 --- a/docs/getting-started/guides/libs/arrays/set-helper.md +++ b/docs/getting-started/guides/libs/arrays/set-helper.md @@ -36,6 +36,65 @@ function add( ```solidity function add( + EnumerableSet.Bytes32Set storage set, + bytes32[] memory array_ +) internal; +``` + +```solidity +function add( + StringSet.Set storage set, + string[] memory array_ +) internal; +``` + +#### Description + +This function adds the provided `array_` to the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array. + +#### Time complexity + +Linear. + +#### Example + +```solidity +EnumerableSet.UintSet public nums; +nums.add(1); +nums.add(2); + +uint256[] memory arr_ = new uint256[](2); +arr_[0] = 3; +arr_[1] = 4; + +nums.add(arr_); // [1, 2, 3, 4] +``` + +### strictAdd + +```solidity +function strictAdd( + EnumerableSet.AddressSet storage set, + address[] memory array_ +) internal; +``` + +```solidity +function strictAdd( + EnumerableSet.UintSet storage set, + uint256[] memory array_ +) internal; +``` + +```solidity +function strictAdd( + EnumerableSet.Bytes32Set storage set, + bytes32[] memory array_ +) internal; +``` + +```solidity +function strictAdd( StringSet.Set storage set, string[] memory array_ ) internal; @@ -43,7 +102,7 @@ function add( #### Description -This function adds the provided `array_` to the provided `set`. +This function strictly adds the provided `array_` to the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array. Reverts if elements duplicate. #### Time complexity @@ -61,6 +120,7 @@ arr_[0] = 3; arr_[1] = 4; nums.add(arr_); // [1, 2, 3, 4] +nums.add(arr_); // Reverts with: "SetHelper: element already exists" ``` ### remove @@ -79,6 +139,13 @@ function remove( ) internal; ``` +```solidity +function remove( + EnumerableSet.Bytes32Set storage set, + bytes32[] memory array_ +) internal; +``` + ```solidity function remove( StringSet.Set storage set, @@ -111,3 +178,58 @@ arr_[3] = 10; nums.remove(arr_); // [2, 4] ``` + +### strictRemove + +```solidity +function strictRemove( + EnumerableSet.AddressSet storage set, + address[] memory array_ +) internal; +``` + +```solidity +function strictRemove( + EnumerableSet.UintSet storage set, + uint256[] memory array_ +) internal; +``` + +```solidity +function strictRemove( + EnumerableSet.Bytes32Set storage set, + bytes32[] memory array_ +) internal; +``` + +```solidity +function strictRemove( + StringSet.Set storage set, + string[] memory array_ +) internal; +``` + +#### Description + +This function strictly removes the provided `array_` from the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array. Reverts if set doesn't contain provided elements. + +#### Time complexity + +Linear. + +#### Example + +```solidity +EnumerableSet.UintSet public nums; +nums.add(1); +nums.add(2); +nums.add(3); +nums.add(4); + +uint256[] memory arr_ = new uint256[](4); +arr_[0] = 1; +arr_[1] = 3; + +nums.remove(arr_); // [2, 4] +nums.remove(arr_); // Reverts with: "SetHelper: no such element" +```