HASH(3) BSD Programmer's Manual HASH(3) NNAAMMEE hash - hash database access method SSYYNNOOPPSSIISS ##iinncclluuddee <<ssyyss//ttyyppeess..hh>> ##iinncclluuddee <<ddbb..hh>> DDEESSCCRRIIPPTTIIOONN The routine _d_b_o_p_e_n is the library interface to database files. One of the supported file formats is hash files. The general description of the database access methods is in _d_b_o_p_e_n(3), this manual page describes only the hash specific information. The hash data structure is an extensible, dynamic hashing scheme. The access method specific data structure provided to _d_b_o_p_e_n is defined in the <db.h> include file as follows: typedef struct { int bsize; int ffactor; int nelem; int cachesize; u_long (*hash)(const void *, size_t); int lorder; } HASHINFO; The elements of this structure are as follows: bsize _B_s_i_z_e defines the hash table bucket size, and is, by default, 256 bytes. It may be preferable to increase the page size for disk-resident tables and tables with large data items. cachesize A suggested maximum size, in bytes, of the memory cache. This value is oonnllyy advisory, and the access method will allocate more memory rather than fail. ffactor _F_f_a_c_t_o_r indicates a desired density within the hash table. It is 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 is 8. hash _H_a_s_h is a user defined hash function. Since no hash function performs equally well on all possible data, the user may find that the built-in hash 4.4 Berkeley Distribution July 19, 1993 1 HASH(3) BSD Programmer's Manual HASH(3) function does poorly on a particular data set. User specified hash functions must take two argu- ments (a pointer to a byte string and a length) and return an u_long to be used as the hash value. lorder 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 number 4,321. If _l_o_r_d_e_r is 0 (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. nelem _N_e_l_e_m is an estimate of the final size of the hash table. If 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 is 1. If the file already exists (and the O_TRUNC flag is not specified), the values specified for the parameters bsize, ffactor, lorder and nelem are ignored and the values spec- ified when the tree was created are used. If a hash function is specified, _h_a_s_h___o_p_e_n will attempt to determine if the hash function specified is the same as the one with which the database was created, and will fail if it is not. Backward compatible interfaces to the routines described in _d_b_m(3), and _n_d_b_m(3) are provided, however, these inter- faces are not compatible with previous file formats. SSEEEE AALLSSOO _b_t_r_e_e(3), _d_b_o_p_e_n(3), _m_p_o_o_l(3), _r_e_c_n_o(3) _D_y_n_a_m_i_c _H_a_s_h _T_a_b_l_e_s, Per-Ake Larson, Communications of the ACM, April 1988. _A _N_e_w _H_a_s_h _P_a_c_k_a_g_e _f_o_r _U_N_I_X, Margo Seltzer, USENIX Pro- ceedings, Winter 1991. BBUUGGSS Only big and little endian byte order is supported. 4.4 Berkeley Distribution July 19, 1993 2