24cb589cd0a8082c42b5bd86686abfa6f8943035
[dragonfly.git] / usr.bin / m4 / lib / ohash_interval.3
1 .\"     $OpenBSD: ohash_interval.3,v 1.11 2007/05/31 19:19:30 jmc Exp $
2 .\" Copyright (c) 2001 Marc Espie <espie@openbsd.org>
3 .\"
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
7 .\"
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 .\"
16 .\" $FreeBSD: src/usr.bin/m4/lib/ohash_interval.3,v 1.3 2012/11/17 01:54:24 svnexp Exp $
17 .\"
18 .Dd $Mdocdate: May 31 2007 $
19 .Dt OPEN_HASH_HELPER 3
20 .Os
21 .Sh NAME
22 .Nm ohash_interval ,
23 .Nm ohash_create_entry ,
24 .Nm ohash_qlookup ,
25 .Nm ohash_qlookupi
26 .Nd helper functions for open hashing
27 .Sh SYNOPSIS
28 .Fd #include <stdint.h>
29 .Fd #include <stddef.h>
30 .Fd #include <ohash.h>
31 .Ft uint32_t
32 .Fn ohash_interval "const char *start" "const char **pend"
33 .Ft "void *"
34 .Fn ohash_create_entry "struct ohash_info *info" "const char *start" "const char **pend"
35 .Ft "unsigned int"
36 .Fn ohash_qlookupi "struct ohash *h" "const char *start" "const char **pend"
37 .Ft "unsigned int"
38 .Fn ohash_qlookup "struct ohash *h" "const char *start"
39 .Sh DESCRIPTION
40 These functions are commonly used to simplify open hashing usage, and use
41 similar conventions.
42 They operate indifferently on NUL-terminated strings
43 .Po
44 by setting
45 .Fa *pend
46 =
47 .Dv NULL
48 .Pc
49 or memory ranges
50 .Po
51 delimited by
52 .Fa start
53 and
54 .Fa *pend
55 .Pc .
56 For NUL-terminated strings, as a side effect, those functions
57 set
58 .Fa *pend
59 to the terminating NUL byte.
60 .Pp
61 .Fn ohash_interval
62 is a simple hashing function that yields good results on common data sets.
63 .Pp
64 .Fn ohash_create_entry
65 can be used to create a new record with a given key.
66 In that case,
67 the alloc field of
68 .Fa info
69 should point to a
70 .Xr malloc 3 Ns -like
71 function to allocate the storage.
72 .Pp
73 .Fn ohash_qlookupi
74 is a wrapper function that simply calls
75 .Fn ohash_interval
76 and
77 .Fn ohash_lookup_interval .
78 .Pp
79 .Fn ohash_qlookup
80 is a variation on
81 .Fn ohash_qlookupi
82 designed for NUL-terminated strings.
83 .Sh SEE ALSO
84 .Xr ohash_init 3
85 .Sh STANDARDS
86 Those functions are completely non-standard and should be avoided in
87 portable programs.
88 .Sh HISTORY
89 Those functions were designed and written for
90 .Ox
91 .Xr make 1
92 by Marc Espie in 1999.