- (EnumerableBytes4Set.sol)
View Source: contracts/mixins/EnumerableBytes4Set.sol
Sets have the following properties:
-
- Elements are added, removed, and checked for existence in constant time (O(1)).
- Elements are enumerated in O(n). No guarantees are made on the ordering.
- Include with
using EnumerableBytes4Set for EnumerableBytes4Set.Bytes4Set;
.
struct Bytes4Set {
mapping(bytes4 => uint256) index,
bytes4[] values
}
- addBytes4(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value)
- removeBytes4(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value)
- contains(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value)
- enumerate(struct EnumerableBytes4Set.Bytes4Set set, uint256 start, uint256 count)
- length(struct EnumerableBytes4Set.Bytes4Set set)
- get(struct EnumerableBytes4Set.Bytes4Set set, uint256 index)
Add a value to a set. O(1). *
function addBytes4(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value) internal nonpayable
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. |
value | bytes4 | The new value to add. * |
Returns
False if the value was already in the set.
Source Code
function addBytes4(Bytes4Set storage set, bytes4 value) internal returns (bool) {
if (!contains(set, value)) {
set.index[value] = set.values.push(value);
return true;
} else {
return false;
}
}
Remove a value from a set. O(1). *
function removeBytes4(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value) internal nonpayable
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. |
value | bytes4 | The value to remove. * |
Returns
False if the value was not present in the set.
Source Code
function removeBytes4(Bytes4Set storage set, bytes4 value) internal returns (bool) {
if (contains(set, value)) {
uint256 toDeleteIndex = set.index[value] - 1;
uint256 lastIndex = set.values.length - 1;
/// If the element we're deleting is the last one,
/// we can just remove it without doing a swap.
if (lastIndex != toDeleteIndex) {
bytes4 lastValue = set.values[lastIndex];
/// Move the last value to the index where the deleted value is.
set.values[toDeleteIndex] = lastValue;
/// Update the index for the moved value.
set.index[lastValue] = toDeleteIndex + 1; // All indexes are 1-based
}
/// Delete the index entry for the deleted value.
delete set.index[value];
/// Delete the old entry for the moved value.
set.values.pop();
return true;
} else {
return false;
}
}
Find out whether a value exists in the set. *
function contains(struct EnumerableBytes4Set.Bytes4Set set, bytes4 value) internal view
returns(bool)
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. |
value | bytes4 | The value to find. * |
Returns
True if the value is in the set. O(1).
Source Code
function contains(Bytes4Set storage set, bytes4 value) internal view returns (bool) {
return set.index[value] != 0;
}
Get all set values. *
function enumerate(struct EnumerableBytes4Set.Bytes4Set set, uint256 start, uint256 count) internal view
returns(output bytes4[])
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. |
start | uint256 | The offset of the returning set. |
count | uint256 | The limit of number of values to return. * |
Returns
An array with all values in the set. O(N). *
Source Code
function enumerate(
Bytes4Set storage set,
uint256 start,
uint256 count
) internal view returns (bytes4[] memory output) {
uint256 end = start + count;
require(end >= start, "addition overflow");
end = set.values.length < end ? set.values.length : end;
if (end == 0 || start >= end) {
return output;
}
output = new bytes4[](end - start);
for (uint256 i; i < end - start; i++) {
output[i] = set.values[i + start];
}
return output;
}
Get the legth of the set. *
function length(struct EnumerableBytes4Set.Bytes4Set set) internal view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. * |
Returns
the number of elements on the set. O(1).
Source Code
function length(Bytes4Set storage set) internal view returns (uint256) {
return set.values.length;
}
Get an item from the set by its index. *
function get(struct EnumerableBytes4Set.Bytes4Set set, uint256 index) internal view
returns(bytes4)
Arguments
Name | Type | Description |
---|---|---|
set | struct EnumerableBytes4Set.Bytes4Set | The set of values. |
index | uint256 | The index of the value to return. * |
Returns
the element stored at position index
in the set. O(1).
Source Code
function get(Bytes4Set storage set, uint256 index) internal view returns (bytes4) {
return set.values[index];
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC