THE STRUGGLE IS REAL

Most siblings fight over who has to help to bring in the groceries, which happens in my family too, but when I was younger, I remember fighting with my sister over who had to bring the grocery bags…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Sorting in Solidity without Comparison

This article discusses the cost of sorting small sets of numbers in Solidity, the defacto smart contract language for the Ethereum blockchain.

During the development and testing of Datona Labs’ Solidity Smart-Data-Access-Contract (S-DAC) templates, we wanted to sort some small sets of small numbers, for example:

Of course we want to use as little gas (few cycles) as possible because blockchain languages like Solidity are very expensive to run compared with normal systems and the gas actually costs a measurable amount of money.

We presumed that the complexities of Quick Sort would be overkill for sorting a few small integers but useful for comparison purposes.

Insertion Sort is well known — the code is provided below.

Counting Sort uses the values of the data itself to drive the algorithm, and thus performs no comparisons. Unique Counting Sort further refines this by assuming that the numbers in the small set are unique.

In addition to the range of sorting algorithms, implementation in Solidity includes the following possible array data types for holding small numbers:

Add a comment

Related posts:

Which Chicago Data Centers Attract the Best Clients?

Regardless of a facility’s cost of power, fiber choices, location, security, compliance, or certifications, in order for Chicago metro data center providers to grow their client base they need to get…