allTokensIndex
allTokensIndex is a storage mapping used in enumerable token contracts to track the position of each token in the allTokens array. In typical ERC721Enumerable-like implementations, the contract maintains an array called _allTokens containing every tokenId currently in existence, and a mapping called _allTokensIndex that maps each tokenId to its index within that array. This pairing enables constant-time lookups of a token’s position and supports enumeration of all tokens via functions like tokenByIndex and totalSupply.
How it works: When a new token is minted, its tokenId is appended to the _allTokens array
Typical usage: tokenByIndex(uint256 index) returns the tokenId at _allTokens[index], and totalSupply() returns the length of _allTokens.
Considerations: Implementing allTokensIndex enables full token enumeration at the cost of additional storage and gas. It