* add vector, lifo and fifo structures * fix lint * need more memory for coverage * remove Vector wrappers and gas optimization * refactor Vector testing * revert package.json changes * rename to DoubleEndedQueue * rename and refactor * refactor tests and expand coverage * test for custom errors * add changelog entry * add docs * add sample code and note about storage vs. memory * add available since * lint * use underscore for struct members * add struct documentation * remove SafeCast in length * rename i -> index and improve docs Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
59 lines
1.3 KiB
Solidity
59 lines
1.3 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
import "../utils/structs/DoubleEndedQueue.sol";
|
|
|
|
// Bytes32Deque
|
|
contract Bytes32DequeMock {
|
|
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
|
|
|
|
event OperationResult(bytes32 value);
|
|
|
|
DoubleEndedQueue.Bytes32Deque private _vector;
|
|
|
|
function pushBack(bytes32 value) public {
|
|
_vector.pushBack(value);
|
|
}
|
|
|
|
function pushFront(bytes32 value) public {
|
|
_vector.pushFront(value);
|
|
}
|
|
|
|
function popFront() public returns (bytes32) {
|
|
bytes32 value = _vector.popFront();
|
|
emit OperationResult(value);
|
|
return value;
|
|
}
|
|
|
|
function popBack() public returns (bytes32) {
|
|
bytes32 value = _vector.popBack();
|
|
emit OperationResult(value);
|
|
return value;
|
|
}
|
|
|
|
function front() public view returns (bytes32) {
|
|
return _vector.front();
|
|
}
|
|
|
|
function back() public view returns (bytes32) {
|
|
return _vector.back();
|
|
}
|
|
|
|
function at(uint256 i) public view returns (bytes32) {
|
|
return _vector.at(i);
|
|
}
|
|
|
|
function clear() public {
|
|
_vector.clear();
|
|
}
|
|
|
|
function length() public view returns (uint256) {
|
|
return _vector.length();
|
|
}
|
|
|
|
function empty() public view returns (bool) {
|
|
return _vector.empty();
|
|
}
|
|
}
|