d19294a5b9e101e3f16b12bf2191aa742a4c8151
[xfstests-dev.git] / include / pattern.h
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef _PATTERN_H_
19 #define _PATTERN_H_
20
21 /*
22  * pattern_check(buf, buflen, pat, patlen, patshift)
23  *
24  * Check a buffer of length buflen against repeated occurrances of
25  * a pattern whose length is patlen.  Patshift can be used to rotate
26  * the pattern by patshift bytes to the left.
27  *
28  * Patshift may be greater than patlen, the pattern will be rotated by
29  * (patshift % patshift) bytes.
30  *
31  * pattern_check returns -1 if the buffer does not contain repeated
32  * occurrances of the indicated pattern (shifted by patshift).
33  *
34  * The algorithm used to check the buffer relies on the fact that buf is 
35  * supposed to be repeated copies of pattern.  The basic algorithm is
36  * to validate the first patlen bytes of buf against the pat argument
37  * passed in - then validate the next patlen bytes against the 1st patlen
38  * bytes - the next (2*patlen) bytes against the 1st (2*pathen) bytes, and
39  * so on.  This algorithm only works when the assumption of a buffer full
40  * of repeated copies of a pattern holds, and gives MUCH better results
41  * then walking the buffer byte by byte.
42  *
43  * Performance wise, It appears to be about 5% slower than doing a straight
44  * memcmp of 2 buffers, but the big win is that it does not require a
45  * 2nd comparison buffer, only the pattern.
46  */
47 int pattern_check( char * , int , char * , int , int );
48
49 /*
50  * pattern_fill(buf, buflen, pat, patlen, patshift)
51  *
52  * Fill a buffer of length buflen with repeated occurrances of
53  * a pattern whose length is patlen.  Patshift can be used to rotate
54  * the pattern by patshift bytes to the left.
55  *
56  * Patshift may be greater than patlen, the pattern will be rotated by
57  * (patshift % patlen) bytes.
58  *
59  * If buflen is not a multiple of patlen, a partial pattern will be written
60  * in the last part of the buffer.  This implies that a buffer which is
61  * shorter than the pattern length will receive only a partial pattern ...
62  *
63  * pattern_fill always returns 0 - no validation of arguments is done.
64  *
65  * The algorithm used to fill the buffer relies on the fact that buf is 
66  * supposed to be repeated copies of pattern.  The basic algorithm is
67  * to fill the first patlen bytes of buf with the pat argument
68  * passed in - then copy the next patlen bytes with the 1st patlen
69  * bytes - the next (2*patlen) bytes with the 1st (2*pathen) bytes, and
70  * so on.  This algorithm only works when the assumption of a buffer full
71  * of repeated copies of a pattern holds, and gives MUCH better results
72  * then filling the buffer 1 byte at a time.
73  */
74 int pattern_fill( char * , int , char * , int , int );
75
76 #endif