function getValue(uint256 _id) external view returns (uint256)
An utility library for working with sorted linked list data structures in your Solidity project.
struct List {
uint256 size;
mapping(uint256 => mapping(bool => uint256)) list;
}
function insertAfter(struct StructuredLinkedList.List self, uint256 _node, uint256 _new) internal returns (bool)
Insert node _new
beside existing node _node
in direction _NEXT
.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Existing node. |
_new |
uint256 |
New node to insert. |
Name |
Type |
Description |
[0] |
bool |
bool True if success, false otherwise. |
function insertBefore(struct StructuredLinkedList.List self, uint256 _node, uint256 _new) internal returns (bool)
Insert node _new
beside existing node _node
in direction _PREV
.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Existing node. |
_new |
uint256 |
New node to insert. |
Name |
Type |
Description |
[0] |
bool |
bool True if success, false otherwise. |
function remove(struct StructuredLinkedList.List self, uint256 _node) internal returns (uint256)
Removes an entry from the linked list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Node to remove from the list. |
Name |
Type |
Description |
[0] |
uint256 |
uint256 The removed node. |
function pushFront(struct StructuredLinkedList.List self, uint256 _node) internal returns (bool)
Pushes an entry to the head of the linked list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
New entry to push to the head. |
Name |
Type |
Description |
[0] |
bool |
bool True if success, false otherwise. |
function pushBack(struct StructuredLinkedList.List self, uint256 _node) internal returns (bool)
Pushes an entry to the tail of the linked list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
New entry to push to the tail. |
Name |
Type |
Description |
[0] |
bool |
bool True if success, false otherwise. |
function popFront(struct StructuredLinkedList.List self) internal returns (uint256)
Pops the first entry from the head of the linked list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
Name |
Type |
Description |
[0] |
uint256 |
uint256 The removed node. |
function popBack(struct StructuredLinkedList.List self) internal returns (uint256)
Pops the first entry from the tail of the linked list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
Name |
Type |
Description |
[0] |
uint256 |
uint256 The removed node. |
function listExists(struct StructuredLinkedList.List self) internal view returns (bool)
Checks if the list exists.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
Name |
Type |
Description |
[0] |
bool |
bool True if list exists, false otherwise. |
function nodeExists(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool)
Checks if the node exists.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
A node to search for. |
Name |
Type |
Description |
[0] |
bool |
bool True if node exists, false otherwise. |
function sizeOf(struct StructuredLinkedList.List self) internal view returns (uint256)
Returns the number of elements in the list.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
Name |
Type |
Description |
[0] |
uint256 |
uint256 The size of the list. |
function getNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256, uint256)
Returns the links of a node as a tuple.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Id of the node to get. |
Name |
Type |
Description |
[0] |
bool |
bool, uint256, uint256 True if node exists or false otherwise, previous node, next node. |
[1] |
uint256 |
|
[2] |
uint256 |
|
function getAdjacent(struct StructuredLinkedList.List self, uint256 _node, bool _direction) internal view returns (bool, uint256)
Returns the link of a node _node
in direction _direction
.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Id of the node to step from. |
_direction |
bool |
Direction to step in. |
Name |
Type |
Description |
[0] |
bool |
bool, uint256 True if node exists or false otherwise, node in _direction. |
[1] |
uint256 |
|
function getNextNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256)
Returns the link of a node _node
in direction _NEXT
.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Id of the node to step from. |
Name |
Type |
Description |
[0] |
bool |
bool, uint256 True if node exists or false otherwise, next node. |
[1] |
uint256 |
|
function getPreviousNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256)
Returns the link of a node _node
in direction _PREV
.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_node |
uint256 |
Id of the node to step from. |
Name |
Type |
Description |
[0] |
bool |
bool, uint256 True if node exists or false otherwise, previous node. |
[1] |
uint256 |
|
function getSortedSpot(struct StructuredLinkedList.List self, address _structure, uint256 _value) internal view returns (uint256)
Can be used before insert
to build an ordered list.
Get the node and then insertBefore
or insertAfter
basing on your list order.
If you want to order basing on other than structure.getValue()
override this function.
Name |
Type |
Description |
self |
struct StructuredLinkedList.List |
Stored linked list from contract. |
_structure |
address |
The structure instance. |
_value |
uint256 |
Value to seek. |
Name |
Type |
Description |
[0] |
uint256 |
uint256 Next node with a value less than _value. |