lib/ProfileIndex.js
function( index_offset, size, depth, prefix, testVar, callback ) {
		if (size == 0) 
			return prefix + this.indent + "/* No items */\n";
		var code = "";
			genChunk = (function( s, e, d, pf ) {
				if (d === 0) {
					code += pf + "switch ("+testVar+") {\n";
					for (var i=s; i<e; ++i) {
						code += pf + this.indent + "case "+(index_offset+i)+": return "+callback(i);
					}
					code += pf + "}\n";
				} else {

					// No items
					if (e == s) {

					// Only 1 item
					} else if (e == s+1) {
						code += pf + "if (" + testVar + " === " + (index_offset+s) + ")\n";
						code += pf + this.indent + "return "+callback(s);
					} else {
						var mid = Math.round((s+e) / 2);
						code += pf + "if (" + testVar + " < " + (index_offset+mid) + ") {\n";
						genChunk(s, mid, d - 1, pf + this.indent);
						code += pf + "} else {\n";
						genChunk(mid, e, d - 1, pf + this.indent);
						code += pf + "}\n";
					}
				}
			}).bind(this);
		genChunk( 0, size, depth, prefix + this.indent );
		return code;
	}
function( index_offset, size, depth, prefix, testVar, callback ) {
		if (size == 0) 
			return prefix + this.indent + "/* No items */\n";
		var code = "";
			genChunk = (function( s, e, d, pf ) {
				if (d === 0) {
					code += pf + "switch ("+testVar+") {\n";
					for (var i=s; i<e; ++i) {
						code += pf + this.indent + "case "+(index_offset+i)+": return "+callback(i);
					}
					code += pf + "}\n";
				} else {

					// No items
					if (e == s) {

					// Only 1 item
					} else if (e == s+1) {
						code += pf + "if (" + testVar + " === " + (index_offset+s) + ")\n";
						code += pf + this.indent + "return "+callback(s);
					} else {
						var mid = Math.round((s+e) / 2);
						code += pf + "if (" + testVar + " < " + (index_offset+mid) + ") {\n";
						genChunk(s, mid, d - 1, pf + this.indent);
						code += pf + "} else {\n";
						genChunk(mid, e, d - 1, pf + this.indent);
						code += pf + "}\n";
					}
				}
			}).bind(this);
		genChunk( 0, size, depth, prefix + this.indent );
		return code;
	}
function ( index_offset , size , depth , prefix , testVar , callback ) { if ( size == 0 ) return prefix + this . indent + "/* No items */\n" ; var code = "" ; genChunk = ( function ( s , e , d , pf ) { if ( d === 0 ) { code += pf + "switch (" + testVar + ") {\n" ; for ( var i = s ; i < e ; ++ i ) { code += pf + this . indent + "case " + ( index_offset + i ) + ": return " + callback ( i ) ; } code += pf + "}\n" ; } else { // No items if ( e == s ) { // Only 1 item } else if ( e == s + 1 ) { code += pf + "if (" + testVar + " === " + ( index_offset + s ) + ")\n" ; code += pf + this . indent + "return " + callback ( s ) ; } else { var mid = Math . round ( ( s + e ) / 2 ) ; code += pf + "if (" + testVar + " < " + ( index_offset + mid ) + ") {\n" ; genChunk ( s , mid , d - 1 , pf + this . indent ) ; code += pf + "} else {\n" ; genChunk ( mid , e , d - 1 , pf + this . indent ) ; code += pf + "}\n" ; } } } ) . bind ( this ) ; genChunk ( 0 , size , depth , prefix + this . indent ) ; return code ; }
Generates a divide-and-conquer nested if-statements
up to maximum 'depth' steps deep. After that it performs
equality testing using a switch-case statement.

This is intended for optimizing the lookup speed of
elements when processing.
Generates a divide - and - conquer nested if - statements up to maximum depth steps deep . After that it performs equality testing using a switch - case statement .