/**
   * @throws IllegalArgumentException if the pattern length is larger than 31 / ⌈
   *     log<sub>2</sub> (k + 1) &rceil;
   * @see com.eaio.stringsearch.MismatchSearch#processChars(char[], int)
   */
  public Object processChars(char[] pattern, int k) {

    Object type = MISMATCH;

    if ((k << 1) > pattern.length) {
      type = MATCH;
      k = pattern.length - k;
    }

    int b = clog2(k + 1) + 1;

    if (pattern.length > (31 / b)) {
      throw new IllegalArgumentException();
    }

    /* Preprocessing */

    int i;
    int lim = k << ((pattern.length - 1) * b);
    int ovmask = 0;

    for (i = 0; i < pattern.length; i++) {
      ovmask = (ovmask << b) | (1 << (b - 1));
    }

    CharIntMap t;

    if (type == MATCH) {
      t = createCharIntMap(pattern);
    } else {
      lim += 1 << ((pattern.length - 1) * b);
      t = createCharIntMap(pattern, ovmask >> (b - 1));
    }

    i = 1;
    for (int p = 0; p < pattern.length; p++, i <<= b) {
      if (type == MATCH) {
        t.set(pattern[p], t.get(pattern[p]) + i);
      } else {
        t.set(pattern[p], t.get(pattern[p]) & ~i);
      }
    }

    return new Object[] {
      t,
      type,
      Integer.valueOf(i - 1),
      Integer.valueOf(ovmask),
      Integer.valueOf(b),
      Integer.valueOf(lim)
    };
  }
示例#2
0
  /**
   * Pre-processing of the pattern. The pattern may not exceed 31 characters in length. If it does,
   * <b>only it's first 31 characters</b> are processed which might lead to unexpected results.
   * Returns a {@link CharIntMap}.
   *
   * @param char[] the pattern
   * @return an Object
   * @see StringSearch#processChars(char[])
   */
  public Object processChars(char[] pattern) {
    int end = Math.min(pattern.length, 31);

    CharIntMap m = createCharIntMap(pattern, ~0);

    for (int i = 0; i < end; ++i) {
      m.set(pattern[i], m.get(pattern[i]) & ~(1 << i));
    }

    return m;
  }
示例#3
0
  /**
   * Pre-processing of the pattern. The pattern may not exceed 32 bytes in length. If it does,
   * <b>only it's first 32 bytes</b> are processed which might lead to unexpected results. Returns a
   * {@link CharIntMap} which is serializable.
   *
   * @see com.eaio.stringsearch.StringSearch#processChars(char[])
   */
  @Override
  public Object processChars(char[] pattern) {
    int end = pattern.length < 32 ? pattern.length : 32;

    CharIntMap b = createCharIntMap(pattern, end, 0);

    int j = 1;
    for (int i = end - 1; i >= 0; --i, j <<= 1) {
      b.set(pattern[i], b.get(pattern[i]) | j);
    }

    return b;
  }
  /**
   * Returns a {@link CharIntMap} for patterns longer than 2 characters, <code>null</code>
   * otherwise.
   *
   * @see com.eaio.stringsearch.StringSearch#processChars(char[])
   */
  @Override
  public Object processChars(char[] pattern) {
    if (pattern.length == 1 || pattern.length == 2) {
      return null;
    }

    CharIntMap skip = createCharIntMap(pattern, pattern.length);

    for (int i = 0; i < pattern.length - 1; ++i) {
      skip.set(pattern[i], pattern.length - i - 1);
    }

    return skip;
  }
示例#5
0
  /**
   * Pre-processes the pattern. The pattern may not exceed 32 characters in length. If it does,
   * <b>only it's first 32 bytes</b> are processed which might lead to unexpected results. Returns a
   * {@link CharIntMap}.
   *
   * @param pattern the <code>char</code> array containing the pattern, may not be <code>null</code>
   * @param w the wildcard character
   * @return a {@link CharIntMap}.
   */
  public Object processChars(char[] pattern, char w) {
    int j = 0;
    int end = pattern.length < 32 ? pattern.length : 32;

    for (int i = 0; i < end; ++i) {
      if (pattern[i] == w) {
        j |= (1 << end - i - 1);
      }
    }

    CharIntMap b = createCharIntMap(pattern, j);

    j = 1;
    for (int i = end - 1; i >= 0; --i, j <<= 1) {
      b.set(pattern[i], b.get(pattern[i]) | j);
    }

    return b;
  }