LinkedIdList.sol
State Variables
_SENTINEL
Marks the beginning of the list.
Unrealistic to have that many ids.
uint internal constant _SENTINEL = type(uint).max;
Functions
validNewId
Modifier to guarantee the given new id is valid.
modifier validNewId(List storage self, uint id);
validId
Modifier to guarantee the given id is valid.
modifier validId(List storage self, uint id);
validPosition
Modifier to guarantee the given position is valid.
modifier validPosition(List storage self, uint id);
onlyConsecutiveIds
Modifier to guarantee the given ids are consecutive.
modifier onlyConsecutiveIds(List storage self, uint prevId, uint id);
validMoveParameter
prevId
is checked by consecutiveId to be valid
modifier validMoveParameter(
List storage self,
uint id,
uint prevId,
uint idToPositionAfter
);
init
should never be called more than once
function init(List storage self) internal;
length
function length(List storage self) internal view returns (uint);
lastId
Returns the last id in
function lastId(List storage self) internal view returns (uint);
listIds
lists the ids contained in the linked list.
function listIds(List storage self) internal view returns (uint[] memory);
Parameters
self
List
The linked List from where the ids should be listed.
Returns
<none>
uint256[]
array of ids that are contained in the list
isExistingId
Returns whether id is in list and not Sentinel
function isExistingId(List storage self, uint id)
internal
view
returns (bool);
Parameters
self
List
The linked List from where the ids should be listed.
id
uint256
The id to check.
getPreviousId
Id and prevId can be _SENTINEL
function getPreviousId(List storage self, uint id)
internal
view
validPosition(self, id)
returns (uint prevId);
Parameters
self
List
The linked List from where the ids should be listed.
id
uint256
The id to check.
getNextId
Id and nextId can be _SENTINEL
function getNextId(List storage self, uint id)
internal
view
validPosition(self, id)
returns (uint nextId);
Parameters
self
List
The linked List from which to get the next id.
id
uint256
The id to check.
addId
Add To list at last position
function addId(List storage self, uint id) internal validNewId(self, id);
Parameters
self
List
The linked List to which to add the id.
id
uint256
The id to add.
removeId
Remove Id from list and decrease size.
function removeId(List storage self, uint prevId, uint id)
internal
validId(self, id)
onlyConsecutiveIds(self, prevId, id);
Parameters
self
List
The linked List from which to remove the id.
prevId
uint256
The id of the previous id.
id
uint256
The id to remove.
moveIdInList
Move id in list
function moveIdInList(
List storage self,
uint id,
uint prevId,
uint idToPositionAfter
) internal validMoveParameter(self, id, prevId, idToPositionAfter);
Parameters
self
List
The linked List in which to move the id.
id
uint256
The id to move.
prevId
uint256
The id of the previous id.
idToPositionAfter
uint256
The id to position after.
Errors
Library__LinkedIdList__InvalidId
Given id invalid.
error Library__LinkedIdList__InvalidId();
Library__LinkedIdList__InvalidNewId
Given new id invalid.
error Library__LinkedIdList__InvalidNewId();
Library__LinkedIdList__InvalidPosition
Given position in list is invalid.
error Library__LinkedIdList__InvalidPosition();
Library__LinkedIdList__IdNotConsecutive
Given ids are not consecutive.
error Library__LinkedIdList__IdNotConsecutive();
Library__LinkedIdList__InvalidIntermediatePosition
Given ids are not consecutive.
error Library__LinkedIdList__InvalidIntermediatePosition();
Structs
List
Struct used to store information about an element in the list.
struct List {
uint size;
uint last;
mapping(uint => uint) list;
}
Properties
size
uint256
last
uint256
list
mapping(uint256 => uint256)
Last updated