```\nfunction _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {\n    // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and\n    // then delete the last slot (swap and pop).\n\n    uint256 lastTokenIndex = _allTokens.length - 1;\n    uint256 tokenIndex = _allTokensIndex[tokenId];\n\n    // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so\n    // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding\n    // an 'if' statement (like in _removeTokenFromOwnerEnumeration)\n    uint256 lastTokenId = _allTokens[lastTokenIndex];\n\n    _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token\n    _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index\n\n    // This also deletes the contents at the last position of the array\n    delete _allTokensIndex[tokenId];\n    _allTokens.pop();\n}\n```\n