Unique Sorting in Solidity using Value Arrays

This article considers using value arrays to improve sorting in Solidity, the defacto smart contract language for the Ethereum blockchain.

Jules Goddard
Coinmonks
Published in
5 min readAug 31, 2020

--

Photo by the author

Background

In my article “Sorting in Solidity without Comparison”, I compared various sorting techniques on Solidity memory arrays. In summary, my conclusion, according to the provided code, data and tests, was that the Unique Sort on dynamic uint memory arrays was most suitable for my particular application. If you need to sort Solidity storage arrays, consider the article “Shadowing Solidity Storage Variables in Memory” which illustrates the best technique.

Following my further articles “Value Arrays in Solidity” and “Dynamic Value Arrays in Solidity”, I revisit the Unique Sort algorithm here, to determine whether using value arrays can improve performance further.

Discussion

A Value Array is simply an array held in a value type, as opposed to a reference array. Solidity runs on the Ethereum Virtual Machine (EVM) which has a very large machine word of 256bits (32bytes). It is this latter feature that enables us to consider using Value Arrays.

--

--

Jules Goddard
Coinmonks

Experienced high-integrity software engineer, crypto code compactor and Datona Labs founder — providing smart contracts to protect your digital information.