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.3111
1 files changed, 111 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..772b0d372e
--- /dev/null
+++ b/src/lib/libc/string/bm.3
@@ -0,0 +1,111 @@
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. Neither the name of the University nor the names of its contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" $OpenBSD: bm.3,v 1.7 2003/06/02 20:18:38 millert Exp $
32.\"
33.Dd June 29, 1999
34.Dt BM 3
35.Os
36.Sh NAME
37.Nm bm_comp ,
38.Nm bm_exec ,
39.Nm bm_free
40.Nd Boyer-Moore string search
41.Sh SYNOPSIS
42.Fd #include <sys/types.h>
43.Fd #include <bm.h>
44.Ft bm_pat *
45.Fn bm_comp "u_char *pattern" "size_t patlen" "u_char freq[256]"
46.Ft u_char *
47.Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len"
48.Ft void
49.Fn bm_free "bm_pat *pdesc"
50.Sh DESCRIPTION
51These routines implement an efficient mechanism to find an
52occurrence of a byte string within another byte string.
53.Pp
54.Fn bm_comp
55evaluates
56.Fa patlen
57bytes starting at
58.Fa pattern
59and returns a pointer to a structure describing them.
60The bytes referenced by
61.Fa pattern
62may be of any value.
63.Pp
64The search takes advantage of the frequency distribution of the
65bytes in the text to be searched.
66If specified,
67.Ar freq
68should be an array of 256 values,
69with higher values indicating that the corresponding character occurs
70more frequently.
71(A less than optimal frequency distribution can only result in less
72than optimal performance, not incorrect results.)
73If
74.Ar freq
75is
76.Dv NULL ,
77a system default table is used.
78.Pp
79.Fn bm_exec
80returns a pointer to the leftmost occurrence of the string given to
81.Fn bm_comp
82within
83.Ar text ,
84or
85.Dv NULL
86if none occurs.
87The number of bytes in
88.Ar text
89must be specified by
90.Ar len .
91.Pp
92Space allocated for the returned description is discarded
93by calling
94.Fn bm_free
95with the returned description as an argument.
96.Pp
97The asymptotic speed of
98.Fn bm_exec
99is
100.Pf O Ns Pq len / patlen .
101.Sh SEE ALSO
102.Xr regexp 3 ,
103.Xr strstr 3
104.Rs
105.%R "Fast String Searching"
106.%A Andrew Hume
107.%A Daniel Sunday
108.%J "Software Practice and Experience"
109.%V Volume 21, 11 (November 1991)
110.%P 1221-48
111.Re