/*
	Copyright (c) 2004-2016, The JS Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/

//>>built
define("dojo/store/Memory",["../_base/declare","./util/QueryResults","./util/SimpleQueryEngine"],function(k,l,m){return k("dojo.store.Memory",null,{constructor:function(a){for(var b in a)this[b]=a[b];this.setData(this.data||[])},data:null,idProperty:"id",index:null,queryEngine:m,get:function(a){return this.data[this.index[a]]},getIdentity:function(a){return a[this.idProperty]},put:function(a,b){var d=this.data,c=this.index,e=this.idProperty;e=a[e]=b&&"id"in b?b.id:e in a?a[e]:Math.random();var g=
d.length,f,h=e in c?"update":"add";if("update"===h){if(b&&!1===b.overwrite)throw Error("Object already exists");g=f=c[e]}b&&"before"in b?null==b.before?(c=d.length,"update"===h&&--c):(c=c[this.getIdentity(b.before)],f<c&&--c):c=g;c===f?d[c]=a:(void 0!==f&&d.splice(f,1),d.splice(c,0,a),this._rebuildIndex(void 0===f?c:Math.min(f,c)));return e},add:function(a,b){(b=b||{}).overwrite=!1;return this.put(a,b)},remove:function(a){var b=this.index,d=this.data;if(a in b)return d.splice(b[a],1),this.index={},
this._rebuildIndex(),!0},query:function(a,b){return l(this.queryEngine(a,b)(this.data))},setData:function(a){a.items?(this.idProperty=a.identifier||this.idProperty,a=this.data=a.items):this.data=a;this.index={};this._rebuildIndex()},_rebuildIndex:function(a){var b=this.data,d=b.length;for(a=a||0;a<d;a++)this.index[b[a][this.idProperty]]=a}})});