xref: /freebsd/lib/libopenbsd/ohash_interval.3 (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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
38These functions are commonly used to simplify open hashing usage, and use
39similar conventions.
40They operate indifferently on NUL-terminated strings
41.Po
42by setting
43.Fa *pend
44=
45.Dv NULL
46.Pc
47or memory ranges
48.Po
49delimited by
50.Fa start
51and
52.Fa *pend
53.Pc .
54For NUL-terminated strings, as a side effect, those functions
55set
56.Fa *pend
57to the terminating NUL byte.
58.Pp
59.Fn ohash_interval
60is a simple hashing function that yields good results on common data sets.
61.Pp
62.Fn ohash_create_entry
63can be used to create a new record with a given key.
64In that case,
65the alloc field of
66.Fa info
67should point to a
68.Xr malloc 3 Ns -like
69function to allocate the storage:
70.Bd -literal -offset indent
71p = (*info->alloc)(sz, info->data);
72.Ed
73.Pp
74.Fn ohash_qlookupi
75is a wrapper function that simply calls
76.Fn ohash_interval
77and
78.Fn ohash_lookup_interval .
79.Pp
80.Fn ohash_qlookup
81is a variation on
82.Fn ohash_qlookupi
83designed for NUL-terminated strings.
84.Sh SEE ALSO
85.Xr ohash_init 3
86.Sh STANDARDS
87Those functions are completely non-standard and should be avoided in
88portable programs.
89.Sh HISTORY
90Those functions were designed and written for
91.Ox
92.Xr make 1
93by Marc Espie in 1999.
94