summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/bm.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/bm.3')
-rw-r--r--src/lib/libc/string/bm.3113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3
new file mode 100644
index 0000000000..c942930163
--- /dev/null
+++ b/src/lib/libc/string/bm.3
@@ -0,0 +1,113 @@
1.\" Copyright (c) 1994
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Andrew Hume of AT&T Bell Laboratories.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by the University of
18.\" California, Berkeley and its contributors.
19.\" 4. Neither the name of the University nor the names of its contributors
20.\" may be used to endorse or promote products derived from this software
21.\" without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\" $OpenBSD: bm.3,v 1.2 1996/08/19 08:33:58 tholo Exp $
36.\"
37.TH BM 3
38.SH NAME
39bm_comp, bm_exec, bm_free \- Boyer-Moore string search
40.SH SYNOPSIS
41.ft B
42#include <sys/types.h>
43.br
44#include <bm.h>
45.sp
46bm_pat *
47.br
48bm_comp(u_char *pattern, size_t patlen, u_char freq[256]);
49.sp
50u_char *
51.br
52bm_exec(bm_pat *pdesc, u_char *text, size_t len);
53.sp
54void
55.br
56bm_free(bm_pat *pdesc);
57.SH DESCRIPTION
58These routines implement an efficient mechanism to find an
59occurrence of a byte string within another byte string.
60.PP
61.I Bm_comp
62evaluates the
63.I patlen
64bytes starting at
65.IR pattern ,
66and returns a pointer to a structure describing them.
67The bytes referenced by
68.I pattern
69may be of any value.
70.PP
71The search takes advantage of the frequency distribution of the
72bytes in the text to be searched.
73If specified,
74.I freq
75should be an array of 256 values,
76with higher values indicating that the corresponding character occurs
77more frequently.
78(A less than optimal frequency distribution can only result in less
79than optimal performance, not incorrect results.)
80If
81.I freq
82is NULL,
83a system default table is used.
84.PP
85.I Bm_exec
86returns a pointer to the leftmost occurrence of the string given to
87.I bm_comp
88within
89.IR text ,
90or NULL if none occurs.
91The number of bytes in
92.I text
93must be specified by
94.IR len .
95.PP
96Space allocated for the returned description is discarded
97by calling
98.I bm_free
99with the returned description as an argument.
100.PP
101The asymptotic speed of
102.I bm_exec
103is
104.RI O( len / patlen ).
105.PP
106.SH "SEE ALSO"
107.IR regexp (3),
108.IR strstr (3)
109.sp
110.IR "Fast String Searching" ,
111Hume and Sunday,
112Software Practice and Experience,
113Vol. 21, 11 (November 1991) pp. 1221-48.