Try it Live
Run Address examples in the interactive playground
- C
C API - Manual Implementation Required
The C API currently providesprimitives_address_equals() but not a three-way comparison. Implement lexicographic comparison manually:Example:memcmp for byte-level comparison:Comparison Semantics
Lexicographic ordering: Compares byte-by-byte from left to right (big-endian). Return values:-1: First address is less than second0: Addresses are equal1: First address is greater than second
Use Cases
Sorting Arrays
Sort addresses in ascending or descending order:Binary Search
Efficient lookup in sorted arrays:Ordered Sets
Maintain addresses in sorted order:Range Queries
Find addresses within a range:Merkle Trees
Build ordered merkle trees using address ordering:Performance
Time complexity: O(n) where n = 20 bytes (constant time for addresses) Implementation: Compares byte-by-byte until difference found or end reached Early termination: Stops at first differing byte For large-scale sorting, consider converting to hex once:Relation to Other Comparisons
Sorting Examples
Sort transaction list by sender:
Group addresses by range:
See Also
- equals - Equality comparison
- lessThan - Less than comparison
- greaterThan - Greater than comparison

