lut.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* lut.c -- simple lookup table module
*
* this file contains a very simple lookup table (lut) implementation.
* the tables only support insert & lookup, no delete, and can
* only be walked in one order. if the key already exists
* for something being inserted, the previous entry is simply
* replaced.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include "alloc.h"
#include "out.h"
#include "stats.h"
#include "lut.h"
#include "tree.h"
/* info created by lut_add(), private to this module */
struct lut {
void *lut_lhs; /* search key */
void *lut_rhs; /* the datum */
};
static struct stats *Lookuptotal;
void
lut_init(void)
{
}
void
lut_fini(void)
{
}
/*
* lut_add -- add an entry to the table
*
* use it like this:
* struct lut *root = NULL;
* root = lut_add(root, key, value, cmp_func);
*
* the cmp_func can be strcmp(). pass in NULL and instead of
* calling a cmp_func the routine will just look at the difference
* between key pointers (useful when all strings are kept in a
* string table so they are equal if their pointers are equal).
*
*/
struct lut *
{
int diff;
/* not in tree, create new node */
return (root);
}
if (cmp_func)
else
if (diff == 0) {
/* already in tree, replace node */
} else if (diff > 0)
else
return (root);
}
/*
* lut_lookup -- find an entry
*/
void *
{
int diff;
return (NULL);
if (cmp_func)
else
if (diff == 0) {
} else if (diff > 0)
else
}
/*
* lut_lookup_lhs -- find an entry, return the matched key (lut_lhs)
*/
void *
{
int diff;
return (NULL);
if (cmp_func)
else
if (diff == 0) {
} else if (diff > 0)
else
}
/*
* lut_walk -- walk the table in lexical order
*/
void
{
if (root) {
}
}
/*
* lut_free -- free the lut
*/
void
{
if (root) {
if (callback)
}
}