xref: /onnv-gate/usr/src/lib/libast/common/hash/hashview.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin  * Glenn Fowler
254887Schin  * AT&T Bell Laboratories
264887Schin  *
274887Schin  * hash table library
284887Schin  */
294887Schin 
304887Schin #include "hashlib.h"
314887Schin 
324887Schin /*
334887Schin  * push/pop/query hash table scope
344887Schin  *
354887Schin  *	bot==0		pop top scope
364887Schin  *	bot==top	query
374887Schin  *	bot!=0		push top on bot
384887Schin  *
394887Schin  * scope table pointer returned
404887Schin  */
414887Schin 
424887Schin Hash_table_t*
hashview(Hash_table_t * top,Hash_table_t * bot)434887Schin hashview(Hash_table_t* top, Hash_table_t* bot)
444887Schin {
454887Schin 	register Hash_bucket_t*		b;
464887Schin 	register Hash_bucket_t*		p;
474887Schin 	register Hash_bucket_t**	sp;
484887Schin 	register Hash_bucket_t**	sx;
494887Schin 
504887Schin 	if (!top || top->frozen)
514887Schin 		bot = 0;
524887Schin 	else if (top == bot)
534887Schin 		bot = top->scope;
544887Schin 	else if (bot)
554887Schin 	{
564887Schin 		if (top->scope)
574887Schin 			bot = 0;
584887Schin 		else
594887Schin 		{
604887Schin 			sx = &top->table[top->size];
614887Schin 			sp = &top->table[0];
624887Schin 			while (sp < sx)
634887Schin 				for (b = *sp++; b; b = b->next)
644887Schin 					if (p = (Hash_bucket_t*)hashlook(bot, b->name, HASH_LOOKUP, NiL))
654887Schin 					{
664887Schin 						b->name = (p->hash & HASH_HIDES) ? p->name : (char*)b;
674887Schin 						b->hash |= HASH_HIDES;
684887Schin 					}
694887Schin 			top->scope = bot;
704887Schin 			bot->frozen++;
714887Schin 		}
724887Schin 	}
734887Schin 	else if (bot = top->scope)
744887Schin 	{
754887Schin 		sx = &top->table[top->size];
764887Schin 		sp = &top->table[0];
774887Schin 		while (sp < sx)
784887Schin 			for (b = *sp++; b; b = b->next)
794887Schin 				if (b->hash & HASH_HIDES)
804887Schin 				{
814887Schin 					b->hash &= ~HASH_HIDES;
824887Schin 					b->name = ((Hash_bucket_t*)b->name)->name;
834887Schin 				}
844887Schin 		top->scope = 0;
854887Schin 		bot->frozen--;
864887Schin 	}
874887Schin 	return(bot);
884887Schin }
89