Skip to content

Commit 3840533

Browse files
authored
Merge pull request #121 from HQ20/unrelease/lists/ordered
Moved OrderedList.sol to drafts due to coverage.
2 parents f440135 + 5731c28 commit 3840533

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Lists
2+
3+
This is an Ethereum project that implements an ordered doubly linked list (https://en.wikipedia.org/wiki/Linked_list).
4+
5+
# Terminology
6+
Object: Objects are linked to each other and together they are a Linked List
7+
Head: The first object in the list. No other object points to the head.
8+
Tail: The last object in the list. The tail points to no other object.
9+
Data: In this contract the data is an Ethereum address, which can be used for any purpose.
10+
11+
# Implementation
12+
Solidity doesn't support recursive type references, as in:
13+
```
14+
struct Object {
15+
Object nextObject;
16+
}
17+
```
18+
This renders a traditional implementation of Linked Lists impossible. In this implementation all Objects are given an id and stored in a mapping instead. This results in an extra inefficiency of doing an extra mapping lookup when following a link between objects.
19+
20+
## Usage
21+
22+
`OrderedList.sol`: Doubly Linked List, sorted by `rank` descending from the head.
23+
* constructor: Creates an empty list.
24+
* `function get(uint256 _id)`: Retrieves the Object denoted by `_id`.
25+
* `function findRank(uint256 _rank)`: Return the id of the first Object with a lower or equal `_rank`, starting from the head.
26+
* `function insert(uint256 _rank, address _data)`: Insert a new Object immediately before the one with the closest lower `_rank`.
27+
* `function remove(uint256 _id)`: Remove the Object denoted by `_id` from the List.
28+
* `function _addHead(address _data)`: Insert a new Object as the new Head with `_data` in the data field.
29+
* `function _addTail(address _data)`: Insert a new Object as the new Tail with `_data` in the data field.
30+
* `function _insertAfter(uint256 _prevId, address _data)`: Insert a new Object after the Object denoted by `_id` with `_data` in the data field.
31+
* `function _insertBefore(uint256 _nextId, address _data)`: Insert a new Object before the Object denoted by `_id` with `_data` in the data field.
32+
* `function _setHead(uint256 _id)`: Internal function to update the Head pointer.
33+
* `function _createObject(address _data)`: Internal function to create an unlinked Object.
34+
* `function _link(uint256 _prevId, uint256 _nextId)`: Internal function to link an Object to another.
35+
File renamed without changes.

contracts/lists/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,3 @@ This renders a traditional implementation of Linked Lists impossible. In this im
4747
* `function _createObject(address _data)`: Internal function to create an unlinked Object.
4848
* `function _link(uint256 _prevId, uint256 _nextId)`: Internal function to link an Object to another.
4949

50-
`OrderedList.sol`: Doubly Linked List, sorted by `rank` descending from the head.
51-
* constructor: Creates an empty list.
52-
* `function get(uint256 _id)`: Retrieves the Object denoted by `_id`.
53-
* `function findRank(uint256 _rank)`: Return the id of the first Object with a lower or equal `_rank`, starting from the head.
54-
* `function insert(uint256 _rank, address _data)`: Insert a new Object immediately before the one with the closest lower `_rank`.
55-
* `function remove(uint256 _id)`: Remove the Object denoted by `_id` from the List.
56-
* `function _addHead(address _data)`: Insert a new Object as the new Head with `_data` in the data field.
57-
* `function _addTail(address _data)`: Insert a new Object as the new Tail with `_data` in the data field.
58-
* `function _insertAfter(uint256 _prevId, address _data)`: Insert a new Object after the Object denoted by `_id` with `_data` in the data field.
59-
* `function _insertBefore(uint256 _nextId, address _data)`: Insert a new Object before the Object denoted by `_id` with `_data` in the data field.
60-
* `function _setHead(uint256 _id)`: Internal function to update the Head pointer.
61-
* `function _createObject(address _data)`: Internal function to create an unlinked Object.
62-
* `function _link(uint256 _prevId, uint256 _nextId)`: Internal function to link an Object to another.
63-
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { should } from 'chai';
2-
import { OrderedListMockInstance } from '../../types/truffle-contracts';
2+
import { OrderedListMockInstance } from '../../../types/truffle-contracts';
33

44
const OrderedList = artifacts
5-
.require('./lists/mocks/OrderedListMock.sol') as Truffle.Contract<OrderedListMockInstance>;
5+
.require('./drafts/lists/mocks/OrderedListMock.sol') as Truffle.Contract<OrderedListMockInstance>;
66
should();
77

88
const emptyData = '0x0000000000000000000000000000000000000000';

0 commit comments

Comments
 (0)