# LinkedIdList.sol

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/649b450f02fc8b735c128ff0821467e71966c666/src/modules/lib/LinkedIdList.sol)

### State Variables

#### \_SENTINEL

*Marks the beginning of the list.*

*Unrealistic to have that many ids.*

```solidity
uint internal constant _SENTINEL = type(uint).max;
```

### Functions

#### validNewId

*Modifier to guarantee the given new id is valid.*

```solidity
modifier validNewId(List storage self, uint id);
```

#### validId

*Modifier to guarantee the given id is valid.*

```solidity
modifier validId(List storage self, uint id);
```

#### validPosition

*Modifier to guarantee the given position is valid.*

```solidity
modifier validPosition(List storage self, uint id);
```

#### onlyConsecutiveIds

*Modifier to guarantee the given ids are consecutive.*

```solidity
modifier onlyConsecutiveIds(List storage self, uint prevId, uint id);
```

#### validMoveParameter

*`prevId` is checked by consecutiveId to be valid*

```solidity
modifier validMoveParameter(
    List storage self,
    uint id,
    uint prevId,
    uint idToPositionAfter
);
```

#### init

*should never be called more than once*

```solidity
function init(List storage self) internal;
```

#### length

```solidity
function length(List storage self) internal view returns (uint);
```

#### lastId

*Returns the last id in*

```solidity
function lastId(List storage self) internal view returns (uint);
```

#### listIds

lists the ids contained in the linked list.

```solidity
function listIds(List storage self) internal view returns (uint[] memory);
```

**Parameters**

| Name   | Type   | Description                                          |
| ------ | ------ | ---------------------------------------------------- |
| `self` | `List` | The linked List from where the ids should be listed. |

**Returns**

| Name     | Type        | Description                                 |
| -------- | ----------- | ------------------------------------------- |
| `<none>` | `uint256[]` | array of ids that are contained in the list |

#### isExistingId

*Returns whether id is in list and not Sentinel*

```solidity
function isExistingId(List storage self, uint id)
    internal
    view
    returns (bool);
```

**Parameters**

| Name   | Type      | Description                                          |
| ------ | --------- | ---------------------------------------------------- |
| `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*

```solidity
function getPreviousId(List storage self, uint id)
    internal
    view
    validPosition(self, id)
    returns (uint prevId);
```

**Parameters**

| Name   | Type      | Description                                          |
| ------ | --------- | ---------------------------------------------------- |
| `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*

```solidity
function getNextId(List storage self, uint id)
    internal
    view
    validPosition(self, id)
    returns (uint nextId);
```

**Parameters**

| Name   | Type      | Description                                    |
| ------ | --------- | ---------------------------------------------- |
| `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*

```solidity
function addId(List storage self, uint id) internal validNewId(self, id);
```

**Parameters**

| Name   | Type      | Description                             |
| ------ | --------- | --------------------------------------- |
| `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.*

```solidity
function removeId(List storage self, uint prevId, uint id)
    internal
    validId(self, id)
    onlyConsecutiveIds(self, prevId, id);
```

**Parameters**

| Name     | Type      | Description                                  |
| -------- | --------- | -------------------------------------------- |
| `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*

```solidity
function moveIdInList(
    List storage self,
    uint id,
    uint prevId,
    uint idToPositionAfter
) internal validMoveParameter(self, id, prevId, idToPositionAfter);
```

**Parameters**

| Name                | Type      | Description                              |
| ------------------- | --------- | ---------------------------------------- |
| `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.

```solidity
error Library__LinkedIdList__InvalidId();
```

#### Library\_\_LinkedIdList\_\_InvalidNewId

Given new id invalid.

```solidity
error Library__LinkedIdList__InvalidNewId();
```

#### Library\_\_LinkedIdList\_\_InvalidPosition

Given position in list is invalid.

```solidity
error Library__LinkedIdList__InvalidPosition();
```

#### Library\_\_LinkedIdList\_\_IdNotConsecutive

Given ids are not consecutive.

```solidity
error Library__LinkedIdList__IdNotConsecutive();
```

#### Library\_\_LinkedIdList\_\_InvalidIntermediatePosition

Given ids are not consecutive.

```solidity
error Library__LinkedIdList__InvalidIntermediatePosition();
```

### Structs

#### List

Struct used to store information about an element in the list.

```solidity
struct List {
    uint size;
    uint last;
    mapping(uint => uint) list;
}
```

**Properties**

| Name   | Type                          | Description |
| ------ | ----------------------------- | ----------- |
| `size` | `uint256`                     |             |
| `last` | `uint256`                     |             |
| `list` | `mapping(uint256 => uint256)` |             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inverter.network/contracts/technical-reference/modules/lib/linkedidlist.sol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
