def _match_hash(x, y, no_match=None):
    """Returns an array of the positions of (first) matches of y in x
    
    This is similar to R's `match` or Matlab's `[Lia, Locb] = ismember`
    
    As in R's `match`, a hash (i.e. dictionary) is built to do the
    mapping.
    """

    x_val2ind = {v: i for i, v in enumerate(x)}
    y_ind = [x_val2ind.get(v, no_match) for v in y]

    return y_ind