https://github.com/dcmox/algorithms
General purpose data structures and algorithms
https://github.com/dcmox/algorithms
algorithms binary data hash linked list structures tree
Last synced: about 1 year ago
JSON representation
General purpose data structures and algorithms
- Host: GitHub
- URL: https://github.com/dcmox/algorithms
- Owner: dcmox
- License: apache-2.0
- Created: 2020-01-28T00:39:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T05:53:11.000Z (about 3 years ago)
- Last Synced: 2024-04-27T02:02:22.600Z (almost 2 years ago)
- Topics: algorithms, binary, data, hash, linked, list, structures, tree
- Language: JavaScript
- Homepage:
- Size: 693 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# moxy-algorithms
Useful data structures and algorithms
## Features
- LinkedList
- HashedList
- BinaryHashTree w/ hash validation and proofs
- detectCycle (loops)
- sha256
- base58
## Usage
```typescript
const MoxyAlgos = require('moxy-algos')
const data = [
'hello',
'world',
'this',
'is',
'a',
'test',
'to',
'see',
'if',
'our',
'binary',
'hash',
'tree',
'works',
'as',
'expected',
]
const tree = MoxyAlgos.BinaryHashTree(data)
console.log(JSON.stringify(tree, null, 2))
console.log(tree.validate()) // true
const tree = MoxyAlgos.BinaryHashTree([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
])
console.log(JSON.stringify(tree, null, 2))
console.log(
tree.getProofs(
'2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3',
),
) // Gives you the necessary node hashes to prove a transaction is valid
console.log(
tree.verifyHash(
'2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3',
),
) // Verifies hash is valid
```