Skip to content

Commit

Permalink
Added lib docs (#27)
Browse files Browse the repository at this point in the history
* added docs

* fix
  • Loading branch information
dovgopoly authored Mar 15, 2024
1 parent 14974fe commit d986887
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 1 deletion.
14 changes: 14 additions & 0 deletions docs/getting-started/guides/libs/arrays/array-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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_,
Expand Down
124 changes: 123 additions & 1 deletion docs/getting-started/guides/libs/arrays/set-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,73 @@ 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;
```

#### 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

Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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"
```

0 comments on commit d986887

Please sign in to comment.