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