Skip to main content

SetStorage

Git Source

This struct is used to store the set data.

To optimize the gas consumption, firstElement is stored in the same storage slot as the numElements

so that for sets with one element, only one storage slot has to be read/written. To keep the elements

array indexing consistent and because the first element is stored outside of the array, the elements[0]

is not utilized. The stamp field is used to keep the storage slot non-zero when the element is removed.

It allows for cheaper SSTORE when an element is inserted.

struct SetStorage {
uint8 numElements;
address firstElement;
uint80 metadata;
uint8 stamp;
ElementStorage[SET_MAX_ELEMENTS] elements;
}