home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Programming / vahunz / source / ubiqx / ubi_AVLtree.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-17  |  5.6 KB  |  304 lines

  1. /*
  2.  * This source file is part of Vahunz,
  3.  * a tool to make source code un-/more legible.
  4.  *
  5.  *--------------------------------------------------------------------------
  6.  *
  7.  * Vahunz and the Ugly library are Copyright (C) 1998 by
  8.  * Thomas Aglassinger <agi@giga.or.at>
  9.  *
  10.  * All rights reserved.
  11.  *
  12.  * Refer to the manual for more information.
  13.  *
  14.  *--------------------------------------------------------------------------
  15.  *
  16.  * Ubiqx library is Copyright (C) 1991-1998 by
  17.  * Christopher R. Hertel <crh@ubiqx.mn.org>
  18.  *
  19.  * Ubiqx library is free software; you can redistribute it and/or
  20.  * modify it under the terms of the GNU Library General Public
  21.  * License as published by the Free Software Foundation; either
  22.  * version 2 of the License, or (at your option) any later version.
  23.  *
  24.  */
  25. #include "ubi_AVLtree.h" 
  26. #include <stdlib.h> 
  27. static char f2A[] = "ubi_AVLtree\n\
  28. \t$Revision: 2.5 $\n\
  29. \t$Date: 1997/12/23 04:00:42 $\n\
  30. \t$Author: crh $\n";
  31. static h1G L1( h1G p )
  32. {
  33. h1G e0Y;
  34. e0Y = p->b9H[i7C];
  35. p->b9H[i7C] = e0Y->b9H[z7V];
  36. e0Y->b9H[z7V] = p;
  37. e0Y->b9H[z6Y] = p->b9H[z6Y];
  38. e0Y->k5O = p->k5O;
  39. if(e0Y->b9H[z6Y])
  40. (e0Y->b9H[z6Y])->b9H[(int)(e0Y->k5O)] = e0Y;
  41. p->b9H[z6Y] = e0Y;
  42. p->k5O = z7V;
  43. if( p->b9H[i7C] )
  44. {
  45. p->b9H[i7C]->b9H[z6Y] = p;
  46. (p->b9H[i7C])->k5O = i7C;
  47. }
  48. p->h4S -= z7O( e0Y->h4S );
  49. (e0Y->h4S)--;
  50. return( e0Y );
  51. static h1G R1( h1G p )
  52. {
  53. h1G e0Y;
  54. e0Y = p->b9H[z7V];
  55. p->b9H[z7V] = e0Y->b9H[i7C];
  56. e0Y->b9H[i7C] = p;
  57. e0Y->b9H[z6Y] = p->b9H[z6Y];
  58. e0Y->k5O = p->k5O;
  59. if(e0Y->b9H[z6Y])
  60. (e0Y->b9H[z6Y])->b9H[(int)(e0Y->k5O)] = e0Y;
  61. p->b9H[z6Y] = e0Y;
  62. p->k5O = i7C;
  63. if(p->b9H[z7V])
  64. {
  65. p->b9H[z7V]->b9H[z6Y] = p;
  66. p->b9H[z7V]->k5O = z7V;
  67. }
  68. p->h4S -= z7O( e0Y->h4S );
  69. (e0Y->h4S)++;
  70. return( e0Y );
  71. static h1G L2( h1G d2J )
  72. {
  73. h1G e0Y, g3Mw;
  74. e0Y = d2J->b9H[i7C];
  75. g3Mw = e0Y->b9H[z7V];
  76. e0Y->b9H[z7V] = g3Mw->b9H[i7C];
  77. g3Mw->b9H[i7C] = e0Y;
  78. d2J->b9H[i7C] = g3Mw->b9H[z7V];
  79. g3Mw->b9H[z7V] = d2J;
  80. g3Mw->b9H[z6Y] = d2J->b9H[z6Y];
  81. g3Mw->k5O = d2J->k5O;
  82. d2J->b9H[z6Y] = g3Mw;
  83. d2J->k5O = z7V;
  84. e0Y->b9H[z6Y] = g3Mw;
  85. e0Y->k5O = i7C;
  86. if( d2J->b9H[i7C] )
  87. {
  88. d2J->b9H[i7C]->b9H[z6Y] = d2J;
  89. d2J->b9H[i7C]->k5O = i7C;
  90. }
  91. if( e0Y->b9H[z7V] )
  92. {
  93. e0Y->b9H[z7V]->b9H[z6Y] = e0Y;
  94. e0Y->b9H[z7V]->k5O = z7V;
  95. }
  96. if(g3Mw->b9H[z6Y])
  97. g3Mw->b9H[z6Y]->b9H[(int)(g3Mw->k5O)] = g3Mw;
  98. switch( g3Mw->h4S )
  99. {
  100. case z7V :
  101. d2J->h4S = t3Db; e0Y->h4S = i7C; break;
  102. case t3Db:
  103. d2J->h4S = t3Db; e0Y->h4S = t3Db; break;
  104. case i7C:
  105. d2J->h4S = z7V; e0Y->h4S = t3Db; break;
  106. }
  107. g3Mw->h4S = t3Db;
  108. return( g3Mw );
  109. static h1G R2( h1G d2J )
  110. {
  111. h1G e0Y, g3Mw;
  112. e0Y = d2J->b9H[z7V];
  113. g3Mw = e0Y->b9H[i7C];
  114. e0Y->b9H[i7C] = g3Mw->b9H[z7V];
  115. g3Mw->b9H[z7V] = e0Y;
  116. d2J->b9H[z7V] = g3Mw->b9H[i7C];
  117. g3Mw->b9H[i7C] = d2J;
  118. g3Mw->b9H[z6Y] = d2J->b9H[z6Y];
  119. g3Mw->k5O = d2J->k5O;
  120. d2J->b9H[z6Y] = g3Mw;
  121. d2J->k5O = i7C;
  122. e0Y->b9H[z6Y] = g3Mw;
  123. e0Y->k5O = z7V;
  124. if( d2J->b9H[z7V] )
  125. {
  126. d2J->b9H[z7V]->b9H[z6Y] = d2J;
  127. d2J->b9H[z7V]->k5O = z7V;
  128. }
  129. if( e0Y->b9H[i7C] )
  130. {
  131. e0Y->b9H[i7C]->b9H[z6Y] = e0Y;
  132. e0Y->b9H[i7C]->k5O = i7C;
  133. }
  134. if(g3Mw->b9H[z6Y])
  135. g3Mw->b9H[z6Y]->b9H[(int)(g3Mw->k5O)] = g3Mw;
  136. switch( g3Mw->h4S )
  137. {
  138. case z7V :
  139. d2J->h4S = i7C; e0Y->h4S = t3Db; break;
  140. case t3Db :
  141. d2J->h4S = t3Db; e0Y->h4S = t3Db; break;
  142. case i7C :
  143. d2J->h4S = t3Db; e0Y->h4S = z7V; break;
  144. }
  145. g3Mw->h4S = t3Db;
  146. return( g3Mw );
  147. static h1G y3Y( h1G p, char o3T )
  148. {
  149. if( p->h4S != o3T )
  150. p->h4S += z7O(o3T);
  151. else
  152. {
  153. char b2P; 
  154. b2P = p->b9H[(int)o3T]->h4S;
  155. if( ( t3Db == b2P ) || ( p->h4S == b2P ) )
  156. p = ( (z7V==o3T) ? R1(p) : L1(p) ); 
  157. else
  158. p = ( (z7V==o3T) ? R2(p) : L2(p) ); 
  159. }
  160. return( p );
  161. static h1G l2B( h1G f1B,
  162. h1G z0G,
  163. char o3T )
  164. {
  165. while( z0G )
  166. {
  167. z0G = y3Y( z0G, o3T );
  168. if( z6Y == z0G->k5O )
  169. return( z0G );
  170. if( t3Db == z0G->h4S )
  171. return( f1B );
  172. o3T = z0G->k5O;
  173. z0G = z0G->b9H[z6Y];
  174. }
  175. return( f1B );
  176. static h1G t4A( h1G f1B,
  177. h1G z0G,
  178. char o3T )
  179. {
  180. while( z0G )
  181. {
  182. z0G = y3Y( z0G, y2Bn(o3T) );
  183. if( z6Y == z0G->k5O )
  184. return( z0G );
  185. if( t3Db != z0G->h4S )
  186. return( f1B );
  187. o3T = z0G->k5O;
  188. z0G = z0G->b9H[z6Y];
  189. }
  190. return( f1B );
  191. static void l9H( h1G *e2L,
  192. h1G k7H,
  193. h1G t2M )
  194. {
  195. register int i;
  196. register int s3U = sizeof( l3Q );
  197. for( i = 0; i < s3U; i++ )
  198. ((unsigned char *)t2M)[i] = ((unsigned char *)k7H)[i];
  199. (*e2L) = t2M;
  200. if(k7H->b9H[z7V ] )
  201. (k7H->b9H[z7V ])->b9H[z6Y] = t2M;
  202. if(k7H->b9H[i7C] )
  203. (k7H->b9H[i7C])->b9H[z6Y] = t2M;
  204. static void q7H( o4R x8O,
  205. h1G v6L,
  206. h1G h3D )
  207. {
  208. h1G *Parent;
  209. l3Q u4M;
  210. h1G v3O = &u4M;
  211. if( v6L->b9H[z6Y] )
  212. Parent = &((v6L->b9H[z6Y])->b9H[(int)(v6L->k5O)]);
  213. else
  214. Parent = (h1G *)&(x8O->k6P);
  215. l9H( Parent, v6L, v3O );
  216. if( h3D->b9H[z6Y] )
  217. Parent = &((h3D->b9H[z6Y])->b9H[(int)(h3D->k5O)]);
  218. else
  219. Parent = (h1G *)&(x8O->k6P);
  220. l9H( Parent, h3D, v6L );
  221. if( v3O->b9H[z6Y] )
  222. Parent = &((v3O->b9H[z6Y])->b9H[(int)(v3O->k5O)]);
  223. else
  224. Parent = (h1G *)&(x8O->k6P);
  225. l9H( Parent, v3O, h3D );
  226. h1G v2G( h1G y2B )
  227. {
  228. (void)u3Ny( (l1Z)y2B );
  229. y2B->h4S = t3Db;
  230. return( y2B );
  231. f6W y6M( o4R x8O,
  232. h1G j4E,
  233. f7P j7S,
  234. h1G *s3L )
  235. {
  236. h1G r9V;
  237. if( !(s3L) ) s3L = &r9V;
  238. if( k2M( x8O,
  239. (l1Z)j4E,
  240. j7S,
  241. (l1Z *)s3L ) )
  242. {
  243. if( (*s3L) )
  244. j4E->h4S = (*s3L)->h4S;
  245. else
  246. {
  247. j4E->h4S = t3Db;
  248. x8O->k6P = (l1Z)l2B( (h1G)x8O->k6P,
  249. j4E->b9H[z6Y],
  250. j4E->k5O );
  251. }
  252. return( s0E );
  253. }
  254. return( b9P ); 
  255. h1G y5R( o4R x8O,
  256. h1G b2L )
  257. {
  258. l1Z p,
  259. *t6Z;
  260. if( (b2L->b9H[z7V]) && (b2L->b9H[i7C]) )
  261. q7H( x8O, b2L, s0K( b2L ) );
  262. if( b2L->b9H[z6Y] )
  263. t6Z = (l1Z *)
  264. &((b2L->b9H[z6Y])->b9H[(int)(b2L->k5O)]);
  265. else
  266. t6Z = &( x8O->k6P );
  267. if( t3Db == b2L->h4S )
  268. (*t6Z) = NULL;
  269. else
  270. {
  271. p = (l1Z)(b2L->b9H[(int)(b2L->h4S)]);
  272. p->b9H[z6Y] = (l1Z)b2L->b9H[z6Y];
  273. p->k5O = b2L->k5O;
  274. (*t6Z) = p;
  275. }
  276. x8O->k6P = (l1Z)t4A( (h1G)x8O->k6P,
  277. b2L->b9H[z6Y],
  278. b2L->k5O );
  279. (x8O->count)--;
  280. return( b2L );
  281. int p8M( int c8H, char *list[] )
  282. {
  283. if( c8H > 0 )
  284. {
  285. list[0] = f2A;
  286. if( c8H > 1 )
  287. return( 1 + x0K( --c8H, &(list[1]) ) );
  288. return( 1 );
  289. }
  290. return( 0 );
  291.