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