]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libopenbsd/ohash_interval.3
Merge commit '850ef5ae11d69ea3381bd310f564f025fc8caea3'
[FreeBSD/FreeBSD.git] / lib / libopenbsd / ohash_interval.3
1 .\"     $OpenBSD: ohash_interval.3,v 1.1 2014/05/12 19:09:00 espie 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 .Dd June 5, 2013
17 .Dt OHASH_INTERVAL 3
18 .Os
19 .Sh NAME
20 .Nm ohash_interval ,
21 .Nm ohash_create_entry ,
22 .Nm ohash_qlookup ,
23 .Nm ohash_qlookupi
24 .Nd helper functions for open hashing
25 .Sh SYNOPSIS
26 .In stdint.h
27 .In stddef.h
28 .In ohash.h
29 .Ft uint32_t
30 .Fn ohash_interval "const char *start" "const char **pend"
31 .Ft "void *"
32 .Fn ohash_create_entry "struct ohash_info *info" "const char *start" "const char **pend"
33 .Ft "unsigned int"
34 .Fn ohash_qlookupi "struct ohash *h" "const char *start" "const char **pend"
35 .Ft "unsigned int"
36 .Fn ohash_qlookup "struct ohash *h" "const char *start"
37 .Sh DESCRIPTION
38 These functions are commonly used to simplify open hashing usage, and use
39 similar conventions.
40 They operate indifferently on NUL-terminated strings
41 .Po
42 by setting
43 .Fa *pend
44 =
45 .Dv NULL
46 .Pc
47 or memory ranges
48 .Po
49 delimited by
50 .Fa start
51 and
52 .Fa *pend
53 .Pc .
54 For NUL-terminated strings, as a side effect, those functions
55 set
56 .Fa *pend
57 to the terminating NUL byte.
58 .Pp
59 .Fn ohash_interval
60 is a simple hashing function that yields good results on common data sets.
61 .Pp
62 .Fn ohash_create_entry
63 can be used to create a new record with a given key.
64 In that case,
65 the alloc field of
66 .Fa info
67 should point to a
68 .Xr malloc 3 Ns -like
69 function to allocate the storage:
70 .Bd -literal -offset indent
71 p = (*info->alloc)(sz, info->data);
72 .Ed
73 .Pp
74 .Fn ohash_qlookupi
75 is a wrapper function that simply calls
76 .Fn ohash_interval
77 and
78 .Fn ohash_lookup_interval .
79 .Pp
80 .Fn ohash_qlookup
81 is a variation on
82 .Fn ohash_qlookupi
83 designed for NUL-terminated strings.
84 .Sh SEE ALSO
85 .Xr ohash_init 3
86 .Sh STANDARDS
87 Those functions are completely non-standard and should be avoided in
88 portable programs.
89 .Sh HISTORY
90 Those functions were designed and written for
91 .Ox
92 .Xr make 1
93 by Marc Espie in 1999.