Skip to content

chuyenpn-rks/CappedSet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implement a set-like structure in Solidity

This project for assignment CappedSet - RikkeiSoft solution

v0.2: first simple solution using hashmap with index as address - value pair; find smallest value element by iterating through all elemets. Have issues with high gas (Max 12 Million Gas when Capped = 1000 - Insert Operation)

Gas Image

v0.3: Recommended version using Red Black Tree Library from Red-Black Binary Search Tree Library
Much better gas usage with maximum gas ~ 400,000 (0.0011 BNB per transaction) when Capped Number = 1000
Should scale well with high Capped Number since all operation complexity is O(logN)

Gas Image

Try running some of the following tasks:

yarn
copy .env.example .env
npx hardhat help
npx hardhat test

Choose Type Script Project in "npx hardhat test" in case being asked. Test Scenario in Test Folder, Change Capped Number file CappedSet.ts const MAX_LENGTH = 1000;

To deploy, create .env file (see .env.example file for sample), then run command

npx hardhat run scripts/deploy.ts --network bsctestnet

Contract deployed and verified on BNB Smart Chain Testnet

About

Implement a set-like structure in Solidity

Resources

Stars

Watchers

Forks

Packages

No packages published