import{is_array}from"../common.js";import Index,{autoCommit}from"../index.js";import{KeystoreMap}from"../keystore.js";Index.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate){for(let b,d,e=0;e<c.length;e++)if(!((b=c[e])&&(d=b.length)));else if(b[d-1]===a)b.pop();else{const c=b.indexOf(a);0<=c&&b.splice(c,1)}}else remove_index(this.map,a),this.depth&&remove_index(this.ctx,a);b||this.reg.delete(a)}return this.db&&(this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this.cache&&this.cache.remove(a),this};export function remove_index(a,b){let c=0;if(is_array(a)){for(let d,e,f,g=0;g<a.length;g++)if((d=a[g])&&d.length){if("undefined"==typeof b)return 1;if(e=d.indexOf(b),0<=e){if(1<d.length)return d.splice(e,1),1;if(delete a[g],c)return 1;f=1}else{if(f)return 1;c++}}}else for(let d of a.entries()){const e=d[0],f=d[1],g=remove_index(f,b);g?c++:a.delete(e)}return c}