Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

625 lines
23 KiB

  1. /*
  2. File: AVLTree.h
  3. Contains: Interfaces for AVL balanced trees.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1999-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __AVLTREE__
  11. #define __AVLTREE__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __MIXEDMODE__
  16. #include <MixedMode.h>
  17. #endif
  18. /* The visit stage for AVLWalk() walkProcs */
  19. #if PRAGMA_ONCE
  20. #pragma once
  21. #endif
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #if PRAGMA_IMPORT
  26. #pragma import on
  27. #endif
  28. #if PRAGMA_STRUCT_ALIGN
  29. #pragma options align=mac68k
  30. #elif PRAGMA_STRUCT_PACKPUSH
  31. #pragma pack(push, 2)
  32. #elif PRAGMA_STRUCT_PACK
  33. #pragma pack(2)
  34. #endif
  35. /*
  36. * AVLTree
  37. *
  38. * Discussion:
  39. * Prototypes for routines which create, destroy, allow for
  40. * insertion, deleting, and iteration of routines in an AVL balanced
  41. * binary tree.
  42. *
  43. * An AVL tree is a balanced, binary tree which is fairly fast for
  44. * finds and acceptably fast for insertion and deletion. The tree
  45. * is kept balanced, so that the heights of any given node's left
  46. * and right branches never differ by more than 1, which keeps
  47. * performance from being too horribe in the degenerate case.
  48. *
  49. *
  50. * Very loosely based on some public domain source code for doing
  51. * avl trees and on the discussion in Sedgewick "Algorithms" book.
  52. */
  53. typedef UInt16 AVLVisitStage;
  54. enum {
  55. kAVLPreOrder = 0,
  56. kAVLInOrder = 1,
  57. kAVLPostOrder = 2
  58. };
  59. /* The order the tree is walked or disposed of. */
  60. typedef UInt16 AVLOrder;
  61. enum {
  62. kLeftToRight = 0,
  63. kRightToLeft = 1
  64. };
  65. /* The type of the node being passed to a callback proc. */
  66. typedef UInt16 AVLNodeType;
  67. enum {
  68. kAVLIsTree = 0,
  69. kAVLIsLeftBranch = 1,
  70. kAVLIsRightBranch = 2,
  71. kAVLIsLeaf = 3,
  72. kAVLNullNode = 4
  73. };
  74. enum {
  75. errItemAlreadyInTree = -960,
  76. errNotValidTree = -961,
  77. errItemNotFoundInTree = -962,
  78. errCanNotInsertWhileWalkProcInProgress = -963,
  79. errTreeIsLocked = -964
  80. };
  81. /* The structure of a tree. It's opaque; don't assume it's 36 bytes in size.*/
  82. struct AVLTreeStruct {
  83. OSType signature;
  84. unsigned long privateStuff[8];
  85. };
  86. typedef struct AVLTreeStruct AVLTreeStruct;
  87. typedef AVLTreeStruct * AVLTreePtr;
  88. /*
  89. Every tree must have a function which compares the data for two items and returns < 0, 0, or >0
  90. for the items - < 0 if the first item is 'before' the second item according to some criteria,
  91. == 0 if the two items are identical according to the criteria, or > 0 if the first item is
  92. 'after' the second item according to the criteria. The comparison function is also passed the
  93. node type, but most of the time this can be ignored.
  94. */
  95. typedef CALLBACK_API( SInt32 , AVLCompareItemsProcPtr )(AVLTreePtr tree, const void *i1, const void *i2, AVLNodeType nd_typ);
  96. /*
  97. Every tree must have a itemSizeProc; this routine gets passed a pointer to the item's data and
  98. returns the size of the data. If a tree contains records of a fixed size, this function can
  99. just return sizeof( that-struct ); otherwise it should calculate the size of the item based on
  100. the data for the item.
  101. */
  102. typedef CALLBACK_API( UInt32 , AVLItemSizeProcPtr )(AVLTreePtr tree, const void *itemPtr);
  103. /*
  104. A tree may have an optional disposeItemProc, which gets called whenever an item is removed
  105. from the tree ( via AVLRemove() or when AVLDispose() deletes all of the items in the tree ).
  106. This might be useful if the nodes in the tree own 'resources' ( like, open files ) which
  107. should be released before the item is removed.
  108. */
  109. typedef CALLBACK_API( void , AVLDisposeItemProcPtr )(AVLTreePtr tree, const void *dataP);
  110. /*
  111. The common way to iterate across all of the items in a tree is via AVLWalk(), which takes
  112. a walkProcPtr. This function will get called for every item in the tree three times, as
  113. the tree is being walked across. First, the walkProc will get called with visitStage ==
  114. kAVLPreOrder, at which point internally the node of the tree for the given data has just
  115. been reached. Later, this function will get called with visitStage == kAVLInOrder, and
  116. lastly this function will get called with visitStage == kAVLPostOrder.
  117. The 'minimum' item in the tree will get called with visitStage == kInOrder first, followed
  118. by the 'next' item in the tree, up until the last item in the tree structure is called.
  119. In general, you'll only care about calls to this function when visitStage == kAVLInOrder.
  120. */
  121. typedef CALLBACK_API( OSErr , AVLWalkProcPtr )(AVLTreePtr tree, const void *dataP, AVLVisitStage visitStage, AVLNodeType node, UInt32 level, SInt32 balance, void *refCon);
  122. typedef STACK_UPP_TYPE(AVLCompareItemsProcPtr) AVLCompareItemsUPP;
  123. typedef STACK_UPP_TYPE(AVLItemSizeProcPtr) AVLItemSizeUPP;
  124. typedef STACK_UPP_TYPE(AVLDisposeItemProcPtr) AVLDisposeItemUPP;
  125. typedef STACK_UPP_TYPE(AVLWalkProcPtr) AVLWalkUPP;
  126. /*
  127. * NewAVLCompareItemsUPP()
  128. *
  129. * Availability:
  130. * Non-Carbon CFM: available as macro/inline
  131. * CarbonLib: in CarbonLib 1.0 and later
  132. * Mac OS X: in version 10.0 and later
  133. */
  134. EXTERN_API_C( AVLCompareItemsUPP )
  135. NewAVLCompareItemsUPP(AVLCompareItemsProcPtr userRoutine);
  136. #if !OPAQUE_UPP_TYPES
  137. enum { uppAVLCompareItemsProcInfo = 0x00002FF0 }; /* pascal 4_bytes Func(4_bytes, 4_bytes, 4_bytes, 2_bytes) */
  138. #ifdef __cplusplus
  139. inline DEFINE_API_C(AVLCompareItemsUPP) NewAVLCompareItemsUPP(AVLCompareItemsProcPtr userRoutine) { return (AVLCompareItemsUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLCompareItemsProcInfo, GetCurrentArchitecture()); }
  140. #else
  141. #define NewAVLCompareItemsUPP(userRoutine) (AVLCompareItemsUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLCompareItemsProcInfo, GetCurrentArchitecture())
  142. #endif
  143. #endif
  144. /*
  145. * NewAVLItemSizeUPP()
  146. *
  147. * Availability:
  148. * Non-Carbon CFM: available as macro/inline
  149. * CarbonLib: in CarbonLib 1.0 and later
  150. * Mac OS X: in version 10.0 and later
  151. */
  152. EXTERN_API_C( AVLItemSizeUPP )
  153. NewAVLItemSizeUPP(AVLItemSizeProcPtr userRoutine);
  154. #if !OPAQUE_UPP_TYPES
  155. enum { uppAVLItemSizeProcInfo = 0x000003F0 }; /* pascal 4_bytes Func(4_bytes, 4_bytes) */
  156. #ifdef __cplusplus
  157. inline DEFINE_API_C(AVLItemSizeUPP) NewAVLItemSizeUPP(AVLItemSizeProcPtr userRoutine) { return (AVLItemSizeUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLItemSizeProcInfo, GetCurrentArchitecture()); }
  158. #else
  159. #define NewAVLItemSizeUPP(userRoutine) (AVLItemSizeUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLItemSizeProcInfo, GetCurrentArchitecture())
  160. #endif
  161. #endif
  162. /*
  163. * NewAVLDisposeItemUPP()
  164. *
  165. * Availability:
  166. * Non-Carbon CFM: available as macro/inline
  167. * CarbonLib: in CarbonLib 1.0 and later
  168. * Mac OS X: in version 10.0 and later
  169. */
  170. EXTERN_API_C( AVLDisposeItemUPP )
  171. NewAVLDisposeItemUPP(AVLDisposeItemProcPtr userRoutine);
  172. #if !OPAQUE_UPP_TYPES
  173. enum { uppAVLDisposeItemProcInfo = 0x000003C0 }; /* pascal no_return_value Func(4_bytes, 4_bytes) */
  174. #ifdef __cplusplus
  175. inline DEFINE_API_C(AVLDisposeItemUPP) NewAVLDisposeItemUPP(AVLDisposeItemProcPtr userRoutine) { return (AVLDisposeItemUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLDisposeItemProcInfo, GetCurrentArchitecture()); }
  176. #else
  177. #define NewAVLDisposeItemUPP(userRoutine) (AVLDisposeItemUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLDisposeItemProcInfo, GetCurrentArchitecture())
  178. #endif
  179. #endif
  180. /*
  181. * NewAVLWalkUPP()
  182. *
  183. * Availability:
  184. * Non-Carbon CFM: available as macro/inline
  185. * CarbonLib: in CarbonLib 1.0 and later
  186. * Mac OS X: in version 10.0 and later
  187. */
  188. EXTERN_API_C( AVLWalkUPP )
  189. NewAVLWalkUPP(AVLWalkProcPtr userRoutine);
  190. #if !OPAQUE_UPP_TYPES
  191. enum { uppAVLWalkProcInfo = 0x000FEBE0 }; /* pascal 2_bytes Func(4_bytes, 4_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes, 4_bytes) */
  192. #ifdef __cplusplus
  193. inline DEFINE_API_C(AVLWalkUPP) NewAVLWalkUPP(AVLWalkProcPtr userRoutine) { return (AVLWalkUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLWalkProcInfo, GetCurrentArchitecture()); }
  194. #else
  195. #define NewAVLWalkUPP(userRoutine) (AVLWalkUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLWalkProcInfo, GetCurrentArchitecture())
  196. #endif
  197. #endif
  198. /*
  199. * DisposeAVLCompareItemsUPP()
  200. *
  201. * Availability:
  202. * Non-Carbon CFM: available as macro/inline
  203. * CarbonLib: in CarbonLib 1.0 and later
  204. * Mac OS X: in version 10.0 and later
  205. */
  206. EXTERN_API_C( void )
  207. DisposeAVLCompareItemsUPP(AVLCompareItemsUPP userUPP);
  208. #if !OPAQUE_UPP_TYPES
  209. #ifdef __cplusplus
  210. inline DEFINE_API_C(void) DisposeAVLCompareItemsUPP(AVLCompareItemsUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  211. #else
  212. #define DisposeAVLCompareItemsUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  213. #endif
  214. #endif
  215. /*
  216. * DisposeAVLItemSizeUPP()
  217. *
  218. * Availability:
  219. * Non-Carbon CFM: available as macro/inline
  220. * CarbonLib: in CarbonLib 1.0 and later
  221. * Mac OS X: in version 10.0 and later
  222. */
  223. EXTERN_API_C( void )
  224. DisposeAVLItemSizeUPP(AVLItemSizeUPP userUPP);
  225. #if !OPAQUE_UPP_TYPES
  226. #ifdef __cplusplus
  227. inline DEFINE_API_C(void) DisposeAVLItemSizeUPP(AVLItemSizeUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  228. #else
  229. #define DisposeAVLItemSizeUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  230. #endif
  231. #endif
  232. /*
  233. * DisposeAVLDisposeItemUPP()
  234. *
  235. * Availability:
  236. * Non-Carbon CFM: available as macro/inline
  237. * CarbonLib: in CarbonLib 1.0 and later
  238. * Mac OS X: in version 10.0 and later
  239. */
  240. EXTERN_API_C( void )
  241. DisposeAVLDisposeItemUPP(AVLDisposeItemUPP userUPP);
  242. #if !OPAQUE_UPP_TYPES
  243. #ifdef __cplusplus
  244. inline DEFINE_API_C(void) DisposeAVLDisposeItemUPP(AVLDisposeItemUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  245. #else
  246. #define DisposeAVLDisposeItemUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  247. #endif
  248. #endif
  249. /*
  250. * DisposeAVLWalkUPP()
  251. *
  252. * Availability:
  253. * Non-Carbon CFM: available as macro/inline
  254. * CarbonLib: in CarbonLib 1.0 and later
  255. * Mac OS X: in version 10.0 and later
  256. */
  257. EXTERN_API_C( void )
  258. DisposeAVLWalkUPP(AVLWalkUPP userUPP);
  259. #if !OPAQUE_UPP_TYPES
  260. #ifdef __cplusplus
  261. inline DEFINE_API_C(void) DisposeAVLWalkUPP(AVLWalkUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  262. #else
  263. #define DisposeAVLWalkUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  264. #endif
  265. #endif
  266. /*
  267. * InvokeAVLCompareItemsUPP()
  268. *
  269. * Availability:
  270. * Non-Carbon CFM: available as macro/inline
  271. * CarbonLib: in CarbonLib 1.0 and later
  272. * Mac OS X: in version 10.0 and later
  273. */
  274. EXTERN_API_C( SInt32 )
  275. InvokeAVLCompareItemsUPP(
  276. AVLTreePtr tree,
  277. const void * i1,
  278. const void * i2,
  279. AVLNodeType nd_typ,
  280. AVLCompareItemsUPP userUPP);
  281. #if !OPAQUE_UPP_TYPES
  282. #ifdef __cplusplus
  283. inline DEFINE_API_C(SInt32) InvokeAVLCompareItemsUPP(AVLTreePtr tree, const void * i1, const void * i2, AVLNodeType nd_typ, AVLCompareItemsUPP userUPP) { return (SInt32)CALL_FOUR_PARAMETER_UPP(userUPP, uppAVLCompareItemsProcInfo, tree, i1, i2, nd_typ); }
  284. #else
  285. #define InvokeAVLCompareItemsUPP(tree, i1, i2, nd_typ, userUPP) (SInt32)CALL_FOUR_PARAMETER_UPP((userUPP), uppAVLCompareItemsProcInfo, (tree), (i1), (i2), (nd_typ))
  286. #endif
  287. #endif
  288. /*
  289. * InvokeAVLItemSizeUPP()
  290. *
  291. * Availability:
  292. * Non-Carbon CFM: available as macro/inline
  293. * CarbonLib: in CarbonLib 1.0 and later
  294. * Mac OS X: in version 10.0 and later
  295. */
  296. EXTERN_API_C( UInt32 )
  297. InvokeAVLItemSizeUPP(
  298. AVLTreePtr tree,
  299. const void * itemPtr,
  300. AVLItemSizeUPP userUPP);
  301. #if !OPAQUE_UPP_TYPES
  302. #ifdef __cplusplus
  303. inline DEFINE_API_C(UInt32) InvokeAVLItemSizeUPP(AVLTreePtr tree, const void * itemPtr, AVLItemSizeUPP userUPP) { return (UInt32)CALL_TWO_PARAMETER_UPP(userUPP, uppAVLItemSizeProcInfo, tree, itemPtr); }
  304. #else
  305. #define InvokeAVLItemSizeUPP(tree, itemPtr, userUPP) (UInt32)CALL_TWO_PARAMETER_UPP((userUPP), uppAVLItemSizeProcInfo, (tree), (itemPtr))
  306. #endif
  307. #endif
  308. /*
  309. * InvokeAVLDisposeItemUPP()
  310. *
  311. * Availability:
  312. * Non-Carbon CFM: available as macro/inline
  313. * CarbonLib: in CarbonLib 1.0 and later
  314. * Mac OS X: in version 10.0 and later
  315. */
  316. EXTERN_API_C( void )
  317. InvokeAVLDisposeItemUPP(
  318. AVLTreePtr tree,
  319. const void * dataP,
  320. AVLDisposeItemUPP userUPP);
  321. #if !OPAQUE_UPP_TYPES
  322. #ifdef __cplusplus
  323. inline DEFINE_API_C(void) InvokeAVLDisposeItemUPP(AVLTreePtr tree, const void * dataP, AVLDisposeItemUPP userUPP) { CALL_TWO_PARAMETER_UPP(userUPP, uppAVLDisposeItemProcInfo, tree, dataP); }
  324. #else
  325. #define InvokeAVLDisposeItemUPP(tree, dataP, userUPP) CALL_TWO_PARAMETER_UPP((userUPP), uppAVLDisposeItemProcInfo, (tree), (dataP))
  326. #endif
  327. #endif
  328. /*
  329. * InvokeAVLWalkUPP()
  330. *
  331. * Availability:
  332. * Non-Carbon CFM: available as macro/inline
  333. * CarbonLib: in CarbonLib 1.0 and later
  334. * Mac OS X: in version 10.0 and later
  335. */
  336. EXTERN_API_C( OSErr )
  337. InvokeAVLWalkUPP(
  338. AVLTreePtr tree,
  339. const void * dataP,
  340. AVLVisitStage visitStage,
  341. AVLNodeType node,
  342. UInt32 level,
  343. SInt32 balance,
  344. void * refCon,
  345. AVLWalkUPP userUPP);
  346. #if !OPAQUE_UPP_TYPES
  347. #ifdef __cplusplus
  348. inline DEFINE_API_C(OSErr) InvokeAVLWalkUPP(AVLTreePtr tree, const void * dataP, AVLVisitStage visitStage, AVLNodeType node, UInt32 level, SInt32 balance, void * refCon, AVLWalkUPP userUPP) { return (OSErr)CALL_SEVEN_PARAMETER_UPP(userUPP, uppAVLWalkProcInfo, tree, dataP, visitStage, node, level, balance, refCon); }
  349. #else
  350. #define InvokeAVLWalkUPP(tree, dataP, visitStage, node, level, balance, refCon, userUPP) (OSErr)CALL_SEVEN_PARAMETER_UPP((userUPP), uppAVLWalkProcInfo, (tree), (dataP), (visitStage), (node), (level), (balance), (refCon))
  351. #endif
  352. #endif
  353. #if CALL_NOT_IN_CARBON || OLDROUTINENAMES
  354. /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
  355. #define NewAVLCompareItemsProc(userRoutine) NewAVLCompareItemsUPP(userRoutine)
  356. #define NewAVLItemSizeProc(userRoutine) NewAVLItemSizeUPP(userRoutine)
  357. #define NewAVLDisposeItemProc(userRoutine) NewAVLDisposeItemUPP(userRoutine)
  358. #define NewAVLWalkProc(userRoutine) NewAVLWalkUPP(userRoutine)
  359. #define CallAVLCompareItemsProc(userRoutine, tree, i1, i2, nd_typ) InvokeAVLCompareItemsUPP(tree, i1, i2, nd_typ, userRoutine)
  360. #define CallAVLItemSizeProc(userRoutine, tree, itemPtr) InvokeAVLItemSizeUPP(tree, itemPtr, userRoutine)
  361. #define CallAVLDisposeItemProc(userRoutine, tree, dataP) InvokeAVLDisposeItemUPP(tree, dataP, userRoutine)
  362. #define CallAVLWalkProc(userRoutine, tree, dataP, visitStage, node, level, balance, refCon) InvokeAVLWalkUPP(tree, dataP, visitStage, node, level, balance, refCon, userRoutine)
  363. #endif /* CALL_NOT_IN_CARBON */
  364. /*
  365. Create an AVL tree. The compareItemsProc and the sizeItemProc are required; disposeItemProc is
  366. optional and can be nil. The refCon is stored with the list, and is passed back to the
  367. compareItemsProc, sizeItemProc, and disposeItemsProc calls. The allocation of the tree ( and all
  368. nodes later added to the list with AVLInsert ) will be created in what is the current zone at the
  369. time AVLInit() is called. Always call AVLDispose() to dispose of a list created with AVLInit().
  370. */
  371. /*
  372. * AVLInit()
  373. *
  374. * Availability:
  375. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  376. * CarbonLib: in CarbonLib 1.0 and later
  377. * Mac OS X: in version 10.0 and later
  378. */
  379. EXTERN_API( OSErr )
  380. AVLInit(
  381. UInt32 flags,
  382. AVLCompareItemsUPP compareItemsProc,
  383. AVLItemSizeUPP sizeItemProc,
  384. AVLDisposeItemUPP disposeItemProc,
  385. void * refCon,
  386. AVLTreePtr * tree) THREEWORDINLINE(0x303C, 0x0C01, 0xAA80);
  387. /*
  388. Dispose of an AVL tree. This will dispose of each item in the tree in the order specified,
  389. call the tree's disposeProc proc for each item, and then dispose of the space allocated for
  390. the tree itself.
  391. */
  392. /*
  393. * AVLDispose()
  394. *
  395. * Availability:
  396. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  397. * CarbonLib: in CarbonLib 1.0 and later
  398. * Mac OS X: in version 10.0 and later
  399. */
  400. EXTERN_API( OSErr )
  401. AVLDispose(
  402. AVLTreePtr * tree,
  403. AVLOrder order) THREEWORDINLINE(0x303C, 0x0302, 0xAA80);
  404. /*
  405. Iterate across all of the items in the tree, in the order specified. kLeftToRight is
  406. basically lowest-to-highest order, kRightToLeft is highest-to-lowest order. For each
  407. node in the tree, it will call the walkProc with three messages ( at the appropriate
  408. time ). First, with kAVLPreOrder when the walking gets to this node in the tree,
  409. before handling either the left or right subtree, secondly, with kAVLInOrder after
  410. handling one subtree but before handling the other, and lastly with kAVLPostOrder after
  411. handling both subtrees. If you want to handle items in order, then only do something
  412. if the visit stage is kAVLInOrder. You can only call AVLRemove() from inside a walkProc
  413. if visit stage is kAVLPostOrder ( because if you remove a node during the pre or in order
  414. stages you will corrupt the list ) OR if you return a non-zero result from the walkProc
  415. call which called AVLRemove() to immediately terminate the walkProc. Do not call AVLInsert()
  416. to insert a node into the tree from inside a walkProc.
  417. The walkProc function gets called with the AVLTreePtr, a pointer to the data for the
  418. current node ( which you can change in place as long as you do not affect the order within
  419. the tree ), the visit stage, the type of the current node ( leaf node, right or left branch,
  420. or full tree ), the level within the tree ( the root is level 1 ), the balance for the
  421. current node, and the refCon passed to AVLWalk(). This refCon is different from the one passed
  422. into AVLInit(); use AVLGetRefCon() to get that refCon if you want it inside a walkProc.
  423. ( Most walkProcs will not care about the values for node type, level, or balance. )
  424. */
  425. /*
  426. * AVLWalk()
  427. *
  428. * Availability:
  429. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  430. * CarbonLib: in CarbonLib 1.0 and later
  431. * Mac OS X: in version 10.0 and later
  432. */
  433. EXTERN_API( OSErr )
  434. AVLWalk(
  435. AVLTreePtr tree,
  436. AVLWalkUPP walkProc,
  437. AVLOrder order,
  438. void * walkRefCon) THREEWORDINLINE(0x303C, 0x0703, 0xAA80);
  439. /* Return the number of items in the given tree.*/
  440. /*
  441. * AVLCount()
  442. *
  443. * Availability:
  444. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  445. * CarbonLib: in CarbonLib 1.0 and later
  446. * Mac OS X: in version 10.0 and later
  447. */
  448. EXTERN_API( OSErr )
  449. AVLCount(
  450. AVLTreePtr tree,
  451. UInt32 * count) THREEWORDINLINE(0x303C, 0x0804, 0xAA80);
  452. /*
  453. Return the one-based index-th item from the tree by putting it's data at dataPtr
  454. if dataPtr is non-nil, and it's size into *itemSize if itemSize is non-nil.
  455. If index is out of range, return errItemNotFoundInTree. ( Internally, this does
  456. an AVLWalk(), so the tree can not be modified while this call is in progress ).
  457. */
  458. /*
  459. * AVLGetIndItem()
  460. *
  461. * Availability:
  462. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  463. * CarbonLib: in CarbonLib 1.0 and later
  464. * Mac OS X: in version 10.0 and later
  465. */
  466. EXTERN_API( OSErr )
  467. AVLGetIndItem(
  468. AVLTreePtr tree,
  469. UInt32 index,
  470. void * dataPtr,
  471. UInt32 * itemSize) THREEWORDINLINE(0x303C, 0x0805, 0xAA80);
  472. /*
  473. Insert the given item into the tree. This will call the tree's sizeItemProc
  474. to determine how big the item at data is, and then will make a copy of the
  475. item and insert it into the tree in the appropriate place. If an item already
  476. exists in the tree with the same key ( so that the compareItemsUPP returns 0
  477. when asked to compare this item to an existing one ), then it will return
  478. errItemNotFoundInTree.
  479. */
  480. /*
  481. * AVLInsert()
  482. *
  483. * Availability:
  484. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  485. * CarbonLib: in CarbonLib 1.0 and later
  486. * Mac OS X: in version 10.0 and later
  487. */
  488. EXTERN_API( OSErr )
  489. AVLInsert(
  490. AVLTreePtr tree,
  491. const void * data) THREEWORDINLINE(0x303C, 0x0406, 0xAA80);
  492. /*
  493. Remove any item from the tree with the given key. If dataPtr != nil, then
  494. copy the item's data to dataPtr before removing it from the tree. Before
  495. removing the item, call the tree's disposeItemProc to let it release anything
  496. used by the data in the tree. It is not necessary to fill in a complete
  497. record for key, only that the compareItemsProc return 0 when asked to compare
  498. the data at key with the node in the tree to be deleted. If the item cannot
  499. be found in the tree, this will return errItemNotFoundInTree.
  500. */
  501. /*
  502. * AVLRemove()
  503. *
  504. * Availability:
  505. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  506. * CarbonLib: in CarbonLib 1.0 and later
  507. * Mac OS X: in version 10.0 and later
  508. */
  509. EXTERN_API( OSErr )
  510. AVLRemove(
  511. AVLTreePtr tree,
  512. const void * key,
  513. void * dataPtr,
  514. UInt32 * itemSize) THREEWORDINLINE(0x303C, 0x0807, 0xAA80);
  515. /*
  516. Find the item in the tree with the given key, and return it's data in
  517. dataPtr ( if dataPtr != nil ), and it's size in *itemSize ( if itemSize
  518. != nil ). It is not necessary to fill in a complete record for key,
  519. only that the compareItemsProc return 0 when asked to compare the data
  520. at key with the node in the tree to be deleted. If the item cannot
  521. be found in the tree, this will return errItemNotFoundInTree.
  522. */
  523. /*
  524. * AVLFind()
  525. *
  526. * Availability:
  527. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  528. * CarbonLib: in CarbonLib 1.0 and later
  529. * Mac OS X: in version 10.0 and later
  530. */
  531. EXTERN_API( OSErr )
  532. AVLFind(
  533. AVLTreePtr tree,
  534. const void * key,
  535. void * dataPtr,
  536. UInt32 * itemSize) THREEWORDINLINE(0x303C, 0x0808, 0xAA80);
  537. /*
  538. Get the refCon for the given tree ( set in AVLInit ) and return it.
  539. If the given tree is invalid, then return nil.
  540. */
  541. /*
  542. * AVLGetRefcon()
  543. *
  544. * Availability:
  545. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  546. * CarbonLib: in CarbonLib 1.0 and later
  547. * Mac OS X: in version 10.0 and later
  548. */
  549. EXTERN_API( OSErr )
  550. AVLGetRefcon(
  551. AVLTreePtr tree,
  552. void ** refCon) THREEWORDINLINE(0x303C, 0x0409, 0xAA80);
  553. #if PRAGMA_STRUCT_ALIGN
  554. #pragma options align=reset
  555. #elif PRAGMA_STRUCT_PACKPUSH
  556. #pragma pack(pop)
  557. #elif PRAGMA_STRUCT_PACK
  558. #pragma pack()
  559. #endif
  560. #ifdef PRAGMA_IMPORT_OFF
  561. #pragma import off
  562. #elif PRAGMA_IMPORT
  563. #pragma import reset
  564. #endif
  565. #ifdef __cplusplus
  566. }
  567. #endif
  568. #endif /* __AVLTREE__ */