https://github.com/bitfinexcom/hypercore-bisect
https://github.com/bitfinexcom/hypercore-bisect
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bitfinexcom/hypercore-bisect
- Owner: bitfinexcom
- Created: 2018-11-13T17:12:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T18:12:57.000Z (almost 6 years ago)
- Last Synced: 2025-03-25T04:16:34.466Z (about 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hypercore-bisect
Lookup a data entry in a sequential hypercore by bisecting it.
**Example:**
```js
const hc = hypercore(ram, { valueEncoding: 'json' })
hc.append([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], () => {
bisect(hc, 2, (err, seq, entry) => {
if (err) return console.error('ouch', err)
console.log(seq, entry) // 1, 2
})
})
```
Get the closest entry if nothing was found, useful for timeframes:
```js
const hc = hypercore(ram, { valueEncoding: 'json' })
hc.append([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], () => {
bisect(hc, 11, { returnClosest: true }, (err, seq, entry) => {
if (err) return console.error('ouch', err)
console.log(seq, entry) // 9, 10
})
})
```
## API
### bisect(feed, compare, [opts], cb)
- `feed ` a hypercore feed
- `compare ` item to search for, or custom compare function
- `opts (optional)`
- `returnClosest` if nothing is found, return closest match