2

I am using Lawnchair to store data locally on my client. The key I am using to insert values is created server-side.

Currently when I use .all the list of returned values is an array indexed from 0. I then iterate over this list storing returned values in an object literal (using underscore.js).

var objects = {};
_.each(returnedArray, function (val) {
    objects[val.key] = val;
});

This allows me to use O(1) lookups in other parts of my code, but requires an O(n) operation on all reads from Lawnchair.

Is it possible to configure Lawnchair (or to use a different method / combination of methods) to return a key indexed object literal without iterating over my entire dataset?

Resonance
  • 106
  • 6

1 Answers1

0

If you are open to use other library, I will suggest my one https://bitbucket.org/ytkyaw/ydn-db/wiki/Home

It is easy to used and optimized for performance. It supports IndexedDB, WebSQL and WebStorage too.

Using the library you can get by index key, with O(log n) times, I think, for finding from sorted array. You can eliminate serilization cost by querying key only. Library usage can find here: http://dev.yathit.com/ydn-db/getting-started.html

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83