@~graphite/segmenter-objectid

1.0.1 • Public • Published

Segmenter ObjectId

Segment utilities for ObjectId types. Conveniently bucket data based on an ObjectId hash.

See: segmenter

Installation

npm i @~graphite/segmenter-objectid

Transient dependencies

Examples

Explicit usage

import { ObjectIdSegmenter } from "@~graphite/segmenter-objectid";

const segmenter = new ObjectIdSegmenter();

segmenter.segments(new ObjectId("xxxxxxxxxxxxxxxxxx000000"), ["A", "B"], ["X", "Y"]); // ["A", "X"]
segmenter.segments(new ObjectId("xxxxxxxxxxxxxxxxxx000001"), ["A", "B"], ["X", "Y"]); // ["A", "Y"]
segmenter.segments(new ObjectId("xxxxxxxxxxxxxxxxxx00000d"), ["A", "B"], ["X", "Y"]); // ["A", "Y"]
segmenter.segments(new ObjectId("xxxxxxxxxxxxxxxxxx00000e"), ["A", "B"], ["X", "Y"]); // ["B", "X"]

Extension usage

import "@~graphite/segmenter-objectid";

new ObjectId("xxxxxxxxxxxxxxxxxx000000").segments(["A", "B"], ["X", "Y"]); // ["A", "X"]
new ObjectId("xxxxxxxxxxxxxxxxxx000001").segments(["A", "B"], ["X", "Y"]); // ["A", "Y"]
new ObjectId("xxxxxxxxxxxxxxxxxx00000d").segments(["A", "B"], ["X", "Y"]); // ["A", "Y"]
new ObjectId("xxxxxxxxxxxxxxxxxx00000e").segments(["A", "B"], ["X", "Y"]); // ["B", "X"]

Resolution

  • This segmenter users the trailing 3-bytes of a hexadecimal ObjectID to determine bucket indexing. This specification is arbitrary to MongoDB's implementation of ObjectIDs which describes this portion of the ObjectID as a counter, starting with a random value.

Dependents (0)

Package Sidebar

Install

npm i @~graphite/segmenter-objectid

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

21.9 kB

Total Files

23

Last publish

Collaborators

  • peteschmitz