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