Solidity – How to Clear OpenZeppelin Enumerable Map

openzeppelinsolidity

Supposed I have an enumerable map, now I want to clear it so it doesn't contain any element. What is the most gas efficient way to do that?

Best Answer

The EnumerableMap uses struct Set to store the data. To reset a struct, you can use the keyword delete to clear all the slots.

function clearSet(Set storage set) public {
    delete set;
}