Hi everyone!

In this thread we want to assess the need for data structure libraries in OpenZeppelin, and to gather ideas for what those libraries could look like.

After seeing many many simple implementation errors that translate to catastrophic failures, we think it may be worth it to pursue this feature, even if language support for it is not where we want it to be yet. We have some ideas regarding which patterns are useful in a blockchain-context, but would like for developers to share their ideas, use-cases, and experience working with these.

As an example, a pattern we’ve successfully used is the swap-and-pop for deletion of array elements (where array order is mutable and unimportant, e.g. unsorted arrays). See the following pseudo implementation:

uint256[] private _array; function delete(uint256 index) public { uint256 _array[index] = _array[_array.length.sub(1)]; _array.length--; }

OpenZeppelin’s ERC721Enumerable 's code uses this pattern in a more involved way, since a mapping of indexes is also updated, and while the code is somewhat complex, it is very gas efficient. We’d like to make this sort of thing reusable so that everyone can also have correct, inexpensive algorithms in their contracts.

Looking forward to hear everyone’s thoughts!