Skip to content

Latest commit

 

History

History
345 lines (232 loc) · 8.54 KB

index.md

File metadata and controls

345 lines (232 loc) · 8.54 KB

Solidity API

IStructureInterface

getValue

function getValue(uint256 _id) external view returns (uint256)

StructuredLinkedList

An utility library for working with sorted linked list data structures in your Solidity project.

List

struct List {
  uint256 size;
  mapping(uint256 => mapping(bool => uint256)) list;
}

insertAfter

function insertAfter(struct StructuredLinkedList.List self, uint256 _node, uint256 _new) internal returns (bool)

Insert node _new beside existing node _node in direction _NEXT.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Existing node.
_new uint256 New node to insert.

Return Values

Name Type Description
[0] bool bool True if success, false otherwise.

insertBefore

function insertBefore(struct StructuredLinkedList.List self, uint256 _node, uint256 _new) internal returns (bool)

Insert node _new beside existing node _node in direction _PREV.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Existing node.
_new uint256 New node to insert.

Return Values

Name Type Description
[0] bool bool True if success, false otherwise.

remove

function remove(struct StructuredLinkedList.List self, uint256 _node) internal returns (uint256)

Removes an entry from the linked list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Node to remove from the list.

Return Values

Name Type Description
[0] uint256 uint256 The removed node.

pushFront

function pushFront(struct StructuredLinkedList.List self, uint256 _node) internal returns (bool)

Pushes an entry to the head of the linked list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 New entry to push to the head.

Return Values

Name Type Description
[0] bool bool True if success, false otherwise.

pushBack

function pushBack(struct StructuredLinkedList.List self, uint256 _node) internal returns (bool)

Pushes an entry to the tail of the linked list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 New entry to push to the tail.

Return Values

Name Type Description
[0] bool bool True if success, false otherwise.

popFront

function popFront(struct StructuredLinkedList.List self) internal returns (uint256)

Pops the first entry from the head of the linked list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.

Return Values

Name Type Description
[0] uint256 uint256 The removed node.

popBack

function popBack(struct StructuredLinkedList.List self) internal returns (uint256)

Pops the first entry from the tail of the linked list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.

Return Values

Name Type Description
[0] uint256 uint256 The removed node.

listExists

function listExists(struct StructuredLinkedList.List self) internal view returns (bool)

Checks if the list exists.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.

Return Values

Name Type Description
[0] bool bool True if list exists, false otherwise.

nodeExists

function nodeExists(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool)

Checks if the node exists.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 A node to search for.

Return Values

Name Type Description
[0] bool bool True if node exists, false otherwise.

sizeOf

function sizeOf(struct StructuredLinkedList.List self) internal view returns (uint256)

Returns the number of elements in the list.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.

Return Values

Name Type Description
[0] uint256 uint256 The size of the list.

getNode

function getNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256, uint256)

Returns the links of a node as a tuple.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Id of the node to get.

Return Values

Name Type Description
[0] bool bool, uint256, uint256 True if node exists or false otherwise, previous node, next node.
[1] uint256
[2] uint256

getAdjacent

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.

Parameters

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.

Return Values

Name Type Description
[0] bool bool, uint256 True if node exists or false otherwise, node in _direction.
[1] uint256

getNextNode

function getNextNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256)

Returns the link of a node _node in direction _NEXT.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Id of the node to step from.

Return Values

Name Type Description
[0] bool bool, uint256 True if node exists or false otherwise, next node.
[1] uint256

getPreviousNode

function getPreviousNode(struct StructuredLinkedList.List self, uint256 _node) internal view returns (bool, uint256)

Returns the link of a node _node in direction _PREV.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_node uint256 Id of the node to step from.

Return Values

Name Type Description
[0] bool bool, uint256 True if node exists or false otherwise, previous node.
[1] uint256

getSortedSpot

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.

Parameters

Name Type Description
self struct StructuredLinkedList.List Stored linked list from contract.
_structure address The structure instance.
_value uint256 Value to seek.

Return Values

Name Type Description
[0] uint256 uint256 Next node with a value less than _value.