npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hyperlog-kdb-index

v4.0.2

Published

n-dimensional kdb tree spatial index for hyperlogs

Downloads

11

Readme

hyperlog-kdb-index

n-dimensional kdb tree spatial index for hyperlogs

example

var fdstore = require('fd-chunk-store')
var hyperkdb = require('hyperlog-kdb-index')
var level = require('level')

var hyperlog = require('hyperlog')
var log = hyperlog(level('/tmp/kdb-log/log'), { valueEncoding: 'json' })

var kdb = hyperkdb({
  log: log,
  db: level('/tmp/kdb-log/index'),
  types: [ 'float', 'float' ],
  kdbtree: require('kdb-tree-store'),
  store: fdstore(1024, '/tmp/kdb-log/tree'),
  map: function (row, next) {
    if (row.value.type === 'point') {
      next(null, [ row.value.lat, row.value.lon ])
    } else next()
  }
})

if (process.argv[2] === 'add') {
  log.add(null, {
    type: 'point',
    lat: Number(process.argv[3]),
    lon: Number(process.argv[4])
  })
} else if (process.argv[2] === 'query') {
  var q = process.argv.slice(3).map(commaSplit)
  kdb.query(q, function (err, pts) {
    if (err) return console.error(err)
    pts.forEach(function (pt) {
      console.log(pt.point)
    })
  })
}

function commaSplit (s) { return s.split(',').map(Number) }
$ mkdir /tmp/kdb-log
$ node log.js add 64.7 -147.9
$ node log.js add 66.2 -147.5
$ node log.js add 61.6 -148.3
$ node log.js query 60,65 -149,-146
[ 64.69999694824219, -147.89999389648438 ]
[ 61.599998474121094, -148.3000030517578 ]

api

var hyperkdb = require('hyperlog-kdb-index')

var kdb = hyperkdb(opts)

Create a kdb-tree spatial index for a hyperlog. These options are required:

  • opts.log - a hyperlog where data is written
  • opts.db - leveldb instance to store index data
  • opts.types - array of kdb-tree-store types
  • opts.kdbtree - kdb-tree-store interface (require('kdb-tree-store'))
  • opts.store - abstract-chunk-store for the kdb tree data
  • opts.map(row, next) - asynchornous function mapping hyperlog rows to points

In the opts.map(row, next), if there are no points to map in a given row, call next() with a falsy value. Otherwise call next(err, rec) with a record:

  • rec.type - 'put' or 'del'
  • rec.point - array of coordinates

If rec is an array, it will be interpreted as a point in a 'put'.

kdb.query(q, opts={}, cb)

Query for all points in the region described by q. This method is passed through to the underlying kdb-tree-store query method.

var r = kdb.queryStream(q, opts={})

Return a readable stream r with the region described by q. This method is passed through to the underlying kdb-tree-store query method.

kdb.ready(fn)

When the index has caught up with the latest known entry in the hyperlog, fn() fires.

log.add(links, doc, cb)

When you write to the hyperlog, the links should refer to the ancestors of the current doc which will be replaced with the new value.

When you create a new point, links should be any empty array [].

When you update an existing point, links should contain a list of immediate ancestors that the update will replace. Usually this will be a single key, but for merge cases, this can be several keys.

install

npm install hyperlog-kdb-index

license

BSD