File: hash_method.c

package info (click to toggle)
htdig 1%3A3.2.0b6-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,292 kB
  • sloc: ansic: 49,632; cpp: 46,468; sh: 17,400; xml: 4,180; perl: 2,543; makefile: 888; php: 79; asm: 14
file content (124 lines) | stat: -rw-r--r-- 2,316 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1999
 *	Sleepycat Software.  All rights reserved.
 */

#include "db_config.h"

#ifndef lint
static const char sccsid[] = "@(#)hash_method.c	11.3 (Sleepycat) 9/29/99";
#endif /* not lint */

#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif

#include "db_int.h"
#include "db_page.h"
#include "hash.h"

static int CDB___ham_set_h_ffactor __P((DB *, u_int32_t));
static int CDB___ham_set_h_hash __P((DB *, u_int32_t(*)(const void *, u_int32_t)));
static int CDB___ham_set_h_nelem __P((DB *, u_int32_t));

/*
 * CDB___ham_db_create --
 *	Hash specific initialization of the DB structure.
 *
 * PUBLIC: int CDB___ham_db_create __P((DB *));
 */
int
CDB___ham_db_create(dbp)
	DB *dbp;
{
	HASH *hashp;
	int ret;

	if ((ret = CDB___os_malloc(sizeof(HASH), NULL, &dbp->h_internal)) != 0)
		return (ret);

	hashp = dbp->h_internal;

	hashp->h_nelem = 0;			/* Defaults. */
	hashp->h_ffactor = 0;
	hashp->h_hash = NULL;

	dbp->set_h_ffactor = CDB___ham_set_h_ffactor;
	dbp->set_h_hash = CDB___ham_set_h_hash;
	dbp->set_h_nelem = CDB___ham_set_h_nelem;

	return (0);
}

/*
 * PUBLIC: int CDB___ham_db_close __P((DB *));
 */
int
CDB___ham_db_close(dbp)
	DB *dbp;
{
	if (dbp->h_internal == NULL)
		return (0);
	CDB___os_free(dbp->h_internal, sizeof(HASH));
	dbp->h_internal = NULL;
	return (0);
}

/*
 * CDB___ham_set_h_ffactor --
 *	Set the fill factor.
 */
static int
CDB___ham_set_h_ffactor(dbp, h_ffactor)
	DB *dbp;
	u_int32_t h_ffactor;
{
	HASH *hashp;

	DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_ffactor");
	DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);

	hashp = dbp->h_internal;
	hashp->h_ffactor = h_ffactor;
	return (0);
}

/*
 * CDB___ham_set_h_hash --
 *	Set the hash function.
 */
static int
CDB___ham_set_h_hash(dbp, func)
	DB *dbp;
	u_int32_t (*func) __P((const void *, u_int32_t));
{
	HASH *hashp;

	DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_hash");
	DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);

	hashp = dbp->h_internal;
	hashp->h_hash = func;
	return (0);
}

/*
 * CDB___ham_set_h_nelem --
 *	Set the table size.
 */
static int
CDB___ham_set_h_nelem(dbp, h_nelem)
	DB *dbp;
	u_int32_t h_nelem;
{
	HASH *hashp;

	DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_nelem");
	DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);

	hashp = dbp->h_internal;
	hashp->h_nelem = h_nelem;
	return (0);
}