Permalink
Fetching contributors…
Cannot retrieve contributors at this time
4366 lines (4039 sloc) 259 KB
<!DOCTYPE html>
<html>
<head>
<title>nddb.js</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="doc-style.css" />
<script src="doc-filelist.js"></script>
<script>
var relativeDir = '', thisFile = '', defaultSidebar = true;
</script>
<script src="doc-script.js"></script>
</head>
<body>
<div id="sidebar_wrapper">
<div id="sidebar_switch">
<span class="tree">Files</span>
<span class="headings">Headings</span>
</div>
<div id="tree"></div>
<div id="headings">
<div class="heading h1">
<a href="#nddb--n-dimensional-database">NDDB: N-Dimensional Database</a>
</div>
<div class="heading h2">
<a href="#global-scope">Global scope</a>
</div>
<div class="heading h3">
<a href="#nddb.log">NDDB.log</a>
</div>
<div class="heading h3">
<a href="#nddb.retrocycle">NDDB.retrocycle</a>
</div>
<div class="heading h3">
<a href="#nddb.retrocycle">NDDB.retrocycle</a>
</div>
<div class="heading h2">
<a href="#nddb-constructor">NDDB constructor</a>
</div>
<div class="heading h2">
<a href="#public-properties">Public properties</a>
</div>
<div class="heading h3">
<a href="#db">db</a>
</div>
<div class="heading h3">
<a href="#tags">tags</a>
</div>
<div class="heading h3">
<a href="#hooks">hooks</a>
</div>
<div class="heading h3">
<a href="#nddb_pointer">nddb_pointer</a>
</div>
<div class="heading h3">
<a href="#length">length</a>
</div>
<div class="heading h3">
<a href="#__c">__C</a>
</div>
<div class="heading h3">
<a href="#__h">__H</a>
</div>
<div class="heading h3">
<a href="#__update">__update</a>
</div>
<div class="heading h3">
<a href="#__update.pointer">__update.pointer</a>
</div>
<div class="heading h3">
<a href="#__update.indexes">__update.indexes</a>
</div>
<div class="heading h3">
<a href="#__update.sort">__update.sort</a>
</div>
<div class="heading h3">
<a href="#__parent">__parent</a>
</div>
<div class="heading h2">
<a href="#methods">METHODS</a>
</div>
<div class="heading h3">
<a href="#nddb.init">NDDB.init</a>
</div>
<div class="heading h2">
<a href="#core">CORE</a>
</div>
<div class="heading h3">
<a href="#nddb.globalcompare">NDDB.globalCompare</a>
</div>
<div class="heading h3">
<a href="#nddb._masquerade">NDDB._masquerade</a>
</div>
<div class="heading h3">
<a href="#nddb._masqueradedb">NDDB._masqueradeDB</a>
</div>
<div class="heading h3">
<a href="#nddb._autoupdate">NDDB._autoUpdate</a>
</div>
<div class="heading h3">
<a href="#nddb.importdb">NDDB.importDB</a>
</div>
<div class="heading h3">
<a href="#nddb.insert">NDDB.insert</a>
</div>
<div class="heading h3">
<a href="#nddb._insert">NDDB._insert</a>
</div>
<div class="heading h3">
<a href="#nddb.breed">NDDB.breed</a>
</div>
<div class="heading h3">
<a href="#nddb.clonesettings">NDDB.cloneSettings</a>
</div>
<div class="heading h3">
<a href="#nddb.tostring">NDDB.toString</a>
</div>
<div class="heading h3">
<a href="#nddb.stringify">NDDB.stringify</a>
</div>
<div class="heading h3">
<a href="#nddb.compare---nddb.c">NDDB.compare | NDDB.c</a>
</div>
<div class="heading h3">
<a href="#nddb.comparator">NDDB.comparator</a>
</div>
<div class="heading h3">
<a href="#nddb.isreservedword">NDDB.isReservedWord</a>
</div>
<div class="heading h3">
<a href="#nddb.hash---nddb.h">NDDB.hash | NDDB.h</a>
</div>
<div class="heading h3">
<a href="#nddb.rebuildindexes">NDDB.rebuildIndexes</a>
</div>
<div class="heading h3">
<a href="#nddb._hashit">NDDB._hashIt</a>
</div>
<div class="heading h2">
<a href="#sort-and-select">Sort and Select</a>
</div>
<div class="heading h3">
<a href="#nddb._analyzequery">NDDB._analyzeQuery</a>
</div>
<div class="heading h2">
<a href="#nddb.distinct">NDDB.distinct</a>
</div>
<div class="heading h2">
<a href="#nddb.select">NDDB.select</a>
</div>
<div class="heading h2">
<a href="#input-parameters">Input parameters</a>
</div>
<div class="heading h3">
<a href="#nddb.limit">NDDB.limit</a>
</div>
<div class="heading h3">
<a href="#nddb.reverse">NDDB.reverse</a>
</div>
<div class="heading h3">
<a href="#nddb.sort">NDDB.sort</a>
</div>
<div class="heading h3">
<a href="#nddb.shuffle">NDDB.shuffle</a>
</div>
<div class="heading h2">
<a href="#custom-callbacks">Custom callbacks</a>
</div>
<div class="heading h3">
<a href="#nddb.filter">NDDB.filter</a>
</div>
<div class="heading h3">
<a href="#nddb.each----nddb.foreach">NDDB.each || NDDB.forEach</a>
</div>
<div class="heading h3">
<a href="#nddb.map">NDDB.map</a>
</div>
<div class="heading h1">
<a href="#update">Update</a>
</div>
<div class="heading h2">
<a href="#deletion">Deletion</a>
</div>
<div class="heading h3">
<a href="#nddb.remove">NDDB.remove</a>
</div>
<div class="heading h3">
<a href="#nddb.clear">NDDB.clear</a>
</div>
<div class="heading h2">
<a href="#advanced-operations">Advanced operations</a>
</div>
<div class="heading h3">
<a href="#nddb.join">NDDB.join</a>
</div>
<div class="heading h3">
<a href="#nddb.concat">NDDB.concat</a>
</div>
<div class="heading h3">
<a href="#nddb._join">NDDB._join</a>
</div>
<div class="heading h3">
<a href="#nddb.split">NDDB.split</a>
</div>
<div class="heading h2">
<a href="#fetching">Fetching</a>
</div>
<div class="heading h3">
<a href="#nddb._fetch">NDDB._fetch</a>
</div>
<div class="heading h3">
<a href="#nddb.fetch">NDDB.fetch</a>
</div>
<div class="heading h3">
<a href="#nddb.fetcharray">NDDB.fetchArray</a>
</div>
<div class="heading h3">
<a href="#nddb.fetchkeyarray">NDDB.fetchKeyArray</a>
</div>
<div class="heading h3">
<a href="#nddb.fetchvalues">NDDB.fetchValues</a>
</div>
<div class="heading h3">
<a href="#nddb.fetchkeyvalues">NDDB.fetchKeyValues</a>
</div>
<div class="heading h3">
<a href="#nddb.groupby">NDDB.groupBy</a>
</div>
<div class="heading h2">
<a href="#statistics">Statistics</a>
</div>
<div class="heading h3">
<a href="#nddb.count">NDDB.count</a>
</div>
<div class="heading h3">
<a href="#nddb.sum">NDDB.sum</a>
</div>
<div class="heading h3">
<a href="#nddb.mean">NDDB.mean</a>
</div>
<div class="heading h3">
<a href="#nddb.stddev">NDDB.stddev</a>
</div>
<div class="heading h3">
<a href="#nddb.min">NDDB.min</a>
</div>
<div class="heading h3">
<a href="#nddb.max">NDDB.max</a>
</div>
<div class="heading h2">
<a href="#skim">Skim</a>
</div>
<div class="heading h3">
<a href="#nddb.skim">NDDB.skim</a>
</div>
<div class="heading h3">
<a href="#nddb.keep">NDDB.keep</a>
</div>
<div class="heading h2">
<a href="#diff">Diff</a>
</div>
<div class="heading h3">
<a href="#nddb.diff">NDDB.diff</a>
</div>
<div class="heading h3">
<a href="#nddb.intersect">NDDB.intersect</a>
</div>
<div class="heading h2">
<a href="#iterator">Iterator</a>
</div>
<div class="heading h3">
<a href="#nddb.get">NDDB.get</a>
</div>
<div class="heading h3">
<a href="#nddb.next">NDDB.next</a>
</div>
<div class="heading h3">
<a href="#nddb.previous">NDDB.previous</a>
</div>
<div class="heading h3">
<a href="#nddb.first">NDDB.first</a>
</div>
<div class="heading h3">
<a href="#nddb.last">NDDB.last</a>
</div>
<div class="heading h2">
<a href="#tagging">Tagging</a>
</div>
<div class="heading h3">
<a href="#nddb.tag">NDDB.tag</a>
</div>
<div class="heading h3">
<a href="#nddb.resolvetag">NDDB.resolveTag</a>
</div>
<div class="heading h2">
<a href="#persistance">Persistance</a>
</div>
<div class="heading h2">
<a href="#closure">Closure</a>
</div>
</div>
</div>
<div id="sidebar-toggle"></div>
<div id="container"><div class="background highlight"></div>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb--n-dimensional-database">
<h1>
<a href="#nddb--n-dimensional-database" class="pilcrow">&#182;</a>
NDDB: N-Dimensional Database
</h1>
</div>
</div>
<div class="body"><p>Copyright(c) 2012 Stefano Balietti
MIT Licensed</p>
<p>NDDB provides a simple, lightweight, NO-SQL object database
for node.js and the browser. It depends on JSUS.</p>
<p>Allows to define any number of comparator and indexing functions,
which are associated to any of the dimensions (i.e. properties) of
the objects stored in the database. </p>
<p>Whenever a comparison is needed, the corresponding comparator function
is called, and the database is updated.</p>
<p>Whenever an object is inserted that matches one of the indexing functions
an hash is produced, and the element is added to one of the indexes.</p>
<p>Additional features are: methods chaining, tagging, and iteration
through the entries.</p>
<p>See README.md for help.</p>
<hr />
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">exports</span><span class="p">,</span> <span class="nx">JSUS</span><span class="p">,</span> <span class="nx">store</span><span class="p">)</span> <span class="p">{</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="global-scope">
<h2>
<a href="#global-scope" class="pilcrow">&#182;</a>
Global scope
</h2>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre>
<span class="kd">var</span> <span class="nx">nddb_operation</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">nddb_conditions</span> <span class="o">=</span> <span class="p">[];</span>
<span class="kd">var</span> <span class="nx">addCondition</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">condition</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">type</span> <span class="o">||</span> <span class="o">!</span><span class="nx">condition</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Attempt to add invalid condition&#39;</span><span class="p">,</span> <span class="s1">&#39;ERR&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">nddb_conditions</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span>
<span class="nx">type</span><span class="o">:</span> <span class="nx">type</span><span class="p">,</span>
<span class="nx">condition</span><span class="o">:</span> <span class="nx">condition</span><span class="p">,</span>
<span class="p">});</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">addOperation</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">nddb_operation</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;No operation found.&#39;</span><span class="p">,</span> <span class="s1">&#39;ERR&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">valid</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_analyzeQuery</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">valid</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">addCondition</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">valid</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">and</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">AND</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">addOperation</span><span class="p">(</span><span class="s1">&#39;AND&#39;</span><span class="p">,</span> <span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">};</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">or</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">OR</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">addOperation</span><span class="p">(</span><span class="s1">&#39;OR&#39;</span><span class="p">,</span> <span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">};</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">not</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">NOT</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">addOperation</span><span class="p">(</span><span class="s1">&#39;NOT&#39;</span><span class="p">,</span> <span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-3" id="section-3">&#182;</a>
</div>
<p>Expose constructors</p>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">exports</span><span class="p">.</span><span class="nx">NDDB</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">;</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="nddb.log">
<h3>
<a href="#nddb.log" class="pilcrow">&#182;</a>
NDDB.log
</h3>
</div>
<p>Stdout redirect</p>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span> <span class="o">=</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">;</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">__symbols</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;&gt;&#39;</span><span class="p">,</span><span class="s1">&#39;&gt;=&#39;</span><span class="p">,</span><span class="s1">&#39;&gt;==&#39;</span><span class="p">,</span><span class="s1">&#39;&lt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;=&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;==&#39;</span><span class="p">,</span> <span class="s1">&#39;!=&#39;</span><span class="p">,</span> <span class="s1">&#39;!==&#39;</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="s1">&#39;==&#39;</span><span class="p">,</span> <span class="s1">&#39;===&#39;</span><span class="p">,</span> <span class="s1">&#39;&gt;&lt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;in&#39;</span><span class="p">,</span> <span class="s1">&#39;!in&#39;</span><span class="p">];</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">__operations</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;select&#39;</span><span class="p">,</span> <span class="s1">&#39;groupby&#39;</span><span class="p">,</span> <span class="s1">&#39;limit&#39;</span><span class="p">,</span> <span class="s1">&#39;first&#39;</span><span class="p">,</span> <span class="s1">&#39;fetch&#39;</span><span class="p">,</span> <span class="s1">&#39;last&#39;</span><span class="p">];</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.retrocycle">
<h3>
<a href="#nddb.retrocycle" class="pilcrow">&#182;</a>
NDDB.retrocycle
</h3>
</div>
</div>
<div class="body"><p>Removes cyclic references from an object</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>e</span>
<span class="dox_type">object</span>
<span>The object to decycle</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">object</span>
<span>e The decycled object</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">decycle</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">JSON</span> <span class="o">&amp;&amp;</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">decycle</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;function&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">decycle</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">e</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">decycle</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">e</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.retrocycle">
<h3>
<a href="#nddb.retrocycle" class="pilcrow">&#182;</a>
NDDB.retrocycle
</h3>
</div>
</div>
<div class="body"><p>Restores cyclic references in an object previously decycled</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>e</span>
<span class="dox_type">object</span>
<span>The object to retrocycle</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">object</span>
<span>e The retrocycled object</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">retrocycle</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">JSON</span> <span class="o">&amp;&amp;</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">retrocycle</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;function&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">retrocycle</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">e</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">retrocycle</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">e</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb-constructor">
<h2>
<a href="#nddb-constructor" class="pilcrow">&#182;</a>
NDDB constructor
</h2>
</div>
</div>
<div class="body"><p>Creates a new instance of NDDB</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>options</span>
<span class="dox_type">object</span>
<span>Optional. Configuration options</span>
</div>
<div class="dox_tag_detail">
<span>db</span>
<span class="dox_type">db</span>
<span>Optional. An initial set of items to import</span>
</div>
<div class="dox_tag_detail">
<span>parent</span>
<span class="dox_type">NDDB</span>
<span>Optional. A parent database to keep sync</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">NDDB</span> <span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">db</span><span class="p">,</span> <span class="nx">parent</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">JSUS</span><span class="p">)</span> <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;JSUS not found.&#39;</span><span class="p">);</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="public-properties">
<h2>
<a href="#public-properties" class="pilcrow">&#182;</a>
Public properties
</h2>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre> </pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="db">
<h3>
<a href="#db" class="pilcrow">&#182;</a>
db
</h3>
</div>
<p>The default database</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="p">[];</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="tags">
<h3>
<a href="#tags" class="pilcrow">&#182;</a>
tags
</h3>
</div>
<p>The tags list</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">tags</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="hooks">
<h3>
<a href="#hooks" class="pilcrow">&#182;</a>
hooks
</h3>
</div>
<p>The list of hooks and associated callbacks</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">hooks</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="nddb_pointer">
<h3>
<a href="#nddb_pointer" class="pilcrow">&#182;</a>
nddb_pointer
</h3>
</div>
<p>Pointer for iterating along all the elements</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">nddb_pointer</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="length">
<h3>
<a href="#length" class="pilcrow">&#182;</a>
length
</h3>
</div>
<p>The number of items in the database</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;length&#39;</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">set</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){},</span>
<span class="nx">get</span><span class="o">:</span> <span class="kd">function</span><span class="p">(){</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
<span class="p">},</span>
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span>
<span class="p">});</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__c">
<h3>
<a href="#__c" class="pilcrow">&#182;</a>
__C
</h3>
</div>
<p>List of comparator functions</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__C</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__h">
<h3>
<a href="#__h" class="pilcrow">&#182;</a>
__H
</h3>
</div>
<p>List of hashing functions</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__H</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__update">
<h3>
<a href="#__update" class="pilcrow">&#182;</a>
__update
</h3>
</div>
<p>Auto update options container</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__update.pointer">
<h3>
<a href="#__update.pointer" class="pilcrow">&#182;</a>
__update.pointer
</h3>
</div>
<p>If TRUE, nddb_pointer always points to the last insert</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">pointer</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__update.indexes">
<h3>
<a href="#__update.indexes" class="pilcrow">&#182;</a>
__update.indexes
</h3>
</div>
<p>If TRUE, rebuild indexes on every insert and remove</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">indexes</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__update.sort">
<h3>
<a href="#__update.sort" class="pilcrow">&#182;</a>
__update.sort
</h3>
</div>
<p>If TRUE, sort db on every insert and remove</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">sort</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="__parent">
<h3>
<a href="#__parent" class="pilcrow">&#182;</a>
__parent
</h3>
</div>
<p>Reference to a parent NNDB database (if chaining)</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">__parent</span> <span class="o">=</span> <span class="nx">parent</span> <span class="o">||</span> <span class="kc">undefined</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">importDB</span><span class="p">(</span><span class="nx">db</span><span class="p">);</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="methods">
<h2>
<a href="#methods" class="pilcrow">&#182;</a>
METHODS
</h2>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.init">
<h3>
<a href="#nddb.init" class="pilcrow">&#182;</a>
NDDB.init
</h3>
</div>
</div>
<div class="body"><p>Sets global options based on local configuration</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>options</span>
<span class="dox_type">object</span>
<span>Optional. Configuration options</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">init</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__options</span> <span class="o">=</span> <span class="nx">options</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">log</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">log</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">C</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__C</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">C</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">H</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__H</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">H</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">tags</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">tags</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">tags</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">nddb_pointer</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">nddb_pointer</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">nddb_pointer</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">hooks</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">hooks</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">hook</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">pointer</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">pointer</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">pointer</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">indexes</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">indexes</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">indexes</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">sort</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">sort</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">update</span><span class="p">.</span><span class="nx">sort</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="core">
<h2>
<a href="#core" class="pilcrow">&#182;</a>
CORE
</h2>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.globalcompare">
<h3>
<a href="#nddb.globalcompare" class="pilcrow">&#182;</a>
NDDB.globalCompare
</h3>
</div>
</div>
<div class="body"><p>Function used for comparing two items in the database</p>
<p>By default, elements are sorted according to their
internal id (FIFO). Override to change.</p>
<p>Returns</p>
<ul>
<li>0 if the objects are the same</li>
<li>a positive number if o2 precedes o1 </li>
<li>a negative number if o1 precedes o2 </li>
</ul>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>o1</span>
<span class="dox_type">object</span>
<span>The first object to compare</span>
</div>
<div class="dox_tag_detail">
<span>o1</span>
<span class="dox_type">object</span>
<span>The second object to compare</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">number</span>
<span>The result of the comparison</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">globalCompare</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">o1</span><span class="p">,</span> <span class="nx">o2</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o1</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o2</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o2</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o1</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">o1</span><span class="p">.</span><span class="nx">nddbid</span> <span class="o">&lt;</span> <span class="nx">o2</span><span class="p">.</span><span class="nx">nddbid</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">o1</span><span class="p">.</span><span class="nx">nddbid</span> <span class="o">&gt;</span> <span class="nx">o2</span><span class="p">.</span><span class="nx">nddbid</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._masquerade">
<h3>
<a href="#nddb._masquerade" class="pilcrow">&#182;</a>
NDDB._masquerade
</h3>
</div>
</div>
<div class="body"><p>Injects a hidden counter property into the prototype </p>
<p>The object contains the index of the containing array.</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>o</span>
<span class="dox_type">object</span>
<span>The object to masquerade</span>
</div>
<div class="dox_tag_detail">
<span>db</span>
<span class="dox_type">array</span>
<span>Optional. The array</span>
</div>
<div class="dox_tag_title">API</div>
<div class="dox_tag_detail">
<span class="dox_type">private</span>
</span>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_masquerade</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">db</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-26" id="section-26">&#182;</a>
</div>
<p>TODO: check this</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">o</span><span class="p">.</span><span class="nx">nddbid</span><span class="p">)</span> <span class="k">return</span> <span class="nx">o</span><span class="p">;</span>
<span class="nx">db</span> <span class="o">=</span> <span class="nx">db</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">;</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="s1">&#39;nddbid&#39;</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">value</span><span class="o">:</span> <span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span>
<span class="nx">configurable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="nx">writable</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>
<span class="p">});</span>
<span class="k">return</span> <span class="nx">o</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._masqueradedb">
<h3>
<a href="#nddb._masqueradedb" class="pilcrow">&#182;</a>
NDDB._masqueradeDB
</h3>
</div>
</div>
<div class="body"><p>Masquerades a whole array and returns it</p>
</div>
<div class="details">
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB._masquerade</span>
</div>
<div class="dox_tag_title">API</div>
<div class="dox_tag_detail">
<span class="dox_type">private</span>
</span>
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>db</span>
<span class="dox_type">array</span>
<span>Array of items to masquerade</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_masqueradeDB</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">db</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">db</span><span class="p">)</span> <span class="k">return</span> <span class="p">[];</span>
<span class="kd">var</span> <span class="nx">out</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">out</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_masquerade</span><span class="p">(</span><span class="nx">db</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">out</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">out</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._autoupdate">
<h3>
<a href="#nddb._autoupdate" class="pilcrow">&#182;</a>
NDDB._autoUpdate
</h3>
</div>
</div>
<div class="body"><p>Performs a series of automatic checkings
and updates the db according to current
configuration</p>
</div>
<div class="details">
<div class="dox_tag_title">API</div>
<div class="dox_tag_detail">
<span class="dox_type">private</span>
</span>
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>options</span>
<span class="dox_type">object</span>
<span>Optional. Configuration object</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_autoUpdate</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">update</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">options</span> <span class="o">||</span> <span class="p">{},</span> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">update</span><span class="p">.</span><span class="nx">pointer</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">nddb_pointer</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">update</span><span class="p">.</span><span class="nx">sort</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">sort</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">update</span><span class="p">.</span><span class="nx">indexes</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">rebuildIndexes</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-29" id="section-29">&#182;</a>
</div>
<p>Update also parent element</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__parent</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__parent</span><span class="p">.</span><span class="nx">_autoUpdate</span><span class="p">(</span><span class="nx">update</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.importdb">
<h3>
<a href="#nddb.importdb" class="pilcrow">&#182;</a>
NDDB.importDB
</h3>
</div>
</div>
<div class="body"><p>Imports a whole array into the current database</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>db</span>
<span class="dox_type">array</span>
<span>Array of items to import</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">importDB</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">db</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">db</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">)</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">insert</span><span class="p">(</span><span class="nx">db</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
<span class="p">}</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-31" id="section-31">&#182;</a>
</div>
<!-- Check this
this.db = this.db.concat(this._masqueradeDB(db));
this._autoUpdate();
-->
</td>
<td class="code highlight"><div class="highlight"><pre><span class="p">};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.insert">
<h3>
<a href="#nddb.insert" class="pilcrow">&#182;</a>
NDDB.insert
</h3>
</div>
</div>
<div class="body"><p>Insert an item into the database</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>o</span>
<span class="dox_type">object</span>
<span>The item or array of items to insert</span>
</div>
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB._insert</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">insert</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o</span> <span class="o">||</span> <span class="nx">o</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">)</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_insert</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._insert">
<h3>
<a href="#nddb._insert" class="pilcrow">&#182;</a>
NDDB._insert
</h3>
</div>
</div>
<div class="body"><p>Inserts an object into the current database</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>o</span>
<span class="dox_type">object</span>
<span>The item or array of items to insert</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_insert</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o</span> <span class="o">||</span> <span class="nx">o</span> <span class="o">===</span> <span class="kc">null</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="nx">o</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">_masquerade</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-34" id="section-34">&#182;</a>
</div>
<p>We save time calling _hashIt only
on the latest inserted element</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">.</span><span class="nx">indexes</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_hashIt</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="p">}</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-35" id="section-35">&#182;</a>
</div>
<p>See above</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">_autoUpdate</span><span class="p">({</span><span class="nx">indexes</span><span class="o">:</span> <span class="kc">false</span><span class="p">});</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.breed">
<h3>
<a href="#nddb.breed" class="pilcrow">&#182;</a>
NDDB.breed
</h3>
</div>
</div>
<div class="body"><p>Creates a clone of the current NDDB object
with a reference to the parent database</p>
<p>Takes care of calling the actual constructor
of the class, so that inheriting objects will
preserve their prototype.</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>db</span>
<span class="dox_type">array</span>
<span>Array of items to import in the new database</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">NDDB</span>
<span>The new database</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">breed</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">db</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">db</span> <span class="o">=</span> <span class="nx">db</span> <span class="o">||</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">cloneSettings</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">parent</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__parent</span> <span class="o">||</span> <span class="k">this</span><span class="p">;</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-37" id="section-37">&#182;</a>
</div>
<p>In case the class was inherited</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">return</span> <span class="k">new</span> <span class="k">this</span><span class="p">.</span><span class="nx">constructor</span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">db</span><span class="p">,</span> <span class="nx">parent</span><span class="p">);</span>
<span class="p">};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.clonesettings">
<h3>
<a href="#nddb.clonesettings" class="pilcrow">&#182;</a>
NDDB.cloneSettings
</h3>
</div>
</div>
<div class="body"><p>Creates a configuration object to initialize
a new NDDB instance based on the current settings
and returns it</p>
</div>
<div class="details">
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">object</span>
<span>options A copy of the current settings</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">cloneSettings</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">H</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">;</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">C</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__C</span><span class="p">;</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">tags</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">tags</span><span class="p">;</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">update</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__update</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">clone</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
<span class="p">};</span> </pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.tostring">
<h3>
<a href="#nddb.tostring" class="pilcrow">&#182;</a>
NDDB.toString
</h3>
</div>
</div>
<div class="body"><p>Returns a human-readable representation of the database</p>
</div>
<div class="details">
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">string</span>
<span>out A human-readable representation of the database</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">toString</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">out</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">out</span> <span class="o">+=</span> <span class="k">this</span><span class="p">.</span><span class="nx">db</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;\n&quot;</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">out</span><span class="p">;</span>
<span class="p">};</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.stringify">
<h3>
<a href="#nddb.stringify" class="pilcrow">&#182;</a>
NDDB.stringify
</h3>
</div>
</div>
<div class="body"><p>Returns a machine-readable representation of the database</p>
<p>Cyclic objects are decycled.</p>
</div>
<div class="details">
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">string</span>
<span>out A machine-readable representation of the database</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">stringify</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">return</span> <span class="s1">&#39;[]&#39;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">objToStr</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-41" id="section-41">&#182;</a>
</div>
<p>Skip empty objects</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">JSUS</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span> <span class="k">return</span> <span class="s1">&#39;{}&#39;</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">out</span> <span class="o">=</span> <span class="s1">&#39;[&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-42" id="section-42">&#182;</a>
</div>
<p>decycle, if possible</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="nx">e</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">decycle</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
<span class="nx">out</span> <span class="o">+=</span> <span class="nx">objToStr</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;, &#39;</span><span class="p">;</span>
<span class="p">});</span>
<span class="nx">out</span> <span class="o">=</span> <span class="nx">out</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/, $/</span><span class="p">,</span><span class="s1">&#39;]&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">out</span><span class="p">;</span>
<span class="p">};</span> </pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.compare---nddb.c">
<h3>
<a href="#nddb.compare---nddb.c" class="pilcrow">&#182;</a>
NDDB.compare | NDDB.c
</h3>
</div>
</div>
<div class="body"><p>Registers a comparator function for dimension d</p>
<p>Each time a comparison between two objects containing
property named as the specified dimension, the registered
comparator function will be used.</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>d</span>
<span class="dox_type">string</span>
<span>The name of the dimension</span>
</div>
<div class="dox_tag_detail">
<span>comparator</span>
<span class="dox_type">function</span>
<span>The comparator function</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">boolean</span>
<span>TRUE, if registration was successful</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">compare</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">c</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">comparator</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">d</span> <span class="o">||</span> <span class="o">!</span><span class="nx">comparator</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Cannot set empty property or empty comparator&#39;</span><span class="p">,</span> <span class="s1">&#39;ERR&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__C</span><span class="p">[</span><span class="nx">d</span><span class="p">]</span> <span class="o">=</span> <span class="nx">comparator</span><span class="p">;</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.comparator">
<h3>
<a href="#nddb.comparator" class="pilcrow">&#182;</a>
NDDB.comparator
</h3>
</div>
</div>
<div class="body"><p>Retrieves the comparator function for dimension d.</p>
<p>If no comparator function is found, returns a generic
comparator function. </p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>d</span>
<span class="dox_type">string</span>
<span>The name of the dimension</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">function</span>
<span>The comparator function</span>
</div>
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB.compare</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">comparator</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="k">this</span><span class="p">.</span><span class="nx">__C</span><span class="p">[</span><span class="nx">d</span><span class="p">])</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">__C</span><span class="p">[</span><span class="nx">d</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">return</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">o1</span><span class="p">,</span> <span class="nx">o2</span><span class="p">)</span> <span class="p">{</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-45" id="section-45">&#182;</a>
</div>
<!--
NDDB.log('1' + o1);
NDDB.log('2' + o2);
-->
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o1</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o2</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o1</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">o2</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">v1</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">getNestedValue</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">o1</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">v2</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">getNestedValue</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">o2</span><span class="p">);</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-46" id="section-46">&#182;</a>
</div>
<!--
NDDB.log(v1);
NDDB.log(v2);
-->
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">v1</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">v2</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">v1</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">v2</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">v1</span> <span class="o">&gt;</span> <span class="nx">v2</span><span class="p">)</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">v2</span> <span class="o">&gt;</span> <span class="nx">v1</span><span class="p">)</span> <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">};</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.isreservedword">
<h3>
<a href="#nddb.isreservedword" class="pilcrow">&#182;</a>
NDDB.isReservedWord
</h3>
</div>
</div>
<div class="body"><p>Returns TRUE if a property or a method with the same name
already exists in the current instance od NDDB </p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>key</span>
<span class="dox_type">string</span>
<span>The name of the property</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">boolean</span>
<span>TRUE, if the property exists</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">isReservedWord</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.hash---nddb.h">
<h3>
<a href="#nddb.hash---nddb.h" class="pilcrow">&#182;</a>
NDDB.hash | NDDB.h
</h3>
</div>
</div>
<div class="body"><p>Registers a new hashing function for index d</p>
<p>Hashing functions automatically creates indexes
to retrieve objects faster</p>
<p>If no function is specified Object.toString is used.</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>idx</span>
<span class="dox_type">string</span>
<span>The name of index</span>
</div>
<div class="dox_tag_detail">
<span>func</span>
<span class="dox_type">function</span>
<span>The hashing function</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">boolean</span>
<span>TRUE, if registration was successful</span>
</div>
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB.isReservedWord</span>
</div>
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB.rebuildIndexes</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">hash</span> <span class="o">=</span> <span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">h</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">idx</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">idx</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;A valid index name must be provided&#39;</span><span class="p">,</span> <span class="s1">&#39;ERR&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">func</span> <span class="o">=</span> <span class="nx">func</span> <span class="o">||</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">toString</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">isReservedWord</span><span class="p">(</span><span class="nx">idx</span><span class="p">))</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">str</span> <span class="o">=</span> <span class="s1">&#39;A reserved word have been selected as an index. &#39;</span><span class="p">;</span>
<span class="nx">str</span> <span class="o">+=</span> <span class="s1">&#39;Please select another one: &#39;</span> <span class="o">+</span> <span class="nx">idx</span><span class="p">;</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="s1">&#39;ERR&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span> <span class="o">=</span> <span class="nx">func</span><span class="p">;</span>
<span class="k">this</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb.rebuildindexes">
<h3>
<a href="#nddb.rebuildindexes" class="pilcrow">&#182;</a>
NDDB.rebuildIndexes
</h3>
</div>
</div>
<div class="body"><p>Resets and rebuilds all the database indexes </p>
<p>Indexes are defined by the hashing functions</p>
</div>
<div class="details">
<div class="dox_tag_title">See</div>
<div class="dox_tag_detail">
<span class="dox_type">NDDB.hash</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">rebuildIndexes</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">JSUS</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span> </pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-50" id="section-50">&#182;</a>
</div>
<p>Reset current indexes</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
<span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_hashIt</span><span class="p">)</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._hashit">
<h3>
<a href="#nddb._hashit" class="pilcrow">&#182;</a>
NDDB._hashIt
</h3>
</div>
</div>
<div class="body"><p>Hashes an element and adds it to one of the indexes</p>
</div>
<div class="details">
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>o</span>
<span class="dox_type">object</span>
<span>The element to hash</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">boolean</span>
<span>TRUE, if insertion to an index was successful</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_hashIt</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">o</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">JSUS</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">h</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
<span class="nx">id</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
<span class="nx">hash</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">h</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">__H</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="nx">hash</span> <span class="o">=</span> <span class="nx">h</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">hash</span><span class="p">)</span> <span class="p">{</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span> <span class="p">{</span>
<span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">{};</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">][</span><span class="nx">hash</span><span class="p">])</span> <span class="p">{</span>
<span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">][</span><span class="nx">hash</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">NDDB</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">][</span><span class="nx">hash</span><span class="p">].</span><span class="nx">insert</span><span class="p">(</span><span class="nx">o</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">};</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap" id="sort-and-select">
<h2>
<a href="#sort-and-select" class="pilcrow">&#182;</a>
Sort and Select
</h2>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre></pre></div>
</td>
</tr>
<tr>
<td class="docs"><div class="dox">
<div class="summary">
<div class="pilwrap" id="nddb._analyzequery">
<h3>
<a href="#nddb._analyzequery" class="pilcrow">&#182;</a>
NDDB._analyzeQuery
</h3>
</div>
</div>
<div class="body"><p>Validates and prepares select queries before execution</p>
</div>
<div class="details">
<div class="dox_tag_title">API</div>
<div class="dox_tag_detail">
<span class="dox_type">private</span>
</span>
<div class="dox_tag_title">Params</div>
<div class="dox_tag_detail">
<span>d</span>
<span class="dox_type">string</span>
<span>The dimension of comparison</span>
</div>
<div class="dox_tag_detail">
<span>op</span>
<span class="dox_type">string</span>
<span>The operation to perform</span>
</div>
<div class="dox_tag_detail">
<span>value</span>
<span class="dox_type">string</span>
<span>The right-hand element of comparison</span>
</div>
<div class="dox_tag_title">Returns</div>
<div class="dox_tag_detail">
<span></span>
<span class="dox_type">boolean</span>
<span class="dox_type">object</span>
<span>The object-query or FALSE if an error was detected</span>
</div>
</div>
</div>
</td>
<td class="code highlight"><div class="highlight"><pre><span class="nx">NDDB</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_analyzeQuery</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">op</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">raiseError</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">op</span><span class="p">,</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">miss</span> <span class="o">=</span> <span class="s1">&#39;(?)&#39;</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">err</span> <span class="o">=</span> <span class="s1">&#39;Malformed query: &#39;</span> <span class="o">+</span> <span class="nx">d</span> <span class="o">||</span> <span class="nx">miss</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">op</span> <span class="o">||</span> <span class="nx">miss</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">value</span> <span class="o">||</span> <span class="nx">miss</span><span class="p">;</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="s1">&#39;WARN&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">};</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">d</span><span class="p">)</span> <span class="nx">raiseError</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">op</span><span class="p">,</span><span class="nx">value</span><span class="p">);</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-54" id="section-54">&#182;</a>
</div>
<p>Verify input </p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">op</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</span> <span class="o">===</span> <span class="k">typeof</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">raiseError</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">op</span><span class="p">,</span><span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">JSUS</span><span class="p">.</span><span class="nx">in_array</span><span class="p">(</span><span class="nx">op</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;&gt;&#39;</span><span class="p">,</span><span class="s1">&#39;&gt;=&#39;</span><span class="p">,</span><span class="s1">&#39;&gt;==&#39;</span><span class="p">,</span><span class="s1">&#39;&lt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;=&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;==&#39;</span><span class="p">,</span> <span class="s1">&#39;!=&#39;</span><span class="p">,</span> <span class="s1">&#39;!==&#39;</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="s1">&#39;==&#39;</span><span class="p">,</span> <span class="s1">&#39;===&#39;</span><span class="p">,</span> <span class="s1">&#39;&gt;&lt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;in&#39;</span><span class="p">,</span> <span class="s1">&#39;!in&#39;</span><span class="p">]))</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Query error. Invalid operator detected: &#39;</span> <span class="o">+</span> <span class="nx">op</span><span class="p">,</span> <span class="s1">&#39;WARN&#39;</span><span class="p">);</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">op</span> <span class="o">===</span> <span class="s1">&#39;=&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">op</span> <span class="o">=</span> <span class="s1">&#39;==&#39;</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-55" id="section-55">&#182;</a>
</div>
<p>Range-queries need an array as third parameter</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">JSUS</span><span class="p">.</span><span class="nx">in_array</span><span class="p">(</span><span class="nx">op</span><span class="p">,[</span><span class="s1">&#39;&gt;&lt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;in&#39;</span><span class="p">,</span> <span class="s1">&#39;!in&#39;</span><span class="p">]))</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="nx">value</span> <span class="k">instanceof</span> <span class="nb">Array</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">NDDB</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Range-queries need an array as third parameter&#39;</span><span class="p">,</span> <span class="s1">&#39;WARN&#39;</span><span class="p">);</span>
<span class="nx">raiseError</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">op</span><span class="p">,</span><span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">op</span> <span class="o">===</span> <span class="s1">&#39;&lt;&gt;&#39;</span> <span class="o">||</span> <span class="nx">op</span> <span class="o">===</span> <span class="s1">&#39;&gt;&lt;&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">setNestedValue</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
<span class="nx">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">setNestedValue</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span> <span class="nx">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span></pre></div>
</td>
</tr>
<tr>
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-56" id="section-56">&#182;</a>
</div>
<p>Encapsulating the value;</p>
</td>
<td class="code highlight"><div class="highlight"><pre> <span class="nx">value</span> <span class="o">=</span> <span class="nx">JSUS</span><span class="p">.</span><span class="nx">setNestedValue</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="s1">&#39;undefined&#39;</