Find the mapping that best matches the hypothetical "needle" mapping that we are searching for in the given "haystack" of mappings.
18204
<T> int _findMapping(T aNeedle, List<T> aMappings, Object aLineName, Object aColumnName, BinarySearch.Comparator<T> aComparator,
            BinarySearch.Bias aBias) {
        // To return the position we are searching for, we must first find the
        // mapping for the given position and then return the opposite position it
        // points to. Because the mappings are sorted, we can use binary search to
        // find the best mapping.

        // if (aNeedle[aLineName] <= 0) {
        // throw new TypeError("Line must be greater than or equal to 1, got " + aNeedle[aLineName]);
        // }
        // if (aNeedle[aColumnName] < 0) {
        // throw new TypeError("Column must be greater than or equal to 0, got " + aNeedle[aColumnName]);
        // }

        return BinarySearch.search(aNeedle, aMappings, aComparator, aBias);
    }
276999
def mapping_get(uri, mapping):
    
    ln = localname(uri)
    # 1. try to match URI keys
    for k, v in mapping.items():
        if k == uri:
            return v
    # 2. try to match local names
    for k, v in mapping.items():
        if k == ln:
            return v
    # 3. try to match local names with * prefix
    # try to match longest first, so sort the mapping by key length
    l = list(mapping.items())
    l.sort(key=lambda i: len(i[0]), reverse=True)
    for k, v in l:
        if k[0] == '*' and ln.endswith(k[1:]):
            return v
    raise KeyError(uri)
425963
function (needle, haystack) {
            needle.width = needle.width || 0;
            needle.height = needle.height || 0;
            if (haystack == this.VIEWPORT) {
                return this.isInViewport({
                    left : needle.x,
                    top : needle.y
                }, {
                    width : needle.width,
                    height : needle.height
                });
            }
            haystack.width = haystack.width || 0;
            haystack.height = haystack.height || 0;
            if (needle.x < haystack.x || needle.y < haystack.y || needle.x + needle.width > haystack.x + haystack.width
                    || needle.y + needle.height > haystack.y + haystack.height) {
                return false;
            }
            return true;
        }
536471
def matches? meth
      Citero.map("").respond_to?(meth) && ( directionize(meth).eql?("to") || directionize(meth).eql?(meth.to_s) )
    end
529468
def find_best_match(path, prefixes):
    """"""
    path_parts = path.split('.')
    for p in prefixes:
        if len(p) <= len(path_parts) and p == path_parts[:len(p)]:
            return '.'.join(p), '.'.join(path_parts[len(p):])
    return '', path
898160
function(needle, haystack) {
		var m = false;

		for (var i in haystack) {
			if (i === '*') m = '*';
			else if (urlglob(i, needle)) return i;
		}

		return m;
	}
964037
function trueOrMatch(needle, haystack) {
  if (needle === true) {
    return true;
  }
  if (_.isRegExp(needle) && needle.test(haystack)) {
    return true;
  }
  if (_.isString(needle) && haystack.indexOf(needle) !== -1) {
    return true;
  }
  if (needle instanceof Array) {
    for (var i in needle) {
      if (trueOrMatch(needle[i], haystack)) {
        return true;
      }
    }
  }
  return false;
}
522560
public static <K> Matcher<Multimap<K, ?>> hasSameKeySet(final Set<K> comparison) {
        return IsMultimapWithKeySet.hasSameKeySet(comparison);
    }
245118
def find_broadly_matched_key(self, broad, string):
        """"""
        keys = list(broad.keys())
        for i in range(0, len(keys)):
            key = keys[i]
            if string.find(key) >= 0:
                return key
        return None
143
def match_files(self, matched, unmatched):
        """"""
        for pattern in self.iter():
            pattern.match_files(matched, unmatched)
            if not unmatched:
                # Optimization: If we have matched all files already
                # simply return at this point - nothing else to do
                break
1215055
function _findIndex(haystack, needle) {
            if (angular.isUndefined(haystack) || haystack.length === 0) {
                return -1;
            }

            for (var i = 0, len = haystack.length; i < len; i++) {
                if (haystack[i] === needle) {
                    return i;
                }
            }

            return -1;
        }
1071991
function (needle, haystack, strict) {

            var found = false;

            strict = !!strict;

            $this.each(haystack, function (key) {
                /* jshint -W116 */
                if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
                    found = true;
                    return false;
                }
                /* jshint +W116 */
            });

            return found;
        }
264496
def match(self, other):
        ''' '''
        colortext.message("FASTA Match")
        for frompdbID, fromchains in sorted(self.iteritems()):
            matched_pdbs = {}
            matched_chains = {}
            for fromchain, fromsequence in fromchains.iteritems():
                for topdbID, tochains in other.iteritems():
                    for tochain, tosequence in tochains.iteritems():
                        if fromsequence == tosequence:
                            matched_pdbs[topdbID] = matched_pdbs.get(topdbID, set())
                            matched_pdbs[topdbID].add(fromchain)
                            matched_chains[fromchain] = matched_chains.get(fromchain, [])
                            matched_chains[fromchain].append((topdbID, tochain))
            foundmatches = []
            colortext.printf("  %s" % frompdbID, color="silver")
            for mpdbID, mchains in matched_pdbs.iteritems():
                if mchains == set(fromchains.keys()):
                    foundmatches.append(mpdbID)
                    colortext.printf("  PDB %s matched PDB %s on all chains" % (mpdbID, frompdbID), color="white")
            if foundmatches:
                for fromchain, fromsequence in fromchains.iteritems():
                    colortext.printf("    %s" % (fromchain), color = "silver")
                    colortext.printf("      %s" % (fromsequence), color = self.unique_sequences[fromsequence])
                    mstr = []
                    for mchain in matched_chains[fromchain]:
                        if mchain[0] in foundmatches:
                            mstr.append("%s chain %s" % (mchain[0], mchain[1]))
                    colortext.printf("	  Matches: %s" % ", ".join(mstr))
            else:
                colortext.error("    No matches found.")
395124
def search_mappings(kb, key=None, value=None, match_type=None,
                        sortby=None, page=None, per_page=None):
        """"""
        if kb.kbtype == models.KnwKB.KNWKB_TYPES['written_as']:
            return pagination.RestfulSQLAlchemyPagination(
                api.query_kb_mappings(
                    kbid=kb.id,
                    key=key or '',
                    value=value or '',
                    match_type=match_type or 's',
                    sortby=sortby or 'to',
                ), page=page or 1, per_page=per_page or 10
            ).items
        return []
595689
def _get_best_type_from_mapping(mapping):
    
    best_type_name = None
    best_mapping = None
    for k, m in mapping.items():
        if k == "_default_":
            continue
        if best_type_name is None or len(m.properties) > len(best_mapping.properties):
            best_type_name = k
            best_mapping = m
    if best_type_name == None:
        return "_default_", mapping["_default_"]
    return best_type_name, best_mapping
495456
def find_mapping(es_url, index):
    

    mapping = None

    backend = find_perceval_backend(es_url, index)

    if backend:
        mapping = backend.get_elastic_mappings()

    if mapping:
        logging.debug("MAPPING FOUND:\n%s", json.dumps(json.loads(mapping['items']), indent=True))
    return mapping
426761
function findAllIndices() {
  var needle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mandatory();
  var haystack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mandatory();

  var indices = [];
  for (var i = 0; i < haystack.length; i++) {
    if (haystack.substr(i, needle.length) === needle) {
      indices.push(i);
    }
  }

  if (indices.length) {
    return indices;
  } else {
    return -1;
  }
}