class SearchPattern {

    public int endsWith(byte[] data, int offset, int length) {
        validate(data, offset, length);

        int skip = (pattern.length <= length) ? (offset + length - pattern.length) : offset;
        while (skip < offset + length) {
            for (int i = (offset + length - 1) - skip; data[skip + i] == pattern[i]; --i) {
                if (i == 0)
                    return (offset + length - skip);
            }

            if (skip + pattern.length - 1 < data.length)
                skip += table[0xff & data[skip + pattern.length - 1]];
            else
                skip++;
        }

        return 0;
    }

    private  SearchPattern(byte[] pattern);

}