hashview.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Copyright (c) 1985-2007 AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* by AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* http://www.opensource.org/licenses/cpl1.0.txt *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#pragma prototyped
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Glenn Fowler
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Bell Laboratories
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * hash table library
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include "hashlib.h"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * push/pop/query hash table scope
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * bot==0 pop top scope
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * bot==top query
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * bot!=0 push top on bot
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * scope table pointer returned
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinHash_table_t*
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinhashview(Hash_table_t* top, Hash_table_t* bot)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Hash_bucket_t* b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Hash_bucket_t* p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Hash_bucket_t** sp;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register Hash_bucket_t** sx;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!top || top->frozen)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bot = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (top == bot)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bot = top->scope;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (bot)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (top->scope)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bot = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sx = &top->table[top->size];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sp = &top->table[0];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (sp < sx)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (b = *sp++; b; b = b->next)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (p = (Hash_bucket_t*)hashlook(bot, b->name, HASH_LOOKUP, NiL))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b->name = (p->hash & HASH_HIDES) ? p->name : (char*)b;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b->hash |= HASH_HIDES;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin top->scope = bot;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bot->frozen++;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (bot = top->scope)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sx = &top->table[top->size];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sp = &top->table[0];
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (sp < sx)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (b = *sp++; b; b = b->next)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (b->hash & HASH_HIDES)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b->hash &= ~HASH_HIDES;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin b->name = ((Hash_bucket_t*)b->name)->name;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin top->scope = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin bot->frozen--;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin }
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(bot);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin}