/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 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 "lut_impl.h"
#include "tree.h"
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;
while (tmp) {
if (cmp_func)
else
if (diff == 0) {
/* already in tree, replace node */
return (root);
} else if (diff > 0) {
} else {
}
}
/* either empty tree or not in tree, so create new node */
return (root);
}
void *
{
int diff;
while (root) {
if (cmp_func)
else
if (diff == 0)
else if (diff > 0)
else
}
return (NULL);
}
void *
{
int diff;
while (root) {
if (cmp_func)
else
if (diff == 0)
else if (diff > 0)
else
}
return (NULL);
}
/*
* lut_walk -- walk the table in lexical order
*/
void
{
return;
/* do callback on leftmost node */
for (;;) {
/* do callback on leftmost node */
prev_child = tmp;
/*
* do callback on parent only if we're coming up
* from the left
*/
} else
return;
}
}
/*
* lut_free -- free the lut
*/
void
{
return;
/* do callback on leftmost node */
if (callback)
for (;;) {
/* do callback on leftmost node */
if (callback)
prev_child = tmp;
/*
* do callback on parent only if we're coming up
* from the left
*/
} else {
/*
* free the root node and then we're done
*/
return;
}
}
}