1*35189Smarc /* 2*35189Smarc 3*35189Smarc * Copyright (c) 1984, 1985, 1986 AT&T 4*35189Smarc * All Rights Reserved 5*35189Smarc 6*35189Smarc * THIS IS UNPUBLISHED PROPRIETARY SOURCE 7*35189Smarc * CODE OF AT&T. 8*35189Smarc * The copyright notice above does not 9*35189Smarc * evidence any actual or intended 10*35189Smarc * publication of such source code. 11*35189Smarc 12*35189Smarc */ 13*35189Smarc /* @(#)gettree.c 1.1 */ 14*35189Smarc 15*35189Smarc /* 16*35189Smarc * GETTREE.C 17*35189Smarc * 18*35189Smarc * Programmer: D. A. Lambeth 19*35189Smarc * 20*35189Smarc * Owner: D. A. Lambeth 21*35189Smarc * 22*35189Smarc * Date: April 17, 1980 23*35189Smarc * 24*35189Smarc * 25*35189Smarc * 26*35189Smarc * GETTREE (MSIZE) 27*35189Smarc * 28*35189Smarc * Create a shell associative memory with MSIZE buckets, 29*35189Smarc * and return a pointer to the root of the memory. 30*35189Smarc * MSIZE must be a power of 2. 31*35189Smarc * 32*35189Smarc * 33*35189Smarc * 34*35189Smarc * See Also: linknod(III), findnod(III), libname.h 35*35189Smarc */ 36*35189Smarc 37*35189Smarc #include "name.h" 38*35189Smarc #include "flags.h" 39*35189Smarc 40*35189Smarc /* 41*35189Smarc * GETTREE (MSIZE) 42*35189Smarc * 43*35189Smarc * int MSIZE; 44*35189Smarc * 45*35189Smarc * Create an associative memory containing MSIZE headnodes or 46*35189Smarc * buckets, and return a pointer to the root of the memory. 47*35189Smarc * 48*35189Smarc * Algorithm: Memory consists of a hash table of MSIZE buckets, 49*35189Smarc * each of which holds a pointer to a linked list 50*35189Smarc * of Namnods. Nodes are hashed into a bucket by 51*35189Smarc * namid. 52*35189Smarc */ 53*35189Smarc 54*35189Smarc extern char *malloc(); 55*35189Smarc gettree(msize)56*35189Smarcstruct Amemory *gettree(msize) 57*35189Smarc register int msize; 58*35189Smarc { 59*35189Smarc register struct Amemory *root; 60*35189Smarc 61*35189Smarc root = (struct Amemory *)malloc((unsigned)((msize-1)*sizeof(struct Namnod*) 62*35189Smarc + sizeof(struct Amemory))); 63*35189Smarc root->memsize = msize; 64*35189Smarc root->nexttree = NULL; 65*35189Smarc while (msize) 66*35189Smarc root->memhead[--msize] = NULL; 67*35189Smarc return (root); 68*35189Smarc } 69