Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frangio/solidity-vectors
A vector data type with 32 components 8 bits each and basic vectorized operations.
https://github.com/frangio/solidity-vectors
Last synced: about 1 month ago
JSON representation
A vector data type with 32 components 8 bits each and basic vectorized operations.
- Host: GitHub
- URL: https://github.com/frangio/solidity-vectors
- Owner: frangio
- License: mit
- Created: 2023-03-18T21:36:28.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-30T19:46:25.000Z (over 1 year ago)
- Last Synced: 2024-10-16T10:21:27.380Z (2 months ago)
- Language: Solidity
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# $\vec{v}$.sol
**A vector data type with 32 components 8 bits each and basic vectorized operations.**
*May contain bugs. Use at your own risk.*
```solidity
import {Vec8x32} from 'solidity-vectors/Vec8x32.sol';
```## Constants
### `V0x32`
A vector of zeros.
### `V1x32`
A vector of ones.
## Construction
### `broadcast8x32(x)`
Returns a vector $v$ such that $v_i = x$ for all $i$.
### `embed8x32(i, x)`
Returns a vector $v$ such that $v_i = x$ and $v_j = 0$ for $j \neq i$.
$i$ is used modulo 32.
### `fill8x32(n, x)`
Returns a vector $v$ such that $v_i = x$ for $i < n$ and $v_j = 0$ for $j >= n$.
$n$ is used modulo 32.
## Predicates
### `v.any(x)`
Returns true if there is any $v_i = x$.
### `v.all(x)`
Returns true if $v_i = x$ for all $i$.
### `v == w`, `v != w`
Comparisons operate on the entire vector and return a single boolean.
## Arithmetic
### `v + w`, `v - w`
Component-wise addition and subtraction of two vectors with wrap-around on overflow.
### `-v`
Component-wise negation with wrap-around on overflow.
### `v.mul(k)`
Scalar multiplication of a vector with an 8-bit unsigned integer.
## Others
### `v.put(i, x)`
Returns a new vector $v'$ such that $v'_i = x$ and $v'_j = v_j$ for $i \neq j$.
$i$ is used modulo 32.
### `v.pluck(i)`
Returns $v_i$.
$i$ is used modulo 32.
### `v & w`, `v | w`, `v ^ w`, `~v`
Bitwise operations are component-wise, which is equivalent to their standard behavior on `bytes32`.