Technical Reference

LibRegistry

Source updated:
Last updated:
Source Revision 0xb40fc18c…e875fa
Property Value
Source Revision 0xb40fc18c6f635aca3d0aba90527dd0b4030278a6e5a3274b79b1743fd8e875fa
Source commit ab63f23a4165199f0a6c79ff55b469f2176d7b30
Removal commit 97465b1777313baa61d79671468d301210150c58
Source status Archived source snapshot; this does not establish deployed bytecode equivalence.

The exact historical source did not compile from its final pre-deletion checkout. No ABI is presented as compiled output for this source snapshot.

// SPDX-License-Identifier: Sharia
pragma solidity ^0.8.21;
import "atropamath.sol";
library LibRegistry {
struct Registry {
uint256[] keys;
mapping(uint256 => uint256) indexOf;
mapping(uint256 => bool) inserted;
}
function GetHashByIndex(Registry storage _registry, uint256 index) public view returns(uint256) {
return _registry.keys[index];
}
function Count(Registry storage _registry) public view returns(uint256) {
return _registry.keys.length;
}
function Contains(Registry storage _registry, uint256 key) public view returns(bool) {
return _registry.inserted[key];
}
function Register(Registry storage _registry, uint256 key) public {
if(!_registry.inserted[key])
{
_registry.inserted[key] = true;
_registry.indexOf[key] = _registry.keys.length;
_registry.keys.push(key);
}
}
function Remove(Registry storage _registry, uint256 key) public {
if(!_registry.inserted[key]) return;
delete _registry.inserted[key];
uint256 index = _registry.indexOf[key];
uint256 lastKey = _registry.keys[_registry.keys.length - 1];
_registry.indexOf[lastKey] = index;
delete _registry.indexOf[key];
_registry.keys[index] = lastKey;
_registry.keys.pop();
}
}