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