1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 /* Set attributes of a tree.
26 ** Written by Kiem-Phong Vo (09/17/2001)
30 static Dtlink_t
* treebalance(Dtlink_t
* list
, int size
)
32 static Dtlink_t
* treebalance(list
, size
)
43 for(l
= list
, n
= size
/2 - 1; n
> 0; n
-= 1)
46 mid
= l
->right
; l
->right
= NIL(Dtlink_t
*);
47 mid
->left
= treebalance(list
, (n
= size
/2) );
48 mid
->right
= treebalance(mid
->right
, size
- (n
+ 1));
53 int dttreeset(Dt_t
* dt
, int minp
, int balance
)
55 int dttreeset(dt
, minp
, balance
)
63 if(dt
->meth
->type
!= DT_OSET
)
69 { for(minp
= 0; minp
< DT_MINP
; ++minp
)
70 if((1 << minp
) >= size
)
72 if(minp
<= DT_MINP
-4) /* use log(size) + 4 */
76 if((dt
->data
->minp
= minp
+ (minp
%2)) > DT_MINP
)
77 dt
->data
->minp
= DT_MINP
;
80 dt
->data
->here
= treebalance(dtflatten(dt
), size
);