UNPKG

itemsjs

Version:

Created to perform fast search on small json dataset (up to 1000 elements).

40 lines (31 loc) 660 B
"use strict"; var _ = require('lodash'); var helpers = require('./helpers'); var FastBitSet = require('fastbitset'); /** * storing items and bits ids */ var Storage = function Storage(items) { var _this = this; this.items = items; this._ids = []; var i = 1; _.map(items, function (item) { _this._ids.push(i++); }); }; Storage.prototype = { bits_ids: function bits_ids(ids) { if (ids) { return new FastBitSet(ids); } return this._bits_ids; }, get_items: function get_items(_id) { return this.items; }, get_item: function get_item(_id) { return this._items_map[_id]; } }; module.exports = Storage;