Me gustaría implementar una lista enlazada en el almacenamiento de contratos
Algo vincula esto:
contract A {
struct LinkedList {
uint value;
LinkedList storage next; // What goes here? Can I reference the storage of the next struct in solidity?
}
}
Dentro de su estructura, querrá realizar un seguimiento del siguiente elemento de la lista.
struct LinkedList {
bytes32 next;
uint value;
}
Luego, realice un seguimiento de la longitud + el encabezado de la lista y almacene las estructuras en un mapeo con sus ID
uint public length;
bytes32 public head;
mapping (bytes32 => LinkedList) public listObjects;
Puede agregar entradas como esta:
function addEntry(uint _number) public returns (bool) {
LinkedList memory object = LinkedList(head,_number);
bytes32 id = sha3(_number, length, block.timestamp);
listObjects[id] = object;
head = id;
length++;
}
No necesita una lista vinculada porque las matrices en Solidity se expanden automáticamente y esto solo agregaría una sobrecarga de ejecución de gas.