According to solidity docs the type address
has the following operators:
<=, <, ==, !=, >= and >
Besides checking for equality - Why would I want to check if an address is greater or smaller than another one? What is the usecase?
According to solidity docs the type address
has the following operators:
<=, <, ==, !=, >= and >
Besides checking for equality - Why would I want to check if an address is greater or smaller than another one? What is the usecase?
An address
is a 20 byte number, so it gets comparison operators for free: Solidity doesn't have to implement anything, and the gas costs for using them are the same as comparing integers.
In the future, the comparison operators might be useful depending on how sharding in Ethereum works. For example, one of the simplest and early ideas was to shard according to address space, like shard1 contains the first billion addresses, shard2 contains the next billion, and so on. A contract might then use the comparison operators to determine which shard another contract was in.
They can be used to create things like binary trees which can speed up lookups for collections that are not mapped explicitly, and reduce the number of operations it takes to retrieve a record.