Allow for creation of both LIST and TAILQ based hashes by adding a `hash
type' argument to hashinit().
This commit is contained in:
parent
ae840bf480
commit
5fcf59fd7c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_subr.c,v 1.71 2000/07/26 12:24:52 augustss Exp $ */
|
||||
/* $NetBSD: kern_subr.c,v 1.72 2000/11/08 14:25:24 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
|
||||
|
@ -222,37 +222,65 @@ again:
|
|||
* suitable for masking a value to use as an index into the returned array.
|
||||
*/
|
||||
void *
|
||||
hashinit(elements, type, flags, hashmask)
|
||||
int elements, type, flags;
|
||||
hashinit(elements, htype, mtype, mflags, hashmask)
|
||||
int elements;
|
||||
enum hashtype htype;
|
||||
int mtype, mflags;
|
||||
u_long *hashmask;
|
||||
{
|
||||
long hashsize;
|
||||
LIST_HEAD(generic, generic) *hashtbl;
|
||||
int i;
|
||||
LIST_HEAD(, generic) *hashtbl_list;
|
||||
TAILQ_HEAD(, generic) *hashtbl_tailq;
|
||||
int i, esize;
|
||||
void *p;
|
||||
|
||||
if (elements <= 0)
|
||||
panic("hashinit: bad cnt");
|
||||
for (hashsize = 1; hashsize < elements; hashsize <<= 1)
|
||||
continue;
|
||||
hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, flags);
|
||||
if (hashtbl == NULL)
|
||||
|
||||
switch (htype) {
|
||||
case HASH_LIST:
|
||||
esize = sizeof(*hashtbl_list);
|
||||
break;
|
||||
case HASH_TAILQ:
|
||||
esize = sizeof(*hashtbl_tailq);
|
||||
break;
|
||||
#ifdef DIAGNOSTIC
|
||||
default:
|
||||
panic("hashinit: invalid table type");
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((p = malloc((u_long)hashsize * esize, mtype, mflags)) == NULL)
|
||||
return (NULL);
|
||||
for (i = 0; i < hashsize; i++)
|
||||
LIST_INIT(&hashtbl[i]);
|
||||
|
||||
switch (htype) {
|
||||
case HASH_LIST:
|
||||
hashtbl_list = p;
|
||||
for (i = 0; i < hashsize; i++)
|
||||
LIST_INIT(&hashtbl_list[i]);
|
||||
break;
|
||||
case HASH_TAILQ:
|
||||
hashtbl_tailq = p;
|
||||
for (i = 0; i < hashsize; i++)
|
||||
TAILQ_INIT(&hashtbl_tailq[i]);
|
||||
break;
|
||||
}
|
||||
*hashmask = hashsize - 1;
|
||||
return (hashtbl);
|
||||
return (p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free memory from hash table previosly allocated via hashinit().
|
||||
*/
|
||||
void
|
||||
hashdone(hashtbl, type)
|
||||
hashdone(hashtbl, mtype)
|
||||
void *hashtbl;
|
||||
int type;
|
||||
int mtype;
|
||||
{
|
||||
|
||||
free(hashtbl, type);
|
||||
free(hashtbl, mtype);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: systm.h,v 1.118 2000/11/02 21:24:16 tsutsui Exp $ */
|
||||
/* $NetBSD: systm.h,v 1.119 2000/11/08 14:25:23 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1988, 1991, 1993
|
||||
|
@ -170,9 +170,14 @@ int eopnotsupp __P((void));
|
|||
int lkmenodev __P((void));
|
||||
#endif
|
||||
|
||||
enum hashtype {
|
||||
HASH_LIST,
|
||||
HASH_TAILQ
|
||||
};
|
||||
|
||||
void *hashinit __P((int, enum hashtype, int, int, u_long *));
|
||||
void hashdone __P((void *, int));
|
||||
int seltrue __P((dev_t dev, int events, struct proc *p));
|
||||
void *hashinit __P((int count, int type, int flags, u_long *hashmask));
|
||||
void hashdone __P((void *hashtbl, int type));
|
||||
int sys_nosys __P((struct proc *, void *, register_t *));
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue