1*4887Schin /*********************************************************************** 2*4887Schin * * 3*4887Schin * This software is part of the ast package * 4*4887Schin * Copyright (c) 1985-2007 AT&T Knowledge Ventures * 5*4887Schin * and is licensed under the * 6*4887Schin * Common Public License, Version 1.0 * 7*4887Schin * by AT&T Knowledge Ventures * 8*4887Schin * * 9*4887Schin * A copy of the License is available at * 10*4887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 11*4887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12*4887Schin * * 13*4887Schin * Information and Software Systems Research * 14*4887Schin * AT&T Research * 15*4887Schin * Florham Park NJ * 16*4887Schin * * 17*4887Schin * Glenn Fowler <gsf@research.att.com> * 18*4887Schin * David Korn <dgk@research.att.com> * 19*4887Schin * Phong Vo <kpv@research.att.com> * 20*4887Schin * * 21*4887Schin ***********************************************************************/ 22*4887Schin #pragma prototyped 23*4887Schin /* 24*4887Schin * Glenn Fowler 25*4887Schin * AT&T Bell Laboratories 26*4887Schin * 27*4887Schin * hash table library 28*4887Schin */ 29*4887Schin 30*4887Schin #include "hashlib.h" 31*4887Schin 32*4887Schin /* 33*4887Schin * push/pop/query hash table scope 34*4887Schin * 35*4887Schin * bot==0 pop top scope 36*4887Schin * bot==top query 37*4887Schin * bot!=0 push top on bot 38*4887Schin * 39*4887Schin * scope table pointer returned 40*4887Schin */ 41*4887Schin 42*4887Schin Hash_table_t* 43*4887Schin hashview(Hash_table_t* top, Hash_table_t* bot) 44*4887Schin { 45*4887Schin register Hash_bucket_t* b; 46*4887Schin register Hash_bucket_t* p; 47*4887Schin register Hash_bucket_t** sp; 48*4887Schin register Hash_bucket_t** sx; 49*4887Schin 50*4887Schin if (!top || top->frozen) 51*4887Schin bot = 0; 52*4887Schin else if (top == bot) 53*4887Schin bot = top->scope; 54*4887Schin else if (bot) 55*4887Schin { 56*4887Schin if (top->scope) 57*4887Schin bot = 0; 58*4887Schin else 59*4887Schin { 60*4887Schin sx = &top->table[top->size]; 61*4887Schin sp = &top->table[0]; 62*4887Schin while (sp < sx) 63*4887Schin for (b = *sp++; b; b = b->next) 64*4887Schin if (p = (Hash_bucket_t*)hashlook(bot, b->name, HASH_LOOKUP, NiL)) 65*4887Schin { 66*4887Schin b->name = (p->hash & HASH_HIDES) ? p->name : (char*)b; 67*4887Schin b->hash |= HASH_HIDES; 68*4887Schin } 69*4887Schin top->scope = bot; 70*4887Schin bot->frozen++; 71*4887Schin } 72*4887Schin } 73*4887Schin else if (bot = top->scope) 74*4887Schin { 75*4887Schin sx = &top->table[top->size]; 76*4887Schin sp = &top->table[0]; 77*4887Schin while (sp < sx) 78*4887Schin for (b = *sp++; b; b = b->next) 79*4887Schin if (b->hash & HASH_HIDES) 80*4887Schin { 81*4887Schin b->hash &= ~HASH_HIDES; 82*4887Schin b->name = ((Hash_bucket_t*)b->name)->name; 83*4887Schin } 84*4887Schin top->scope = 0; 85*4887Schin bot->frozen--; 86*4887Schin } 87*4887Schin return(bot); 88*4887Schin } 89