Skip to content

rob-Hitchens/SetTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

SetTypes

Enumerable Set Types, Ethereum, Solidity

Elaboration and optimization of the Solidity CRUD pattern at: https://github.com/rob-Hitchens/UnorderedKeySet

Four implementations:

  • AddressSet
  • Bytes32Set
  • StringSet
  • UintSet

Usage

import "./AddressSet.sol";

contract MyContract {

  using AddressSet for AddressSet.Set;
  AddressSet.Set myAddressSet;
  ...

Uses storage pointers to pass Sets to the library.

myAddressSet.insert(newAddress);
myAddressSet.remove(oldAddress);
uint count = myAddressSet.count();
address key = myAddressSet.keyAtIndex(row);

Works with structs:

struct User {
  AddressSet.Set followerSet;
  AddressSet.Set followingSet;
 }

Works with mappings:

mapping(bytes32 => AddressSet.Set) productOwnerSets;

See SetTypeExamples.sol for example usage.

About

Enumerable Set Types, Ethereum, Solidity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published