end FUNCTION binary_search() HIST2C //
769470
function _hist2c( data, xEdges, yEdges ) {

		var id1, id2, counts = [];

		// Initialize our counts array: (all zeros):
		for ( var i = -1; i < xEdges.length; i++ ) {
			counts[ i+1 ] = [];
			for ( var j = -1; j < yEdges.length; j++ ) {
				counts[ i+1 ][ j+1 ] = 0;
			} // end FOR i
		} // end FOR j

		// For each value in the data array, find where the value resides along the edge vector in each dimension:
		for ( var k = 0; k < data.length; k++ ) {

			for ( var n = 0; n < data[ k ].length; n++ ) {

				// Perform a binary search along each dimension to find the index where the value equals or exceeds the corresponding value in the edge vector:
				id1 = binarysearch( xEdges, data[ k ][ n ][ 0 ] );
				id2 = binarysearch( yEdges, data[ k ][ n ][ 1 ] );

				// Update the counts for the bin:
				counts[ id1+1 ][ id2+1 ] += 1;

			} // end FOR n

		} // end FOR k

		// Return the counts:
		return counts;

	}
356248
private int binaryFirstSearch() {

        int low     = 0;
        int high    = count;
        int mid     = 0;
        int compare = 0;
        int found   = count;

        while (low < high) {
            mid     = (low + high) / 2;
            compare = compare(mid);

            if (compare < 0) {
                high = mid;
            } else if (compare > 0) {
                low = mid + 1;
            } else {
                high  = mid;
                found = mid;
            }
        }

        return found == count ? -1
                              : found;
    }
29708
def query_binary_data(self, target, display_mask, attr):
    """"""
    reply = NVCtrlQueryBinaryDataReplyRequest(display=self.display,
                                              opcode=self.display.get_extension_major(extname),
                                              target_id=target.id(),
                                              target_type=target.type(),
                                              display_mask=display_mask,
                                              attr=attr)
    if not reply._data.get('flags'):
        return None
    return reply._data.get('data')
555128
function histogram() {
  const histogram = {
    r: new Array(256).fill(0),
    g: new Array(256).fill(0),
    b: new Array(256).fill(0)
  };

  this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
    x,
    y,
    index
  ) {
    histogram.r[this.bitmap.data[index + 0]]++;
    histogram.g[this.bitmap.data[index + 1]]++;
    histogram.b[this.bitmap.data[index + 2]]++;
  });

  return histogram;
}
165342
function() {
        gobbleSpaces();
        var to_check = expr.substr(index, max_binop_len),
          tc_len = to_check.length;
        while (tc_len > 0) {
          if (binary_ops.hasOwnProperty(to_check)) {
            index += tc_len;
            return to_check;
          }
          to_check = to_check.substr(0, --tc_len);
        }
        return false;
      }
1120172
function() {
    const buf8 = pslBuffer8;
    const buf32 = pslBuffer32;
    const iCharData = buf32[CHARDATA_PTR_SLOT];

    let iNode = pslBuffer32[RULES_PTR_SLOT];
    let cursorPos = -1;
    let iLabel = LABEL_INDICES_SLOT;

    // Label-lookup loop
    for (;;) {
        // Extract label indices
        const labelBeg = buf8[iLabel+1];
        const labelLen = buf8[iLabel+0] - labelBeg;
        // Match-lookup loop: binary search
        let r = buf32[iNode+0] >>> 16;
        if ( r === 0 ) { break; }
        const iCandidates = buf32[iNode+2];
        let l = 0;
        let iFound = 0;
        while ( l < r ) {
            const iCandidate = l + r >>> 1;
            const iCandidateNode = iCandidates + iCandidate + (iCandidate << 1);
            const candidateLen = buf32[iCandidateNode+0] & 0x000000FF;
            let d = labelLen - candidateLen;
            if ( d === 0 ) {
                const iCandidateChar = candidateLen <= 4
                    ? iCandidateNode + 1 << 2
                    : iCharData + buf32[iCandidateNode+1];
                for ( let i = 0; i < labelLen; i++ ) {
                    d = buf8[labelBeg+i] - buf8[iCandidateChar+i];
                    if ( d !== 0 ) { break; }
                }
            }
            if ( d < 0 ) {
                r = iCandidate;
            } else if ( d > 0 ) {
                l = iCandidate + 1;
            } else /* if ( d === 0 ) */ {
                iFound = iCandidateNode;
                break;
            }
        }
        // 2. If no rules match, the prevailing rule is "*".
        if ( iFound === 0 ) {
            if ( buf8[iCandidates + 1 << 2] !== 0x2A /* '*' */ ) { break; }
            iFound = iCandidates;
        }
        iNode = iFound;
        // 5. If the prevailing rule is a exception rule, modify it by
        //    removing the leftmost label.
        if ( (buf32[iNode+0] & 0x00000200) !== 0 ) {
            if ( iLabel > LABEL_INDICES_SLOT ) {
                return iLabel - 2;
            }
            break;
        }
        if ( (buf32[iNode+0] & 0x00000100) !== 0 ) {
            cursorPos = iLabel;
        }
        if ( labelBeg === 0 ) { break; }
        iLabel += 2;
    }

    return cursorPos;
}
1089098
private int binarySearch(List<SparseItemset> candidates, SparseItemset scratch, int begin, int end) {
    --end;
    while(begin < end) {
      final int mid = (begin + end) >>> 1;
      SparseItemset midVal = candidates.get(mid);
      int cmp = midVal.compareTo(scratch);

      if(cmp < 0) {
        begin = mid + 1;
      }
      else if(cmp > 0) {
        end = mid - 1;
      }
      else {
        return mid; // key found
      }
    }
    return -(begin + 1); // key not found, return next
  }
712659
def discrete_binary_search(tab, lo, hi):
    
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if tab[mid]:
            hi = mid
        else:
            lo = mid + 1
    return lo
15560
function parseBinaryExpression() {
        var expr, token, prec, stack, right, operator, left, i;

        left = parseUnaryExpression();

        token = lookahead;
        prec = binaryPrecedence(token);
        if (prec === 0) {
            return left;
        }
        token.prec = prec;
        lex();

        right = parseUnaryExpression();

        stack = [left, token, right];

        while ((prec = binaryPrecedence(lookahead)) > 0) {

            // Reduce: make a binary expression from the three topmost entries.
            while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
                right = stack.pop();
                operator = stack.pop().value;
                left = stack.pop();
                expr = delegate.createBinaryExpression(operator, left, right);
                stack.push(expr);
            }

            // Shift.
            token = lex();
            token.prec = prec;
            stack.push(token);
            expr = parseUnaryExpression();
            stack.push(expr);
        }

        // Final reduce to clean-up the stack.
        i = stack.length - 1;
        expr = stack[i];
        while (i > 1) {
            expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
            i -= 2;
        }

        return expr;
    }
313152
def binb2b64(binarray)
      tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
      str = ''

      # for(var i = 0; i < binarray.length * 4; i += 3)
      i = 0
      while i < binarray.length * 4
        triplet = (((binarray[i >> 2].to_i >> 8 * (3 - i % 4)) & 0xFF) << 16) |
                     (((binarray[i + 1 >> 2].to_i >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
                      ((binarray[i + 2 >> 2].to_i >> 8 * (3 - (i + 2) % 4)) & 0xFF)
        # for(var j = 0; j < 4; j++)
        j = 0
        while j < 4
          if i * 8 + j * 6 > binarray.length * 32
            str += $b64pad
          else
            str += tab[(triplet >> 6 * (3 - j)) & 0x3F].chr
          end
          j += 1
        end
        i += 3
      end
      str
    end
1315190
def binary_search(data, target, lo=0, hi=None):
    
    hi = hi if hi is not None else len(data)
    mid = (lo + hi) // 2
    if hi < 2 or hi > len(data) or target > data[-1] or target < data[0]:
        return -1
    if data[mid] > target:
        return binary_search(data, target, lo=lo, hi=mid)
    elif data[mid] < target:
        return binary_search(data, target, lo=(mid + 1), hi=hi)
    elif data[mid] == target:
        return mid
1336490
def binary_search(pVector, pElement)
      pVector.bsearch { |obj| pElement.name <=> obj.name }
    end
966992
private int binaryGreaterSearch() {

        int low     = 0;
        int high    = count;
        int mid     = 0;
        int compare = 0;

        while (low < high) {
            mid     = (low + high) / 2;
            compare = compare(mid);

            if (compare < 0) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        return low == count ? -1
                            : low;
    }
1151154
function __() {
    var us = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

    store = typeof us === "boolean" ? us : store;
    us = typeof us === "boolean" ? [] : us;

    var seq = []; //seq is vanilla JS array + features
    seq.id = getID();
    seq.store = store;
    seq.us = us;
    seq.ds = [];
    seq.updatedTo = {};
    seq.us.map(function (u) {
      //  seq is a member of u.ds
      u.ds[u.ds.length] = seq;
      u.updatedTo[seq.id] = 0; // non-interference dependency
    });
    seq.IndexOnTimestamp = {};
    seq.TimestampOnIndex = {};
    seq.propagating = 0;
    seq.done = 0;
    seq.eqs = [];
    seq.addEq = function (eq) {
      return seq.eqs[seq.eqs.length] = eq;
    };
    seq.evalEqs = function (val) {
      var val0 = val;
      seq.eqs.map(function (eq) {
        return val = eq(val);
      });
      return seq.us.length === 0 ? val0 : val;
    };
    //api-----------------
    Object.keys(__.api).map(function (api) {
      seq[api] = __.api[api](__, seq, store);
    });
    //-----------------
    Object.defineProperties(seq, //detect t update on each seqs
    {
      t: {
        //foo.t
        get: function get() {
          return seq.valOnT;
        },
        set: function set(tval) {
          var sanityCheck = seq.propagating === 0 && seq.us.length !== 0 ? function () {
            throw new Error("Do not set a value of the sequence that depends on other sequences!");
          }() : function () {
            seq.propagating = 0;
            var core = seq.done === 0 ? function () {
              seq.valOnT = seq.evalEqs(tval); //self eqs eval
              seq.T = Date.now();
              var core1 = store ? function () {
                seq.IndexOnTimestamp[seq.T] = seq.length;
                seq.TimestampOnIndex[seq.length] = seq.T;
                seq[seq.length] = seq.valOnT; //after funcs
              }() : true;
              Object.keys(seq.updatedTo).map(function (key) {
                seq.updatedTo[key] = 1;
              });
              //clear updated us in non-interference way
              seq.us.map(function (u) {
                return u.updatedTo[seq.id] = 0;
              });
              seq.ds.map(function (d) {
                var usAllUpdated = d.us.map(function (u) {
                  return u.updatedTo[d.id];
                }).reduce(function (a, b) {
                  return a * b;
                });
                var core2 = usAllUpdated === 1 ? function () {
                  d.propagating = 1;
                  d.t = d.us.map(function (u) {
                    return u.t;
                  });
                }() : true;
              });
            }() : true;
          }();
        }
      }
    });
    return seq;
  }
495465
function addBinaries(binaries) {
	var SLICE = Array.prototype.slice;
	//iterate backwards to mimic normal resolution order
	for (var i = binaries.length-1; i >= 0; i--) {
		var parts = binaries[i].split('/');
		(function() {var name = parts[parts.length-1];
		exports[name] = function() {

			//grab the last argument, which might be a callback

			var cbs = SLICE.call(arguments, 3);
			//assume none of the args we got were handlers
			var args = SLICE.call(arguments);
			var argLength = args.length;
		
			var cb, stdoutHandler, stderrHandler, options;
			if (args[argLength-3] instanceof Function) {
				//we have all 3
				stderrHandler = args.pop();
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-2] instanceof Function) {
				//we have cb and stdout 
				stdoutHandler = args.pop();
				cb = args.pop();
			} else if (arguments[argLength-1] instanceof Function) {
				//we have cb only
				cb = args.pop();
			}

			//if the last arg is an object, it's the options object
			var lastArg = args[args.length-1];
			if (typeof lastArg == 'object' && !lastArg.length) {
				options = args.pop();
			}
			//if the first argument was an array, the args were passed as
			//an array
			if (args[0] instanceof Array) {
				args = args[0];
			}
			
			return runCommand(name, args, options, cb, stdoutHandler, stderrHandler);

		};})();
	}
}
881877
private V binarySearch(final K iKey) {
    int low = 0;
    int high = getSize() - 1;
    int mid = 0;

    while (low <= high) {
      mid = (low + high) >>> 1;
      Object midVal = getKeyAt(mid);

      if (tree.comparator != null)
        tree.pageItemComparator = tree.comparator.compare((K) midVal, iKey);
      else
        tree.pageItemComparator = ((Comparable<? super K>) midVal).compareTo(iKey);

      if (tree.pageItemComparator == 0) {
        // FOUND: SET THE INDEX AND RETURN THE NODE
        tree.pageItemFound = true;
        tree.pageIndex = mid;
        return getValueAt(tree.pageIndex);
      }

      if (low == high)
        break;

      if (tree.pageItemComparator < 0)
        low = mid + 1;
      else
        high = mid;
    }

    tree.pageIndex = mid;
    return null;
  }
681309
function() {
        var node, biop, prec, stack, biop_info, left, right, i;

        // First, try to get the leftmost thing
        // Then, check to see if there's a binary operator operating on that leftmost thing
        left = gobbleToken();
        biop = gobbleBinaryOp();

        // If there wasn't a binary operator, just return the leftmost node
        if (!biop) {
          return left;
        }

        // Otherwise, we need to start a stack to properly place the binary operations in their
        // precedence structure
        biop_info = { value: biop, prec: binaryPrecedence(biop) };

        right = gobbleToken();
        if (!right) {
          throwError("Expected expression after " + biop, index);
        }
        stack = [left, biop_info, right];

        // Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)
        while ((biop = gobbleBinaryOp())) {
          prec = binaryPrecedence(biop);

          if (prec === 0) {
            break;
          }
          biop_info = { value: biop, prec: prec };

          // Reduce: make a binary expression from the three topmost entries.
          while (stack.length > 2 && prec <= stack[stack.length - 2].prec) {
            right = stack.pop();
            biop = stack.pop().value;
            left = stack.pop();
            node = createBinaryExpression(biop, left, right);
            stack.push(node);
          }

          node = gobbleToken();
          if (!node) {
            throwError("Expected expression after " + biop, index);
          }
          stack.push(biop_info, node);
        }

        i = stack.length - 1;
        node = stack[i];
        while (i > 1) {
          node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node);
          i -= 2;
        }
        return node;
      }