/*\
|*| Calculates the relative search term based on the given root.
\
502836
function getRelativeTerm(term, root) {
  term = term.slice(root.length);
  return _.str.trim(term, path.sep);
}
1161095
private int findEqual(
    SearchComparator  comp,
    int               lower,
    int               upper,
    Object            searchKey)
  {
    int nkeys = numKeys(lower, upper);
    int idx = -1;
    if (nkeys < 4)
      idx = sequentialSearchEqual(comp, lower, upper, searchKey);
    else
      idx = binarySearchEqual(comp, lower, upper, searchKey);
    return idx;
  }
43649
function findAncestor(node, predicate) {
  var last = false;
  while (node != null && !(last = predicate(node))) {
    node = node.parentNode;
  }
  return last ? node : null;
}
475677
function filter(p, rules, root, isDirectory, included) {
  p = path.relative(root, p);
  for (var i in rules) {
    var rule = rules[i];
    if (isDirectory) {
      if (rule.match(p) || rule.match("/" + p) ||
          rule.match(p + "/") || rule.match("/" + p + "/")
         ) {
        return rule.negate;
      }
    } else {
      if (rule.match(p) || rule.match("/" + p)) {
        return rule.negate;
      }
    }
  }
  return included;
}
1305425
function GetInitialRootInformation(filter_manager){

    var search = _create_manager('ontology');

    // Initial trigger over root terms.
    var rt = [];
    us.each(sd.root_terms, function(pair){
	rt.push(pair['id']);
    });
    search.set_ids(rt);

    // Ready the callback.
    search.register('search', function(resp, man){
	
	// Verify and extract initial response.
	if( resp && resp.documents() && resp.documents().length ){	    
	    global_root_docs = resp.documents();
	    console.log('Starting root gene product search with (' +
			global_root_docs.length + ') documents.');
	    GetRootCountInformation(global_root_docs, filter_manager);
	}else{
	    alert('failure to find root information');
	}
    });

    search.search();
}
1343983
def get_relative_path(self, root):
        
        if self.path == root:
            return ''
        ancestors = self.ancestors(stop=root)
        return functools.reduce(lambda f, p: Folder(p.name).child(f),
                                ancestors,
                                self.name)
823065
def find(root: Union[Path, str], dirs: bool = True) -> str:
    
    if isinstance(root, str):
        root = Path(root)

    results: List[Path] = []
    for dirpath, dirnames, filenames in os.walk(root):
        names = filenames
        if dirs:
            names += dirnames
        for name in names:
            results.append(Path(dirpath) / name)
    results.sort()
    return "\n".join(str(result.relative_to(root)) for result in results)
691783
function calculateRootPosition(layoutInfo, rootRect, targetInfo) {
    if (rootRect) {
        return {x: rootRect.x, y: rootRect.y};
    }

    var defaultPosition = {x: 0, y: 0};
    if (!targetInfo) {
        return defaultPosition;
    }

    // If targetInfo is fetched by 'retrieveTargetInfo',
    // old tree and new tree are the same tree,
    // so the node still exists and we can visit it.

    var targetNode = targetInfo.node;
    var layout = targetNode.getLayout();

    if (!layout) {
        return defaultPosition;
    }

    // Transform coord from local to container.
    var targetCenter = [layout.width / 2, layout.height / 2];
    var node = targetNode;
    while (node) {
        var nodeLayout = node.getLayout();
        targetCenter[0] += nodeLayout.x;
        targetCenter[1] += nodeLayout.y;
        node = node.parentNode;
    }

    return {
        x: layoutInfo.width / 2 - targetCenter[0],
        y: layoutInfo.height / 2 - targetCenter[1]
    };
}
504606
function(_root,_umi,_hanlder){
        var _node = _root,
            _hanlder = _hanlder||_f;
        if (_umi!='/'){
            _u._$forEach(
                _umi.split('/'),function(_name){
                    var _result = _hanlder(_node,_name);
                    if (!_result) 
                        return !0;
                    _node = _result;
                }
            );
        }
        return _node;
    }
686722
function bsearch(arr, val, key) {
  var pred = typeof val === 'function' ? val : (typeof key === 'string'
    ? function(item) { return val <= item[key]; }
    : function(item) { return val <= item; });

  var lo = -1, hi = arr.length;
  while (1 + lo !== hi) {
    var mi = lo + ((hi - lo) >> 1);
    if (pred(arr[mi])) {
      hi = mi;
    } else {
      lo = mi;
    }
  }
  return hi;
}
496929
def add_root_match(self, lst_idx, root_idx):
        """"""
        self.root_matches[lst_idx] = root_idx
        if lst_idx in self.in_result_idx:
            return

        self.not_in_result_root_match_idx.add(lst_idx)
386602
function searchAround (
    getValue, getConditionValue, value, conditionValue, i, arr
  ) {
    var start = i;
    var elm = arr[i];

    while (elm && (
      getValue(elm) !== value || getConditionValue(elm) !== conditionValue)
    ) {
      elm = arr[--i];
    }

    if (!elm || getValue(elm) !== value) {
      i = Math.min(arr.length, start + 1);
      elm = arr[i];
    }

    while (elm && (
      getValue(elm) !== value || getConditionValue(elm) !== conditionValue)
    ) {
      elm = arr[++i];
    }

    if (!elm || getValue(elm) !== value) {
      return -1;
    }

    return i;
  }
600091
function ancestorSearch (getValue, value, isAncestor, tree) {
    if (getValue(tree) === value) {
      return tree;
    }

    var index = binaryIndexBy(getValue, value, tree.children);
    var child1 = tree.children[index];
    var child0 = tree.children[index - 1];

    if (child1 && isAncestor(value, child1)) {
      return ancestorSearch(getValue, value, isAncestor, child1);
    }

    if (child0 && isAncestor(value, child0)) {
      return ancestorSearch(getValue, value, isAncestor, child0);
    }

    return tree;
  }
1156816
function getRoot(term, opts) {
  var parts = term.split(path.sep);
  var root = parts.shift() || path.sep; // Windows support, I hope?

  // Last section treated as term if not suffixed by path separator.
  for(var i = 0; i < parts.length - 1; i++) {
    var tryPath = path.join(root, parts[i]);
    try {
      var stat = fs.statSync(tryPath);
      if(!stat.isDirectory()) {
        break;
      }
    } catch (e) {
      if(e.code === 'ENOENT') {
        break;
      }
      throw e;
    }
    root = tryPath;
  }
  root = util.normalizePath(root);
  return root;
}
78590
def find_root(node):
    """"""
    # Scamper up to the top level namespace
    while node.type != syms.file_input:
        node = node.parent
        if not node:
            raise ValueError("root found before file_input node was found.")
    return node
1210348
private void search(double[] q, Node node, Neighbor<double[], E> neighbor) {
        if (node.isLeaf()) {
            // look at all the instances in this leaf
            for (int idx = node.index; idx < node.index + node.count; idx++) {
                if (q == keys[index[idx]] && identicalExcluded) {
                    continue;
                }

                double distance = Math.squaredDistance(q, keys[index[idx]]);
                if (distance < neighbor.distance) {
                    neighbor.key = keys[index[idx]];
                    neighbor.value = data[index[idx]];
                    neighbor.index = index[idx];
                    neighbor.distance = distance;
                }
            }
        } else {
            Node nearer, further;
            double diff = q[node.split] - node.cutoff;
            if (diff < 0) {
                nearer = node.lower;
                further = node.upper;
            } else {
                nearer = node.upper;
                further = node.lower;
            }

            search(q, nearer, neighbor);

            // now look in further half
            if (neighbor.distance >= diff * diff) {
                search(q, further, neighbor);
            }
        }
    }
287824
function resolveInRoot(root) {
    var input, result;
    var args = Array.prototype.slice.call(arguments, 1);

    input = args
        .reduce(function(current, p) {
            // Handle path relative to book root ("/README.md")
            if (p[0] == '/' || p[0] == '\\') return p.slice(1);

            return current? path.join(current, p) : path.normalize(p);
        }, '');

    result = path.resolve(root, input);

    if (!isInRoot(root, result)) {
        throw new error.FileOutOfScopeError({
            filename: result,
            root: root
        });
    }

    return result;
}