hash(3)
โจ hash(3) โ hash database access method โจ
okay bestie, welcome to hash(3) from the Library Functions Manual, aka the vibe check on the hash database access method ๐ this one lives in the Standard C library (libc, -lc), so let's get into it ๐ซถ
๐ LIBRARY
Standard C library โ <pink>libc</pink>, <pink>-lc</pink> ๐
๐ฆ SYNOPSIS
#include <sys/types.h>
#include <db.h>
๐ DESCRIPTION
Note well: this page is documenting interfaces that were a thing up until glibc 2.1. Since glibc 2.2, glibc literally does not provide these interfaces anymore ๐ญ so if you're here, you're prob looking for the APIs from the libdb library instead. no cap.
The routine dbopen(3) is the library interface to database files. One of the supported file formats is hash files. The general description of the database access methods lives over in dbopen(3) โ this manual page only describes the hash-specific information, periodt โจ
The hash data structure is an extensible, dynamic hashing scheme. iconic behavior honestly ๐
The access-method-specific data structure provided to dbopen(3) is defined in the <db.h> include file like this:
typedef struct {
unsigned int bsize;
unsigned int ffactor;
unsigned int nelem;
unsigned int cachesize;
uint32_t (*hash)(const void *, size_t);
int lorder;
} HASHINFO;
The elements of this structure are as follows, bestie โ one by one, no skimming ๐:
bsizeโ defines the hash table bucket size, and it's, by default,256bytes. it may be preferable to increase the page size for disk-resident tables and tables with large data items ๐ซffactorโ indicates a desired density within the hash table. It's an approximation of the number of keys allowed to accumulate in any one bucket, determining when the hash table grows or shrinks. The default value is8๐nelemโ is an estimate of the final size of the hash table. If it's not set, or set too low, hash tables will expand gracefully as keys are entered, although a slight performance degradation may be noticed ๐ The default value is1.cachesizeโ is the suggested maximum size, in bytes, of the memory cache. This value is only advisory, and the access method will allocate more memory rather than fail ๐hashโ is a user-defined hash function. Since no hash function performs equally well on all possible data, you may find that the built-in hash function does poorly on a particular data set ๐ญ A user-specified hash function must take two arguments (a pointer to a byte string and a length) and return a 32-bit quantity to be used as the hash value โจlorderโ is the byte order for integers in the stored database metadata. The number should represent the order as an integer; for example, big endian order would be the number4,321. Iflorderis0(no order is specified), the current host order is used. If the file already exists, the specified value is ignored and the value specified when the tree was created is used ๐ซถ
If the file already exists (and the O_TRUNC flag is not specified), the values specified for bsize, ffactor, lorder, and nelem are ignored and the values specified when the tree was created are used. yeah. your cute little settings just get ghosted ๐
If a hash function is specified, hash_open attempts to determine if the hash function specified is the same as the one with which the database was created, and fails if it is not ๐ฅ
Backward-compatible interfaces to the routines described in dbm(3) and ndbm(3) are provided โ however these interfaces are not compatible with previous file formats. lowkey important, don't skip that part ๐
๐ญ ERRORS
The hash access method routines may fail and set errno for any of the errors specified for the library routine dbopen(3).
๐ BUGS
Only big and little endian byte order are supported. that's it, that's the whole vibe check ๐ธ
๐ SEE ALSO
btree(3)dbopen(3)mpool(3)recno(3)- Dynamic Hash Tables, Per-Ake Larson, Communications of the ACM, April 1988.
- A New Hash Package for UNIX, Margo Seltzer, USENIX Proceedings, Winter 1991.
and that's the whole page, bestie ๐ this one comes to you from the 4.4 Berkeley Distribution, dated 2025-09-21, and yeah it's still called hash(3) ๐ mwah, go read dbopen(3) next, iykyk โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1990-1993, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms