y_bintree_entry.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. #if defined _INC_y_bintree
  2. #endinput
  3. #endif
  4. #define _INC_y_bintree
  5. /*
  6. Legal:
  7. Version: MPL 1.1
  8. The contents of this file are subject to the Mozilla Public License Version
  9. 1.1 the "License"; you may not use this file except in compliance with
  10. the License. You may obtain a copy of the License at
  11. http://www.mozilla.org/MPL/
  12. Software distributed under the License is distributed on an "AS IS" basis,
  13. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. for the specific language governing rights and limitations under the
  15. License.
  16. The Original Code is the YSI framework.
  17. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  18. Portions created by the Initial Developer are Copyright C 2011
  19. the Initial Developer. All Rights Reserved.
  20. Contributors:
  21. Y_Less
  22. koolk
  23. JoeBullet/Google63
  24. g_aSlice/Slice
  25. Misiur
  26. samphunter
  27. tianmeta
  28. maddinat0r
  29. spacemud
  30. Crayder
  31. Dayvison
  32. Ahmad45123
  33. Zeex
  34. irinel1996
  35. Yiin-
  36. Chaprnks
  37. Konstantinos
  38. Masterchen09
  39. Southclaws
  40. PatchwerkQWER
  41. m0k1
  42. paulommu
  43. udan111
  44. Thanks:
  45. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  46. ZeeX - Very productive conversations.
  47. koolk - IsPlayerinAreaEx code.
  48. TheAlpha - Danish translation.
  49. breadfish - German translation.
  50. Fireburn - Dutch translation.
  51. yom - French translation.
  52. 50p - Polish translation.
  53. Zamaroht - Spanish translation.
  54. Los - Portuguese translation.
  55. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  56. me to strive to better.
  57. Pixels^ - Running XScripters where the idea was born.
  58. Matite - Pestering me to release it and using it.
  59. Very special thanks to:
  60. Thiadmer - PAWN, whose limits continue to amaze me!
  61. Kye/Kalcor - SA:MP.
  62. SA:MP Team past, present and future - SA:MP.
  63. Optional plugins:
  64. Gamer_Z - GPS.
  65. Incognito - Streamer.
  66. Me - sscanf2, fixes2, Whirlpool.
  67. */
  68. #include "..\..\YSI_Core\y_utils"
  69. #define BINTREE_NO_BRANCH -1
  70. #define BINTREE_NOT_FOUND -1
  71. // If this ever changes, update the size reference in y_users.
  72. enum E_BINTREE_TREE
  73. {
  74. E_BINTREE_TREE_VALUE,
  75. E_BINTREE_TREE_LEFT,
  76. E_BINTREE_TREE_RIGHT,
  77. E_BINTREE_TREE_PARENT,
  78. E_BINTREE_TREE_POINTER
  79. }
  80. enum E_BINTREE_INPUT
  81. {
  82. E_BINTREE_INPUT_VALUE,
  83. E_BINTREE_INPUT_POINTER
  84. }
  85. //#define leafs<%1> %1][E_BINTREE_TREE
  86. //#define Bintree:%1[%2] Bintree:%1[%2][E_BINTREE_TREE]
  87. #define BinaryTree:%1<%2> Bintree:%1[%2][E_BINTREE_TREE]
  88. #define BinaryInput:%1<%2> %1[%2][E_BINTREE_INPUT]
  89. #if defined YSI_TESTS
  90. #include "y_bintree_tests"
  91. #endif
  92. // Update at a later date...
  93. #define Bintree_DisplayOutput(%0) "<bintree output>"
  94. #define Bintree_DisplayInput(%0) "<bintree input>"
  95. /*-------------------------------------------------------------------------*//**
  96. * <param name="input">Data to sort.</param>
  97. * <param name="size">Size of data to sort.</param>
  98. * <remarks>
  99. * Entry point for Bintree_QSort.
  100. * </remarks>
  101. *//*------------------------------------------------------------------------**/
  102. P:D(Bintree_Sort(numbers[][E_BINTREE_INPUT], size = sizeof (data)));
  103. #define Bintree_Sort(%1,%2) \
  104. Bintree_QSort((%1), 0, (%2) - 1)
  105. /*-------------------------------------------------------------------------*//**
  106. * <param name="output">Destination for balanced tree.</param>
  107. * <param name="data">Source data.</param>
  108. * <param name="size">Size of data.</param>
  109. * <returns>
  110. * Bintree_SortHalf.
  111. * </returns>
  112. * <remarks>
  113. * Entry point for Bintree_SortHalf.
  114. * </remarks>
  115. *//*------------------------------------------------------------------------**/
  116. P:D(Bintree_Fill(BinaryTree:output<>, data[][E_BINTREE_INPUT], size = sizeof (data)));
  117. #define Bintree_Fill(%1,%2,%3) \
  118. Bintree_SortHalf((%1), (%2), 0, (%3), 0, BINTREE_NO_BRANCH)
  119. /*-------------------------------------------------------------------------*//**
  120. * <param name="output">Binary tree to store the data in.</param>
  121. * <param name="input">Input data to get the data from.</param>
  122. * <param name="size">Number of items to sort.</param>
  123. * <remarks>
  124. * Just calls the sort and fill routines.
  125. * </remarks>
  126. *//*------------------------------------------------------------------------**/
  127. stock Bintree_Generate(BinaryTree:output<>, BinaryInput:input<>, size = sizeof (input))
  128. {
  129. P:3("Bintree_Generate called: %s, %s, %i", Bintree_DisplayOutput(output), Bintree_DisplayInput(input), size);
  130. if (!size)
  131. {
  132. output[0][E_BINTREE_TREE_PARENT] = BINTREE_NO_BRANCH;
  133. output[0][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  134. output[0][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  135. return 0;
  136. }
  137. Bintree_Sort(input, size);
  138. Bintree_Fill(output, input, size);
  139. return 1;
  140. }
  141. /*-------------------------------------------------------------------------*//**
  142. * <param name="tree">Array to reset.</param>
  143. * <param name="pointer">Position to reset.</param>
  144. * <remarks>
  145. * Initialises the array for use.
  146. * </remarks>
  147. *//*------------------------------------------------------------------------**/
  148. stock Bintree_Reset(BinaryTree:tree<>, pointer = 0)
  149. {
  150. P:3("Bintree_Reset called: %s, %i", Bintree_DisplayOutput(tree), pointer);
  151. tree[pointer][E_BINTREE_TREE_VALUE] = 0;
  152. tree[pointer][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  153. tree[pointer][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  154. tree[pointer][E_BINTREE_TREE_PARENT] = BINTREE_NO_BRANCH;
  155. tree[pointer][E_BINTREE_TREE_POINTER] = BINTREE_NOT_FOUND;
  156. }
  157. /*-------------------------------------------------------------------------*//**
  158. * <param name="tree">Tree to find the data in.</param>
  159. * <param name="value">Value to search for.</param>
  160. * <param name="cont">Start point.</param>
  161. * <param name="old">The last real leaf.</param>
  162. * <remarks>
  163. * Itterates through the array following the various paths till it locates
  164. * the value provided or reaches a dead end. If the current value is greater
  165. * than the search value, the search goes left, otherwise right.
  166. *
  167. * If cont is not -1 the search will start from the data pointed to by the
  168. * data pointed to by conts' right path, this is to allow collisions to be
  169. * passed over if you want a subsequent one.
  170. * </remarks>
  171. *//*------------------------------------------------------------------------**/
  172. stock Bintree_FindValue(BinaryTree:tree<>, value, &cont = 0, &old = 0)
  173. {
  174. P:3("Bintree_FindValue called: %s, %i, %i, %i", Bintree_DisplayOutput(tree), value, cont, old);
  175. new
  176. treeValue;
  177. while (cont != BINTREE_NO_BRANCH)
  178. {
  179. P:7("Bintree_FindValue: search %d %d %d %d", cont, old, tree[cont][E_BINTREE_TREE_VALUE], value);
  180. old = cont;
  181. treeValue = tree[old][E_BINTREE_TREE_VALUE];
  182. if (value < treeValue) cont = tree[old][E_BINTREE_TREE_LEFT];
  183. else
  184. {
  185. cont = tree[old][E_BINTREE_TREE_RIGHT];
  186. if (value == treeValue)
  187. {
  188. return tree[old][E_BINTREE_TREE_POINTER];
  189. }
  190. }
  191. }
  192. return BINTREE_NOT_FOUND;
  193. }
  194. /*-------------------------------------------------------------------------*//**
  195. * <param name="numbers">Data to sort.</param>
  196. * <param name="left">Start index.</param>
  197. * <param name="right">End index.</param>
  198. * <remarks>
  199. * Custom version of QSort (see YSI_misc) allows for E_BINTREE_INPUT data
  200. * types, preserving the relative pointers for the sorted data.
  201. * </remarks>
  202. *//*------------------------------------------------------------------------**/
  203. stock Bintree_QSort(numbers[][E_BINTREE_INPUT], left, right)
  204. {
  205. P:3("Bintree_QSort called: %s, %i, %i", Bintree_DisplayInput(numbers), left, right);
  206. new
  207. pivot = numbers[left][E_BINTREE_INPUT_VALUE],
  208. pointer = numbers[left][E_BINTREE_INPUT_POINTER],
  209. l_hold = left,
  210. r_hold = right;
  211. while (left < right)
  212. {
  213. while ((numbers[right][E_BINTREE_INPUT_VALUE] >= pivot) && (left < right)) right--;
  214. if (left != right)
  215. {
  216. numbers[left][E_BINTREE_INPUT_VALUE] = numbers[right][E_BINTREE_INPUT_VALUE];
  217. numbers[left][E_BINTREE_INPUT_POINTER] = numbers[right][E_BINTREE_INPUT_POINTER];
  218. left++;
  219. }
  220. while ((numbers[left][E_BINTREE_INPUT_VALUE] <= pivot) && (left < right)) left++;
  221. if (left != right)
  222. {
  223. numbers[right][E_BINTREE_INPUT_VALUE] = numbers[left][E_BINTREE_INPUT_VALUE];
  224. numbers[right][E_BINTREE_INPUT_POINTER] = numbers[left][E_BINTREE_INPUT_POINTER];
  225. right--;
  226. }
  227. }
  228. numbers[left][E_BINTREE_INPUT_VALUE] = pivot;
  229. numbers[left][E_BINTREE_INPUT_POINTER] = pointer;
  230. pivot = left;
  231. left = l_hold;
  232. right = r_hold;
  233. if (left < pivot) Bintree_QSort(numbers, left, pivot - 1);
  234. if (right > pivot) Bintree_QSort(numbers, pivot + 1, right);
  235. }
  236. /*-------------------------------------------------------------------------*//**
  237. * <param name="output">Destination array.</param>
  238. * <param name="data">Source array.</param>
  239. * <param name="index">Start index of the source for processing.</param>
  240. * <param name="upper">End index of the source for processing.</param>
  241. * <param name="offset">Current offset in the destination array for writing.</param>
  242. * <returns>
  243. * Size of balanced tree.
  244. * </returns>
  245. * <remarks>
  246. * Recursively calls itself. Bisects the passed array and passed each half
  247. * back to itself, with the middle value of each half being the left and
  248. * right branches of the middle value of the passed array (which isn't
  249. * included in either bisected half). This is itterative so those are again
  250. * split and again split. If the passed array is only one or two elements
  251. * big the behaviour is set and hardcoded.
  252. *
  253. * Equal values SHOULD branch right, the code is designed for this however
  254. * the generation is not fully tested (it mostly branches right but adjacent
  255. * after bisecting values haven't been tested).
  256. *
  257. * Based on code written for PHP by me.
  258. * </remarks>
  259. *//*------------------------------------------------------------------------**/
  260. stock Bintree_SortHalf(BinaryTree:output<>, data[][E_BINTREE_INPUT], index, upper, offset, parent)
  261. {
  262. P:3("Bintree_SortHalf called: %s, %s, %i, %i, %i, %i", Bintree_DisplayOutput(output), Bintree_DisplayInput(data), index, upper, offset, parent);
  263. new
  264. num = upper - index;
  265. if (!num) return offset;
  266. if (num == 1)
  267. {
  268. output[offset][E_BINTREE_TREE_VALUE] = data[index][E_BINTREE_INPUT_VALUE];
  269. output[offset][E_BINTREE_TREE_POINTER] = data[index][E_BINTREE_INPUT_POINTER];
  270. output[offset][E_BINTREE_TREE_PARENT] = parent;
  271. output[offset][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  272. output[offset][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  273. }
  274. else if (num == 2)
  275. {
  276. P:3("Bintree_SortHalf: adding %i %i %i", index, data[index][E_BINTREE_INPUT_VALUE], data[index + 1][E_BINTREE_INPUT_VALUE]);
  277. output[offset][E_BINTREE_TREE_VALUE] = data[index][E_BINTREE_INPUT_VALUE];
  278. output[offset][E_BINTREE_TREE_POINTER] = data[index][E_BINTREE_INPUT_POINTER];
  279. output[offset][E_BINTREE_TREE_PARENT] = parent;
  280. output[offset][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  281. output[offset][E_BINTREE_TREE_RIGHT] = offset + 1;
  282. ++offset;
  283. ++index;
  284. output[offset][E_BINTREE_TREE_VALUE] = data[index][E_BINTREE_INPUT_VALUE];
  285. output[offset][E_BINTREE_TREE_POINTER] = data[index][E_BINTREE_INPUT_POINTER];
  286. output[offset][E_BINTREE_TREE_PARENT] = offset - 1;
  287. output[offset][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  288. output[offset][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  289. }
  290. else
  291. {
  292. new
  293. half = num / 2,
  294. off = half + index,
  295. right;
  296. while (off && data[off][E_BINTREE_INPUT_VALUE] == data[off - 1][E_BINTREE_INPUT_VALUE]) off--;
  297. right = Bintree_SortHalf(output, data, index, off, offset + 1, offset);
  298. output[offset][E_BINTREE_TREE_VALUE] = data[off][E_BINTREE_INPUT_VALUE];
  299. output[offset][E_BINTREE_TREE_POINTER] = data[off][E_BINTREE_INPUT_POINTER];
  300. output[offset][E_BINTREE_TREE_PARENT] = parent;
  301. output[offset][E_BINTREE_TREE_LEFT] = offset + 1;
  302. output[offset][E_BINTREE_TREE_RIGHT] = right;
  303. return Bintree_SortHalf(output, data, off + 1, upper, right, offset);
  304. }
  305. return offset + 1;
  306. }
  307. /*-------------------------------------------------------------------------*//**
  308. * <param name="data">Array to add to.</param>
  309. * <param name="pointer">Pointer to add.</param>
  310. * <param name="value">Value to add.</param>
  311. * <param name="offset">Location in the array to store the data.</param>
  312. * <param name="maxsize">Size of data.</param>
  313. * <returns>
  314. * Next free location
  315. * </returns>
  316. * <remarks>
  317. * -
  318. *
  319. * native Bintree_Add(BinaryTree:tree<>, pointer, value, offset, maxsize = sizeof (data));
  320. *
  321. * </remarks>
  322. *//*------------------------------------------------------------------------**/
  323. stock Bintree_Add(BinaryTree:data<>, pointer, value, offset, maxsize = sizeof (data))
  324. {
  325. P:3("Bintree_Add called: %s, %i, %i, %i, %i", Bintree_DisplayOutput(data), pointer, value, offset, maxsize);
  326. if (offset >= maxsize) return BINTREE_NOT_FOUND;
  327. if (offset)
  328. {
  329. new
  330. leaf,
  331. old;
  332. while (Bintree_FindValue(data, value, leaf, old) != BINTREE_NOT_FOUND) continue;
  333. //Bintree_Reset(data, offset);
  334. if (value < data[old][E_BINTREE_TREE_VALUE]) data[old][E_BINTREE_TREE_LEFT] = offset;
  335. else data[old][E_BINTREE_TREE_RIGHT] = offset;
  336. data[offset][E_BINTREE_TREE_PARENT] = old;
  337. data[offset][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  338. data[offset][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  339. data[offset][E_BINTREE_TREE_VALUE] = value;
  340. data[offset][E_BINTREE_TREE_POINTER] = pointer;
  341. return offset + 1;
  342. }
  343. else
  344. {
  345. data[0][E_BINTREE_TREE_PARENT] = BINTREE_NO_BRANCH;
  346. data[0][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  347. data[0][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  348. data[0][E_BINTREE_TREE_VALUE] = value;
  349. data[0][E_BINTREE_TREE_POINTER] = pointer;
  350. return 1;
  351. }
  352. }
  353. /*-------------------------------------------------------------------------*//**
  354. * <param name="tree">Data.</param>
  355. * <param name="index">Index to remove.</param>
  356. * <param name="count">Number of binary tree items.</param>
  357. * <remarks>
  358. * The left branch is usually larger due to the division
  359. * method used so we start there. Even though right is
  360. * >= and left is only < in even sized arrays the greater
  361. * chunk (unless there's only 2 items) goes left.
  362. *
  363. * Called itteratively to ensure branches are maintained.
  364. * </remarks>
  365. *//*------------------------------------------------------------------------**/
  366. stock Bintree_Delete(BinaryTree:source<>, index, count)
  367. {
  368. P:3("Bintree_Delete called: %s, %i, %i", Bintree_DisplayOutput(source), index, count);
  369. new
  370. branch,
  371. old = index;
  372. while (TRUE)
  373. {
  374. if ((branch = source[old][E_BINTREE_TREE_LEFT]) != BINTREE_NO_BRANCH) branch = Bintree_FindMax(source, branch);
  375. else if ((branch = source[old][E_BINTREE_TREE_RIGHT]) != BINTREE_NO_BRANCH) branch = Bintree_FindMin(source, branch);
  376. else
  377. {
  378. if ((branch = source[old][E_BINTREE_TREE_PARENT]) != BINTREE_NO_BRANCH)
  379. {
  380. if (source[branch][E_BINTREE_TREE_LEFT] == old) source[branch][E_BINTREE_TREE_LEFT] = BINTREE_NO_BRANCH;
  381. else source[branch][E_BINTREE_TREE_RIGHT] = BINTREE_NO_BRANCH;
  382. }
  383. return Bintree_Compress(source, old, count);
  384. }
  385. new
  386. value = source[old][E_BINTREE_TREE_VALUE],
  387. pointer = source[old][E_BINTREE_TREE_POINTER];
  388. source[old][E_BINTREE_TREE_VALUE] = source[branch][E_BINTREE_TREE_VALUE];
  389. source[old][E_BINTREE_TREE_POINTER] = source[branch][E_BINTREE_TREE_POINTER];
  390. source[branch][E_BINTREE_TREE_VALUE] = value;
  391. source[branch][E_BINTREE_TREE_POINTER] = pointer;
  392. old = branch;
  393. }
  394. return BINTREE_NO_BRANCH;
  395. }
  396. /*-------------------------------------------------------------------------*//**
  397. * <param name="tree">Array to compress.</param>
  398. * <param name="index">Point to start at.</param>
  399. * <param name="count">Number of items total.</param>
  400. *//*------------------------------------------------------------------------**/
  401. static stock Bintree_Compress(BinaryTree:data<>, index, count)
  402. {
  403. P:4("Bintree_Compress called: %s, %i, %i", Bintree_DisplayOutput(data), index, count);
  404. new
  405. index2 = index + 1;
  406. while (index < count)
  407. {
  408. new
  409. left = (data[index][E_BINTREE_TREE_LEFT] = data[index2][E_BINTREE_TREE_LEFT]),
  410. right = (data[index][E_BINTREE_TREE_RIGHT] = data[index2][E_BINTREE_TREE_RIGHT]),
  411. parent = (data[index][E_BINTREE_TREE_PARENT] = data[index2][E_BINTREE_TREE_PARENT]);
  412. data[index][E_BINTREE_TREE_VALUE] = data[index2][E_BINTREE_TREE_VALUE];
  413. data[index][E_BINTREE_TREE_POINTER] = data[index2][E_BINTREE_TREE_POINTER];
  414. if (left != BINTREE_NO_BRANCH) data[left][E_BINTREE_TREE_PARENT] = index;
  415. if (right != BINTREE_NO_BRANCH) data[right][E_BINTREE_TREE_PARENT] = index;
  416. if (parent != BINTREE_NO_BRANCH)
  417. {
  418. if (data[parent][E_BINTREE_TREE_LEFT] == index2) data[parent][E_BINTREE_TREE_LEFT] = index;
  419. else if (data[parent][E_BINTREE_TREE_RIGHT] == index2) data[parent][E_BINTREE_TREE_RIGHT] = index;
  420. }
  421. index++;
  422. index2++;
  423. }
  424. return count - 1;
  425. }
  426. /*-------------------------------------------------------------------------*//**
  427. * <param name="data">Array to search.</param>
  428. * <param name="offset">Start of branch to search.</param>
  429. * <remarks>
  430. * Finds the smallest value on a branch
  431. * </remarks>
  432. *//*------------------------------------------------------------------------**/
  433. static stock Bintree_FindMin(BinaryTree:data<>, offset)
  434. {
  435. P:4("Bintree_FindMin called: %s, %i", Bintree_DisplayOutput(data), offset);
  436. new
  437. branch;
  438. while ((branch = data[offset][E_BINTREE_TREE_LEFT]) != BINTREE_NO_BRANCH) offset = branch;
  439. return offset;
  440. }
  441. /*-------------------------------------------------------------------------*//**
  442. * <param name="data">Array to search.</param>
  443. * <param name="offset">Start of branch to search.</param>
  444. * <remarks>
  445. * Finds the largest value on a branch
  446. * </remarks>
  447. *//*------------------------------------------------------------------------**/
  448. static stock Bintree_FindMax(BinaryTree:data<>, offset)
  449. {
  450. P:4("Bintree_FindMax called: %s, %i", Bintree_DisplayOutput(data), offset);
  451. new
  452. branch;
  453. while ((branch = data[offset][E_BINTREE_TREE_RIGHT]) != BINTREE_NO_BRANCH) offset = branch;
  454. return offset;
  455. }
  456. /*-------------------------------------------------------------------------*//**
  457. * <param name="data">Data to modify.</param>
  458. * <param name="offset">Pointer to modify values after.</param>
  459. * <param name="mod">Value to modify by.</param>
  460. * <remarks>
  461. * Used for updating pointers when the target data has been modifed (i.e. a
  462. * value has been removed from the array and the array shifted).
  463. * </remarks>
  464. *//*------------------------------------------------------------------------**/
  465. stock Bintree_UpdatePointers(BinaryTree:data<>, offset, size, mod = -1)
  466. {
  467. P:3("Bintree_UpdatePointers called: %s, %i, %i, %i", Bintree_DisplayOutput(data), offset, size, mod);
  468. for (new i = 0; i < size; i++)
  469. {
  470. if (data[i][E_BINTREE_TREE_POINTER] > offset) data[i][E_BINTREE_TREE_POINTER] += mod;
  471. }
  472. }