--- act_hash_lh.c 2002/01/18 18:17:55 1.10
+++ act_hash_lh.c 2003/01/06 12:10:58 1.11
@@ -1,9 +1,10 @@
-/*
-** Act - Abstract Container Type Library
-** Copyright (c) 1999-2002 Ralf S. Engelschall <rse@engelschall.com>
+/*
+** OSSP act - Abstract Container Types
+** Copyright (c) 1999-2003 Ralf S. Engelschall <rse@engelschall.com>
+** Copyright (c) 1999-2003 The OSSP Project <http://www.ossp.org/>
**
-** This file is part of Act, a library for dealing with Abstract
-** Container Types which can be found at http://www.ossp.org/pkg/act/.
+** This file is part of OSSP act, an abstract container type library
+** which can be found at http://www.ossp.org/pkg/lib/act/.
**
** Permission to use, copy, modify, and distribute this software for
** any purpose with or without fee is hereby granted, provided that
@@ -33,7 +34,7 @@
** collision chains as the backend data structure. Some ideas were
** taken over from MIKAEL PETTERSON's Linear Hashing enhancements
** (1993).
-**
+**
** Linear Hashing can be summarized as following:
**
** o drawback of classical hashing is that the hash table is of
@@ -79,7 +80,7 @@
**
** As you can see, it consists of four classes of memory chunks:
** 1. a top-level structure which acts as the primary handle
-** 2. the virtual hash table consisting of a single (growing)
+** 2. the virtual hash table consisting of a single (growing)
** directory and one or more (fixed size) directory segments
** 3. the collision chains consisting of element structures
** 4. the actual elements consisting of key+value structures
@@ -109,7 +110,7 @@
typedef struct segment_st segment_t;
struct segment_st {
element_t *s_element[SEGMENTSIZE]; /* array of pointers to elements */
-};
+};
/* the top-level hash table structure */
typedef struct act_hash_lh_st act_hash_lh_t;
@@ -174,7 +175,7 @@
if (act_grid_alloc(h->h_grid_seg, (void **)&(h->h_dir[0])) != ACT_OK) {
errno_safe(act_grid_destroy(h->h_grid_seg));
errno_safe(act_grid_destroy(h->h_grid_el));
- errno_safe(act_mem_free_ctx(ctx, h->h_dir));
+ errno_safe(act_mem_free_ctx(ctx, h->h_dir));
errno_safe(act_mem_free_ctx(ctx, h));
return NULL;
}
@@ -193,9 +194,9 @@
}
/* expand the hash table */
-static void
+static void
act_hash_lh_expand(
- act_ctx_t *ctx,
+ act_ctx_t *ctx,
act_hash_lh_t *h)
{
unsigned int pmax0;
@@ -204,7 +205,7 @@
element_t **pelold;
element_t *el, *headofold, *headofnew, *next;
unsigned int n;
-
+
/* calculate next new address */
pmax0 = h->h_pmax;
newaddr = pmax0 + h->h_p;
@@ -218,7 +219,7 @@
return;
act_mem_set((char *)h->h_dir+n, 0, n);
}
-
+
/* have to create a new table segment? */
if (SEGINDEX(newaddr) == 0) {
if (act_grid_alloc(h->h_grid_seg, (void **)&seg) != ACT_OK)
@@ -236,7 +237,7 @@
h->h_p = 0;
}
h->h_slack += MAXLOADFCTR;
-
+
/* relocate and split between P-element new element */
headofold = NULL;
headofnew = NULL;
@@ -257,9 +258,9 @@
}
/* shrink hash table */
-static void
+static void
act_hash_lh_shrink(
- act_ctx_t *ctx,
+ act_ctx_t *ctx,
act_hash_lh_t *h)
{
segment_t *lastseg;
@@ -310,12 +311,12 @@
}
/* insert element into hash table */
-static int
+static int
act_hash_lh_insert(
- act_ctx_t *ctx,
- act_hash_lh_t *h,
- void *keyptr, int keylen,
- void *datptr, int datlen,
+ act_ctx_t *ctx,
+ act_hash_lh_t *h,
+ void *keyptr, int keylen,
+ void *datptr, int datlen,
int override)
{
unsigned int hash, addr;
@@ -339,7 +340,7 @@
/* check whether element is already in the hash table */
bFound = FALSE;
for (el = *pel; el != NULL; el = el->e_next) {
- if ( el->e_hash == hash
+ if ( el->e_hash == hash
&& el_keylen(el) == keylen
&& act_mem_cmp(el->e_keyptr, keyptr, el_keylen(el)) == 0) {
bFound = TRUE;
@@ -390,11 +391,11 @@
}
/* lookup an element in hash table */
-static int
+static int
act_hash_lh_lookup(
- act_ctx_t *ctx,
- act_hash_lh_t *h,
- void *keyptr, int keylen,
+ act_ctx_t *ctx,
+ act_hash_lh_t *h,
+ void *keyptr, int keylen,
void **datptr, int *datlen)
{
unsigned int hash, addr;
@@ -415,7 +416,7 @@
/* search for element in collision list */
for (el = *pel; el != NULL; el = el->e_next) {
- if ( el->e_hash == hash
+ if ( el->e_hash == hash
&& el_keylen(el) == keylen
&& act_mem_cmp(el->e_keyptr, keyptr, el_keylen(el)) == 0) {
/* provide results */
@@ -430,10 +431,10 @@
}
/* delete an element in hash table */
-static int
+static int
act_hash_lh_delete(
- act_ctx_t *ctx,
- act_hash_lh_t *h,
+ act_ctx_t *ctx,
+ act_hash_lh_t *h,
void *keyptr, int keylen)
{
unsigned int hash, addr;
@@ -456,7 +457,7 @@
/* search for element in collision chain */
rv = FALSE;
for (lel = NULL, el = *pel; el != NULL; lel = el, el = el->e_next) {
- if ( el->e_hash == hash
+ if ( el->e_hash == hash
&& el_keylen(el) == keylen
&& act_mem_cmp(el->e_keyptr, keyptr, el_keylen(el)) == 0) {
/* free key+data memory chunk */
@@ -464,7 +465,7 @@
act_mem_free_ctx(ctx, el->e_keyptr);
/* remove element from collision chain */
if (lel == NULL)
- *pel = el->e_next;
+ *pel = el->e_next;
else
lel->e_next = el->e_next;
/* deallocate element structure */
@@ -482,10 +483,10 @@
}
/* calculate total size of hash table */
-static int
+static int
act_hash_lh_size(
- act_ctx_t *ctx,
- act_hash_lh_t *h,
+ act_ctx_t *ctx,
+ act_hash_lh_t *h,
long *pbytes, long *pelements)
{
long bytes, elements;
@@ -534,10 +535,10 @@
}
/* calculate total size of hash table */
-static int
+static int
act_hash_lh_status(
- act_ctx_t *ctx,
- act_hash_lh_t *h,
+ act_ctx_t *ctx,
+ act_hash_lh_t *h,
char *pstatus,
int nstatus)
{
@@ -609,7 +610,7 @@
chainlen_avg = chainlen_all / chains;
/* provide results */
- act_snprintf(pstatus, nstatus,
+ act_snprintf(pstatus, nstatus,
"size=%d@%dB dir=1*%dB seg=%d*%dB chains=%d@%d/%d/%d usage=%0.1f",
elements, bytes, dirsize, segments, segsize,
chains, chainlen_min, chainlen_avg, chainlen_max, used);
@@ -618,9 +619,9 @@
}
/* destroy the whole hash table */
-static int
+static int
act_hash_lh_free(
- act_ctx_t *ctx,
+ act_ctx_t *ctx,
act_hash_lh_t *h)
{
element_t *el, **pel, *el_next;
|