Blame man3/hash.3

Packit 7cfc04
.\" Copyright (c) 1990, 1993
Packit 7cfc04
.\"	The Regents of the University of California.  All rights reserved.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
Packit 7cfc04
.\" Redistribution and use in source and binary forms, with or without
Packit 7cfc04
.\" modification, are permitted provided that the following conditions
Packit 7cfc04
.\" are met:
Packit 7cfc04
.\" 1. Redistributions of source code must retain the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer.
Packit 7cfc04
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer in the
Packit 7cfc04
.\"    documentation and/or other materials provided with the distribution.
Packit 7cfc04
.\" 3. All advertising materials mentioning features or use of this software
Packit 7cfc04
.\"    must display the following acknowledgement:
Packit 7cfc04
.\"	This product includes software developed by the University of
Packit 7cfc04
.\"	California, Berkeley and its contributors.
Packit 7cfc04
.\" 4. Neither the name of the University nor the names of its contributors
Packit 7cfc04
.\"    may be used to endorse or promote products derived from this software
Packit 7cfc04
.\"    without specific prior written permission.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 7cfc04
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 7cfc04
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 7cfc04
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 7cfc04
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 7cfc04
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 7cfc04
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 7cfc04
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 7cfc04
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 7cfc04
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 7cfc04
.\" SUCH DAMAGE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"	@(#)hash.3	8.6 (Berkeley) 8/18/94
Packit 7cfc04
.\"
Packit 7cfc04
.TH HASH 3 2017-09-15 "" "Linux Programmer's Manual"
Packit 7cfc04
.UC 7
Packit 7cfc04
.SH NAME
Packit 7cfc04
hash \- hash database access method
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.ft B
Packit 7cfc04
#include <sys/types.h>
Packit 7cfc04
#include <db.h>
Packit 7cfc04
.ft R
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.IR "Note well" :
Packit 7cfc04
This page documents interfaces provided in glibc up until version 2.1.
Packit 7cfc04
Since version 2.2, glibc no longer provides these interfaces.
Packit 7cfc04
Probably, you are looking for the APIs provided by the
Packit 7cfc04
.I libdb
Packit 7cfc04
library instead.
Packit 7cfc04
.PP
Packit 7cfc04
The routine
Packit 7cfc04
.BR dbopen (3)
Packit 7cfc04
is the library interface to database files.
Packit 7cfc04
One of the supported file formats is hash files.
Packit 7cfc04
The general description of the database access methods is in
Packit 7cfc04
.BR dbopen (3),
Packit 7cfc04
this manual page describes only the hash-specific information.
Packit 7cfc04
.PP
Packit 7cfc04
The hash data structure is an extensible, dynamic hashing scheme.
Packit 7cfc04
.PP
Packit 7cfc04
The access-method-specific data structure provided to
Packit 7cfc04
.BR dbopen (3)
Packit 7cfc04
is defined in the
Packit 7cfc04
.I <db.h>
Packit 7cfc04
include file as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
typedef struct {
Packit 7cfc04
    unsigned int       bsize;
Packit 7cfc04
    unsigned int       ffactor;
Packit 7cfc04
    unsigned int       nelem;
Packit 7cfc04
    unsigned int       cachesize;
Packit 7cfc04
    uint32_t         (*hash)(const void *, size_t);
Packit 7cfc04
    int         lorder;
Packit 7cfc04
} HASHINFO;
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The elements of this structure are as follows:
Packit 7cfc04
.TP 10
Packit 7cfc04
.I bsize
Packit 7cfc04
defines the hash table bucket size, and is, by default, 256 bytes.
Packit 7cfc04
It may be preferable to increase the page size for disk-resident tables
Packit 7cfc04
and tables with large data items.
Packit 7cfc04
.TP
Packit 7cfc04
.I ffactor
Packit 7cfc04
indicates a desired density within the hash table.
Packit 7cfc04
It is an approximation of the number of keys allowed to accumulate in any
Packit 7cfc04
one bucket, determining when the hash table grows or shrinks.
Packit 7cfc04
The default value is 8.
Packit 7cfc04
.TP
Packit 7cfc04
.I nelem
Packit 7cfc04
is an estimate of the final size of the hash table.
Packit 7cfc04
If not set or set too low, hash tables will expand gracefully as keys
Packit 7cfc04
are entered, although a slight performance degradation may be noticed.
Packit 7cfc04
The default value is 1.
Packit 7cfc04
.TP
Packit 7cfc04
.I cachesize
Packit 7cfc04
is the suggested maximum size, in bytes, of the memory cache.
Packit 7cfc04
This value is
Packit 7cfc04
.IR "only advisory" ,
Packit 7cfc04
and the access method will allocate more memory rather than fail.
Packit 7cfc04
.TP
Packit 7cfc04
.I hash
Packit 7cfc04
is a user-defined hash function.
Packit 7cfc04
Since no hash function performs equally well on all possible data, the
Packit 7cfc04
user may find that the built-in hash function does poorly on a particular
Packit 7cfc04
data set.
Packit 7cfc04
A user-specified hash functions must take two arguments (a pointer to a byte
Packit 7cfc04
string and a length) and return a 32-bit quantity to be used as the hash
Packit 7cfc04
value.
Packit 7cfc04
.TP
Packit 7cfc04
.I lorder
Packit 7cfc04
is the byte order for integers in the stored database metadata.
Packit 7cfc04
The number should represent the order as an integer; for example,
Packit 7cfc04
big endian order would be the number 4,321.
Packit 7cfc04
If
Packit 7cfc04
.I lorder
Packit 7cfc04
is 0 (no order is specified), the current host order is used.
Packit 7cfc04
If the file already exists, the specified value is ignored and the
Packit 7cfc04
value specified when the tree was created is used.
Packit 7cfc04
.PP
Packit 7cfc04
If the file already exists (and the
Packit 7cfc04
.B O_TRUNC
Packit 7cfc04
flag is not specified), the
Packit 7cfc04
values specified for
Packit 7cfc04
.IR bsize ,
Packit 7cfc04
.IR ffactor ,
Packit 7cfc04
.IR lorder ,
Packit 7cfc04
and
Packit 7cfc04
.I nelem
Packit 7cfc04
are
Packit 7cfc04
ignored and the values specified when the tree was created are used.
Packit 7cfc04
.PP
Packit 7cfc04
If a hash function is specified,
Packit 7cfc04
.I hash_open
Packit 7cfc04
attempts to determine if the hash function specified is the same as
Packit 7cfc04
the one with which the database was created, and fails if it is not.
Packit 7cfc04
.PP
Packit 7cfc04
Backward-compatible interfaces to the routines described in
Packit 7cfc04
.BR dbm (3),
Packit 7cfc04
and
Packit 7cfc04
.BR ndbm (3)
Packit 7cfc04
are provided, however these interfaces are not compatible with
Packit 7cfc04
previous file formats.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
The
Packit 7cfc04
.I hash
Packit 7cfc04
access method routines may fail and set
Packit 7cfc04
.I errno
Packit 7cfc04
for any of the errors specified for the library routine
Packit 7cfc04
.BR dbopen (3).
Packit 7cfc04
.SH BUGS
Packit 7cfc04
Only big and little endian byte order are supported.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR btree (3),
Packit 7cfc04
.BR dbopen (3),
Packit 7cfc04
.BR mpool (3),
Packit 7cfc04
.BR recno (3)
Packit 7cfc04
.PP
Packit 7cfc04
.IR "Dynamic Hash Tables" ,
Packit 7cfc04
Per-Ake Larson, Communications of the ACM, April 1988.
Packit 7cfc04
.PP
Packit 7cfc04
.IR "A New Hash Package for UNIX" ,
Packit 7cfc04
Margo Seltzer, USENIX Proceedings, Winter 1991.
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.