Skip to content

UintArrayUtils

Overview

License: MIT

library UintArrayUtils

Functions info

indexOf

function indexOf(
    uint256[] memory A,
    uint256 a
) internal pure returns (uint256, bool)

Finds the index of the first occurrence of the given element.

Parameters:

NameTypeDescription
Auint256[]The input array to search
auint256The value to find

Return values:

NameTypeDescription
[0]uint256Returns (index and isIn) for the first occurrence starting from index 0

contains

function contains(uint256[] memory A, uint256 a) internal pure returns (bool)

Returns true if the value is present in the list. Uses indexOf internally.

Parameters:

NameTypeDescription
Auint256[]The input array to search
auint256The value to find

Return values:

NameTypeDescription
[0]boolReturns isIn for the first occurrence starting from index 0

difference

function difference(
    uint256[] memory A,
    uint256[] memory B
) internal pure returns (uint256[] memory)

Computes the difference of two arrays. Assumes there are no duplicates.

Parameters:

NameTypeDescription
Auint256[]The first array
Buint256[]The second array

Return values:

NameTypeDescription
[0]uint256[]A - B; an array of values in A not found in B.

intersect

function intersect(
    uint256[] memory A,
    uint256[] memory B
) internal pure returns (uint256[] memory)

Returns the intersection of two arrays. Arrays are treated as collections, so duplicates are kept.

Parameters:

NameTypeDescription
Auint256[]The first array
Buint256[]The second array

Return values:

NameTypeDescription
[0]uint256[]The intersection of the two arrays

extend

function extend(
    uint256[] memory A,
    uint256[] memory B
) internal pure returns (uint256[] memory)

Returns the combination of two arrays

Parameters:

NameTypeDescription
Auint256[]The first array
Buint256[]The second array

Return values:

NameTypeDescription
[0]uint256[]Returns A extended by B