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?

4

1 回答 1

0

如果您愿意使用其他库,我会推荐我的一个https://bitbucket.org/ytkyaw/ydn-db/wiki/Home

它易于使用并针对性能进行了优化。它也支持 IndexedDB、WebSQL 和 WebStorage。

使用该库,您可以通过索引键获得O(log n)时间,我认为,从排序数组中查找。您可以通过仅查询键来消除​​序列化成本。图书馆的使用可以在这里找到:http: //dev.yathit.com/ydn-db/getting-started.html

于 2013-01-02T08:30:05.557 回答