AVLTree.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. {
  2. File: CarbonCore/AVLTree.h
  3. Contains: Interfaces for AVL balanced trees.
  4. The contents of this header file are deprecated.
  5. Copyright: © 1999-2011 by Apple Inc. All rights reserved.
  6. }
  7. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  8. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, September 2012 }
  9. {
  10. Modified for use with Free Pascal
  11. Version 308
  12. Please report any bugs to <[email protected]>
  13. }
  14. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  15. {$mode macpas}
  16. {$packenum 1}
  17. {$macro on}
  18. {$inline on}
  19. {$calling mwpascal}
  20. unit AVLTree;
  21. interface
  22. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  23. {$setc GAP_INTERFACES_VERSION := $0308}
  24. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  25. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  26. {$endc}
  27. {$ifc defined CPUPOWERPC and defined CPUI386}
  28. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  29. {$endc}
  30. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  31. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  32. {$endc}
  33. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  34. {$setc __ppc__ := 1}
  35. {$elsec}
  36. {$setc __ppc__ := 0}
  37. {$endc}
  38. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  39. {$setc __ppc64__ := 1}
  40. {$elsec}
  41. {$setc __ppc64__ := 0}
  42. {$endc}
  43. {$ifc not defined __i386__ and defined CPUI386}
  44. {$setc __i386__ := 1}
  45. {$elsec}
  46. {$setc __i386__ := 0}
  47. {$endc}
  48. {$ifc not defined __x86_64__ and defined CPUX86_64}
  49. {$setc __x86_64__ := 1}
  50. {$elsec}
  51. {$setc __x86_64__ := 0}
  52. {$endc}
  53. {$ifc not defined __arm__ and defined CPUARM}
  54. {$setc __arm__ := 1}
  55. {$elsec}
  56. {$setc __arm__ := 0}
  57. {$endc}
  58. {$ifc defined cpu64}
  59. {$setc __LP64__ := 1}
  60. {$elsec}
  61. {$setc __LP64__ := 0}
  62. {$endc}
  63. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  64. {$error Conflicting definitions for __ppc__ and __i386__}
  65. {$endc}
  66. {$ifc defined __ppc__ and __ppc__}
  67. {$setc TARGET_CPU_PPC := TRUE}
  68. {$setc TARGET_CPU_PPC64 := FALSE}
  69. {$setc TARGET_CPU_X86 := FALSE}
  70. {$setc TARGET_CPU_X86_64 := FALSE}
  71. {$setc TARGET_CPU_ARM := FALSE}
  72. {$setc TARGET_OS_MAC := TRUE}
  73. {$setc TARGET_OS_IPHONE := FALSE}
  74. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  75. {$setc TARGET_OS_EMBEDDED := FALSE}
  76. {$elifc defined __ppc64__ and __ppc64__}
  77. {$setc TARGET_CPU_PPC := FALSE}
  78. {$setc TARGET_CPU_PPC64 := TRUE}
  79. {$setc TARGET_CPU_X86 := FALSE}
  80. {$setc TARGET_CPU_X86_64 := FALSE}
  81. {$setc TARGET_CPU_ARM := FALSE}
  82. {$setc TARGET_OS_MAC := TRUE}
  83. {$setc TARGET_OS_IPHONE := FALSE}
  84. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  85. {$setc TARGET_OS_EMBEDDED := FALSE}
  86. {$elifc defined __i386__ and __i386__}
  87. {$setc TARGET_CPU_PPC := FALSE}
  88. {$setc TARGET_CPU_PPC64 := FALSE}
  89. {$setc TARGET_CPU_X86 := TRUE}
  90. {$setc TARGET_CPU_X86_64 := FALSE}
  91. {$setc TARGET_CPU_ARM := FALSE}
  92. {$ifc defined(iphonesim)}
  93. {$setc TARGET_OS_MAC := FALSE}
  94. {$setc TARGET_OS_IPHONE := TRUE}
  95. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  96. {$elsec}
  97. {$setc TARGET_OS_MAC := TRUE}
  98. {$setc TARGET_OS_IPHONE := FALSE}
  99. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  100. {$endc}
  101. {$setc TARGET_OS_EMBEDDED := FALSE}
  102. {$elifc defined __x86_64__ and __x86_64__}
  103. {$setc TARGET_CPU_PPC := FALSE}
  104. {$setc TARGET_CPU_PPC64 := FALSE}
  105. {$setc TARGET_CPU_X86 := FALSE}
  106. {$setc TARGET_CPU_X86_64 := TRUE}
  107. {$setc TARGET_CPU_ARM := FALSE}
  108. {$setc TARGET_OS_MAC := TRUE}
  109. {$setc TARGET_OS_IPHONE := FALSE}
  110. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  111. {$setc TARGET_OS_EMBEDDED := FALSE}
  112. {$elifc defined __arm__ and __arm__}
  113. {$setc TARGET_CPU_PPC := FALSE}
  114. {$setc TARGET_CPU_PPC64 := FALSE}
  115. {$setc TARGET_CPU_X86 := FALSE}
  116. {$setc TARGET_CPU_X86_64 := FALSE}
  117. {$setc TARGET_CPU_ARM := TRUE}
  118. { will require compiler define when/if other Apple devices with ARM cpus ship }
  119. {$setc TARGET_OS_MAC := FALSE}
  120. {$setc TARGET_OS_IPHONE := TRUE}
  121. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  122. {$setc TARGET_OS_EMBEDDED := TRUE}
  123. {$elsec}
  124. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.}
  125. {$endc}
  126. {$ifc defined __LP64__ and __LP64__ }
  127. {$setc TARGET_CPU_64 := TRUE}
  128. {$elsec}
  129. {$setc TARGET_CPU_64 := FALSE}
  130. {$endc}
  131. {$ifc defined FPC_BIG_ENDIAN}
  132. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  133. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  134. {$elifc defined FPC_LITTLE_ENDIAN}
  135. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  136. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  137. {$elsec}
  138. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  139. {$endc}
  140. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  141. {$setc CALL_NOT_IN_CARBON := FALSE}
  142. {$setc OLDROUTINENAMES := FALSE}
  143. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  144. {$setc OPAQUE_UPP_TYPES := TRUE}
  145. {$setc OTCARBONAPPLICATION := TRUE}
  146. {$setc OTKERNEL := FALSE}
  147. {$setc PM_USE_SESSION_APIS := TRUE}
  148. {$setc TARGET_API_MAC_CARBON := TRUE}
  149. {$setc TARGET_API_MAC_OS8 := FALSE}
  150. {$setc TARGET_API_MAC_OSX := TRUE}
  151. {$setc TARGET_CARBON := TRUE}
  152. {$setc TARGET_CPU_68K := FALSE}
  153. {$setc TARGET_CPU_MIPS := FALSE}
  154. {$setc TARGET_CPU_SPARC := FALSE}
  155. {$setc TARGET_OS_UNIX := FALSE}
  156. {$setc TARGET_OS_WIN32 := FALSE}
  157. {$setc TARGET_RT_MAC_68881 := FALSE}
  158. {$setc TARGET_RT_MAC_CFM := FALSE}
  159. {$setc TARGET_RT_MAC_MACHO := TRUE}
  160. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  161. {$setc TYPE_BOOL := FALSE}
  162. {$setc TYPE_EXTENDED := FALSE}
  163. {$setc TYPE_LONGLONG := TRUE}
  164. uses MacTypes;
  165. {$endc} {not MACOSALLINCLUDE}
  166. {$ifc TARGET_OS_MAC}
  167. {$ALIGN MAC68K}
  168. {
  169. * AVLVisitStage
  170. *
  171. * Discussion:
  172. * The visit stage for AVLWalk() walkProcs
  173. }
  174. type
  175. AVLVisitStage = UInt16;
  176. const
  177. {
  178. * Passed the first time AVLWalk iterates thru a given node.
  179. }
  180. kAVLPreOrder = 0;
  181. {
  182. * Passed the AVLWalk iterates thru a given node when it is 'in
  183. * order'.
  184. }
  185. kAVLInOrder = 1;
  186. {
  187. * Passed the last time AVLWalk iterates thru a given node.
  188. }
  189. kAVLPostOrder = 2;
  190. {
  191. * AVLOrder
  192. *
  193. * Discussion:
  194. * The order the tree is walked or disposed of.
  195. }
  196. type
  197. AVLOrder = UInt16;
  198. const
  199. {
  200. * Walk the tree in left-to-right order ( smaller to bigger, usually )
  201. }
  202. kLeftToRight = 0;
  203. {
  204. * Walk the tree in right-to-left order ( bigger to smaller, usually )
  205. }
  206. kRightToLeft = 1;
  207. {
  208. * AVLNodeType
  209. *
  210. * Discussion:
  211. * The type of the node being passed to a callback proc.
  212. }
  213. type
  214. AVLNodeType = UInt16;
  215. const
  216. kAVLIsTree = 0;
  217. kAVLIsLeftBranch = 1;
  218. kAVLIsRightBranch = 2;
  219. kAVLIsLeaf = 3;
  220. kAVLNullNode = 4;
  221. const
  222. errItemAlreadyInTree = -960;
  223. errNotValidTree = -961;
  224. errItemNotFoundInTree = -962;
  225. errCanNotInsertWhileWalkProcInProgress = -963;
  226. errTreeIsLocked = -964;
  227. {
  228. * AVLTreeStruct
  229. *
  230. * Summary:
  231. * An opaque structure for a balanced binary tree.
  232. *
  233. * Discussion:
  234. * The structure of a tree. It's opaque; don't assume it's 36 bytes
  235. * in size.
  236. }
  237. type
  238. AVLTreeStructPtr = ^AVLTreeStruct;
  239. AVLTreeStruct = record
  240. signature: OSType;
  241. privateStuff: array [0..7] of UNSIGNEDLONG;
  242. end;
  243. type
  244. AVLTreePtr = AVLTreeStructPtr;
  245. {
  246. * AVLCompareItemsProcPtr
  247. *
  248. * Summary:
  249. * A callback function which compares two data items and returns
  250. * their ordering.
  251. *
  252. * Discussion:
  253. * Every tree must have a function which compares the data for two
  254. * items and returns < 0, 0, or >0 for the items - < 0 if the first
  255. * item is 'before' the second item according to some criteria, == 0
  256. * if the two items are identical according to the criteria, or > 0
  257. * if the first item is 'after' the second item according to the
  258. * criteria. The comparison function is also passed the node type,
  259. * but most of the time this can be ignored.
  260. *
  261. * Parameters:
  262. *
  263. * tree:
  264. * The tree which contains the items being compared
  265. *
  266. * i1:
  267. * A pointer to the first item
  268. *
  269. * i2:
  270. * A pointer to the second item
  271. *
  272. * nd_typ:
  273. * The type of the nodes being compared. This is not terribly
  274. * useful most of the time.
  275. *
  276. * Result:
  277. * A value < 0 if i1 is 'before' i2, > 0 if i1 is 'after' i2, or ==
  278. * 0 if i1 is equal to i2.
  279. }
  280. type
  281. AVLCompareItemsProcPtr = function( tree: AVLTreePtr; i1: {const} UnivPtr; i2: {const} UnivPtr; nd_typ: AVLNodeType ): SInt32;
  282. {
  283. * AVLItemSizeProcPtr
  284. *
  285. * Summary:
  286. * A callback function which returns the size of an item.
  287. *
  288. * Discussion:
  289. * Every tree must have a itemSizeProc; this routine gets passed a
  290. * pointer to the item's data and returns the size of the data. If
  291. * a tree contains records of a fixed size, this function can just
  292. * return sizeof( that-struct ); otherwise it should calculate the
  293. * size of the item based on the data for the item.
  294. *
  295. * Parameters:
  296. *
  297. * tree:
  298. * The tree which contains the item whose size is being requested.
  299. *
  300. * itemPtr:
  301. * A pointer to the item whose size is being returned.
  302. *
  303. * Result:
  304. * The size of the item.
  305. }
  306. type
  307. AVLItemSizeProcPtr = function( tree: AVLTreePtr; itemPtr: {const} UnivPtr ): ByteCount;
  308. {
  309. * AVLDisposeItemProcPtr
  310. *
  311. * Summary:
  312. * Dispose of any additional memory associated with an item in the
  313. * tree.
  314. *
  315. * Discussion:
  316. * A tree may have an optional disposeItemProc, which gets called
  317. * whenever an item is removed from the tree ( via AVLRemove() or
  318. * when AVLDispose() deletes all of the items in the tree ). This
  319. * might be useful if the nodes in the tree own 'resources' ( like,
  320. * open files ) which should be released before the item is removed.
  321. *
  322. * Parameters:
  323. *
  324. * tree:
  325. * The tree containing the item being disposed.
  326. *
  327. * dataP:
  328. * A pointer to the data for the item being disposed.
  329. }
  330. type
  331. AVLDisposeItemProcPtr = procedure( tree: AVLTreePtr; dataP: {const} UnivPtr );
  332. {
  333. * AVLWalkProcPtr
  334. *
  335. * Summary:
  336. * A callback function which gets passed each item in the tree, in a
  337. * specified order.
  338. *
  339. * Discussion:
  340. * The common way to iterate across all of the items in a tree is
  341. * via AVLWalk(), which takes a walkProcPtr. This function will get
  342. * called for every item in the tree three times, as the tree is
  343. * being walked across. First, the walkProc will get called with
  344. * visitStage == kAVLPreOrder, at which point internally the node of
  345. * the tree for the given data has just been reached. Later, this
  346. * function will get called with visitStage == kAVLInOrder, and
  347. * lastly this function will get called with visitStage ==
  348. * kAVLPostOrder. The 'minimum' item in the tree will get called
  349. * with visitStage == kInOrder first, followed by the 'next' item in
  350. * the tree, up until the last item in the tree structure is called.
  351. * In general, you'll only care about calls to this function when
  352. * visitStage == kAVLInOrder.
  353. *
  354. * Parameters:
  355. *
  356. * tree:
  357. * The tree being walked.
  358. *
  359. * dataPtr:
  360. * A pointer to the data for an item in the tree.
  361. *
  362. * visitStage:
  363. * The stage of the walk for the given node.
  364. *
  365. * node:
  366. * The type of the given node. This is not terribly useful most of
  367. * the time.
  368. *
  369. * level:
  370. * How 'deep' in the tree the given node is. This is not terribly
  371. * useful most of the time.
  372. *
  373. * balance:
  374. * How balanced the given node in the tree is. This is not
  375. * terribly useful most of the time.
  376. *
  377. * refCon:
  378. * The refCon passed into AVLWalk() for this call.
  379. *
  380. * Result:
  381. * Return 0 to continue walking the tree, or 1 to terminate.
  382. }
  383. type
  384. AVLWalkProcPtr = function( tree: AVLTreePtr; dataPtr: {const} UnivPtr; visitStage: AVLVisitStage; node: AVLNodeType; level: UInt32; balance: SInt32; refCon: UnivPtr ): OSErr;
  385. AVLCompareItemsUPP = AVLCompareItemsProcPtr;
  386. AVLItemSizeUPP = AVLItemSizeProcPtr;
  387. AVLDisposeItemUPP = AVLDisposeItemProcPtr;
  388. AVLWalkUPP = AVLWalkProcPtr;
  389. {
  390. * NewAVLCompareItemsUPP()
  391. *
  392. * Availability:
  393. * Mac OS X: in version 10.0 and later in CoreServices.framework
  394. * CarbonLib: in CarbonLib 1.0 and later
  395. * Non-Carbon CFM: available as macro/inline
  396. }
  397. function NewAVLCompareItemsUPP( userRoutine: AVLCompareItemsProcPtr ): AVLCompareItemsUPP; external name '_NewAVLCompareItemsUPP';
  398. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  399. {
  400. * NewAVLItemSizeUPP()
  401. *
  402. * Availability:
  403. * Mac OS X: in version 10.0 and later in CoreServices.framework
  404. * CarbonLib: in CarbonLib 1.0 and later
  405. * Non-Carbon CFM: available as macro/inline
  406. }
  407. function NewAVLItemSizeUPP( userRoutine: AVLItemSizeProcPtr ): AVLItemSizeUPP; external name '_NewAVLItemSizeUPP';
  408. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  409. {
  410. * NewAVLDisposeItemUPP()
  411. *
  412. * Availability:
  413. * Mac OS X: in version 10.0 and later in CoreServices.framework
  414. * CarbonLib: in CarbonLib 1.0 and later
  415. * Non-Carbon CFM: available as macro/inline
  416. }
  417. function NewAVLDisposeItemUPP( userRoutine: AVLDisposeItemProcPtr ): AVLDisposeItemUPP; external name '_NewAVLDisposeItemUPP';
  418. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  419. {
  420. * NewAVLWalkUPP()
  421. *
  422. * Availability:
  423. * Mac OS X: in version 10.0 and later in CoreServices.framework
  424. * CarbonLib: in CarbonLib 1.0 and later
  425. * Non-Carbon CFM: available as macro/inline
  426. }
  427. function NewAVLWalkUPP( userRoutine: AVLWalkProcPtr ): AVLWalkUPP; external name '_NewAVLWalkUPP';
  428. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  429. {
  430. * DisposeAVLCompareItemsUPP()
  431. *
  432. * Availability:
  433. * Mac OS X: in version 10.0 and later in CoreServices.framework
  434. * CarbonLib: in CarbonLib 1.0 and later
  435. * Non-Carbon CFM: available as macro/inline
  436. }
  437. procedure DisposeAVLCompareItemsUPP( userUPP: AVLCompareItemsUPP ); external name '_DisposeAVLCompareItemsUPP';
  438. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  439. {
  440. * DisposeAVLItemSizeUPP()
  441. *
  442. * Availability:
  443. * Mac OS X: in version 10.0 and later in CoreServices.framework
  444. * CarbonLib: in CarbonLib 1.0 and later
  445. * Non-Carbon CFM: available as macro/inline
  446. }
  447. procedure DisposeAVLItemSizeUPP( userUPP: AVLItemSizeUPP ); external name '_DisposeAVLItemSizeUPP';
  448. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  449. {
  450. * DisposeAVLDisposeItemUPP()
  451. *
  452. * Availability:
  453. * Mac OS X: in version 10.0 and later in CoreServices.framework
  454. * CarbonLib: in CarbonLib 1.0 and later
  455. * Non-Carbon CFM: available as macro/inline
  456. }
  457. procedure DisposeAVLDisposeItemUPP( userUPP: AVLDisposeItemUPP ); external name '_DisposeAVLDisposeItemUPP';
  458. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  459. {
  460. * DisposeAVLWalkUPP()
  461. *
  462. * Availability:
  463. * Mac OS X: in version 10.0 and later in CoreServices.framework
  464. * CarbonLib: in CarbonLib 1.0 and later
  465. * Non-Carbon CFM: available as macro/inline
  466. }
  467. procedure DisposeAVLWalkUPP( userUPP: AVLWalkUPP ); external name '_DisposeAVLWalkUPP';
  468. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  469. {
  470. * InvokeAVLCompareItemsUPP()
  471. *
  472. * Availability:
  473. * Mac OS X: in version 10.0 and later in CoreServices.framework
  474. * CarbonLib: in CarbonLib 1.0 and later
  475. * Non-Carbon CFM: available as macro/inline
  476. }
  477. function InvokeAVLCompareItemsUPP( tree: AVLTreePtr; i1: {const} UnivPtr; i2: {const} UnivPtr; nd_typ: AVLNodeType; userUPP: AVLCompareItemsUPP ): SInt32; external name '_InvokeAVLCompareItemsUPP';
  478. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  479. {
  480. * InvokeAVLItemSizeUPP()
  481. *
  482. * Availability:
  483. * Mac OS X: in version 10.0 and later in CoreServices.framework
  484. * CarbonLib: in CarbonLib 1.0 and later
  485. * Non-Carbon CFM: available as macro/inline
  486. }
  487. function InvokeAVLItemSizeUPP( tree: AVLTreePtr; itemPtr: {const} UnivPtr; userUPP: AVLItemSizeUPP ): ByteCount; external name '_InvokeAVLItemSizeUPP';
  488. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  489. {
  490. * InvokeAVLDisposeItemUPP()
  491. *
  492. * Availability:
  493. * Mac OS X: in version 10.0 and later in CoreServices.framework
  494. * CarbonLib: in CarbonLib 1.0 and later
  495. * Non-Carbon CFM: available as macro/inline
  496. }
  497. procedure InvokeAVLDisposeItemUPP( tree: AVLTreePtr; dataP: {const} UnivPtr; userUPP: AVLDisposeItemUPP ); external name '_InvokeAVLDisposeItemUPP';
  498. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  499. {
  500. * InvokeAVLWalkUPP()
  501. *
  502. * Availability:
  503. * Mac OS X: in version 10.0 and later in CoreServices.framework
  504. * CarbonLib: in CarbonLib 1.0 and later
  505. * Non-Carbon CFM: available as macro/inline
  506. }
  507. function InvokeAVLWalkUPP( tree: AVLTreePtr; dataPtr: {const} UnivPtr; visitStage: AVLVisitStage; node: AVLNodeType; level: UInt32; balance: SInt32; refCon: UnivPtr; userUPP: AVLWalkUPP ): OSErr; external name '_InvokeAVLWalkUPP';
  508. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  509. {$ifc not TARGET_CPU_64}
  510. {
  511. * AVLInit() *** DEPRECATED ***
  512. *
  513. * Summary:
  514. * Create an AVL ( balanced binary ) tree
  515. *
  516. * Discussion:
  517. * Create an AVL tree. The compareItemsProc and the sizeItemProc
  518. * are required; disposeItemProc is optional and can be nil. The
  519. * refCon is stored with the list, and is passed back to the
  520. * compareItemsProc, sizeItemProc, and disposeItemsProc calls. The
  521. * allocation of the tree ( and all nodes later added to the list
  522. * with AVLInsert ) will be created in what is the current zone at
  523. * the time AVLInit() is called. Always call AVLDispose() to
  524. * dispose of a list created with AVLInit().
  525. *
  526. * Mac OS X threading:
  527. * Thread safe
  528. *
  529. * Parameters:
  530. *
  531. * flags:
  532. * Creation flags. Currently, no flags are defined, so pass 0.
  533. *
  534. * compareItemsProc:
  535. * A UPP for a function which compares two data items, and returns
  536. * a value which is < 0, == 0, or > 0 depending on whether the
  537. * first item is 'before', 'equal', or 'after' the first item.
  538. *
  539. * sizeItemProc:
  540. * A UPP for a function which takes a pointer to a data item, and
  541. * returns the size in bytes which it requires to store.
  542. *
  543. * disposeItemProc:
  544. * A UPP for a function which takes a pointer to a data item, and
  545. * disposes of any memory which may have been allocated for the
  546. * item. This does not need to dispose of the item itself ( the
  547. * AVLTree Manager will do that ), only any memory which the item
  548. * passed in may be pointing to. This function may be NULL if
  549. * data items do not use any memory besides that taken up by the
  550. * item itself.
  551. *
  552. * refCon:
  553. * A 32 bit quantity which is stored with this tree, and can be
  554. * retrieved at an time ( and in a callback, if desired ) with
  555. * AVLGetRefcon().
  556. *
  557. * tree:
  558. * The created AVLTree, or NULL if there is an error.
  559. *
  560. * Availability:
  561. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  562. * CarbonLib: in CarbonLib 1.0 and later
  563. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  564. }
  565. function AVLInit( flags: UInt32; compareItemsProc: AVLCompareItemsUPP; sizeItemProc: AVLItemSizeUPP; disposeItemProc: AVLDisposeItemUPP; refCon: UnivPtr; var tree: AVLTreePtr ): OSErr; external name '_AVLInit';
  566. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  567. {
  568. * AVLDispose() *** DEPRECATED ***
  569. *
  570. * Summary:
  571. * Dispose of an AVL tree created with AVLInit()
  572. *
  573. * Discussion:
  574. * Dispose of an AVL tree. This will dispose of each item in the
  575. * tree in the order specified, call the tree's disposeProc proc for
  576. * each item, and then dispose of the space allocated for the tree
  577. * itself.
  578. *
  579. * Mac OS X threading:
  580. * Thread safe
  581. * AVLDispose is thread safe provided no other thread is still using
  582. * the tree being dispose.
  583. *
  584. * Parameters:
  585. *
  586. * tree:
  587. * The tree to dispose, which was created with AVLInit().
  588. *
  589. * order:
  590. * The order to dispose of the items in the tree.
  591. *
  592. * Availability:
  593. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  594. * CarbonLib: in CarbonLib 1.0 and later
  595. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  596. }
  597. function AVLDispose( var tree: AVLTreePtr; order: AVLOrder ): OSErr; external name '_AVLDispose';
  598. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  599. {
  600. * AVLWalk() *** DEPRECATED ***
  601. *
  602. * Summary:
  603. * Iterate across all of the items in an AVL tree, in a specified
  604. * order.
  605. *
  606. * Discussion:
  607. * Iterate across all of the items in the tree, in the order
  608. * specified. kLeftToRight is basically lowest-to-highest order,
  609. * kRightToLeft is highest-to-lowest order. For each node in the
  610. * tree, it will call the walkProc with three messages ( at the
  611. * appropriate time ). First, with kAVLPreOrder when the walking
  612. * gets to this node in the tree, before handling either the left or
  613. * right subtree, secondly, with kAVLInOrder after handling one
  614. * subtree but before handling the other, and lastly with
  615. * kAVLPostOrder after handling both subtrees. If you want to
  616. * handle items in order, then only do something if the visit stage
  617. * is kAVLInOrder. You can only call AVLRemove() from inside a
  618. * walkProc if visit stage is kAVLPostOrder ( because if you remove
  619. * a node during the pre or in order stages you will corrupt the
  620. * list ) OR if you return a non-zero result from the walkProc call
  621. * which called AVLRemove() to immediately terminate the walkProc.
  622. * Do not call AVLInsert() to insert a node into the tree from
  623. * inside a walkProc. The walkProc function gets called with the
  624. * AVLTreePtr, a pointer to the data for the current node ( which
  625. * you can change in place as long as you do not affect the order
  626. * within the tree ), the visit stage, the type of the current node
  627. * ( leaf node, right or left branch, or full tree ), the level
  628. * within the tree ( the root is level 1 ), the balance for the
  629. * current node, and the refCon passed to AVLWalk(). This refCon is
  630. * different from the one passed into AVLInit(); use AVLGetRefCon()
  631. * to get that refCon if you want it inside a walkProc. ( Most
  632. * walkProcs will not care about the values for node type, level, or
  633. * balance. )
  634. *
  635. * Mac OS X threading:
  636. * Thread safe
  637. * AVLWalk is thread safe as long as no other thread tries to modify
  638. * the tree by inserting or removing an item, or disposing of the
  639. * tree itself.
  640. *
  641. * Parameters:
  642. *
  643. * tree:
  644. * The tree to dispose, which was created with AVLInit().
  645. *
  646. * walkProc:
  647. * A UPP for a function which is called during the walk thru the
  648. * tree for each item.
  649. *
  650. * order:
  651. * The order to iterate thru the tree.
  652. *
  653. * walkRefCon:
  654. * A 32 bit value passed to the walkProc each time it is called.
  655. *
  656. * Availability:
  657. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  658. * CarbonLib: in CarbonLib 1.0 and later
  659. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  660. }
  661. function AVLWalk( tree: AVLTreePtr; walkProc: AVLWalkUPP; order: AVLOrder; walkRefCon: UnivPtr ): OSErr; external name '_AVLWalk';
  662. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  663. {
  664. * AVLCount() *** DEPRECATED ***
  665. *
  666. * Summary:
  667. * Return the number of items in the given tree.
  668. *
  669. * Discussion:
  670. * Return the number of items in the given tree.
  671. *
  672. * Mac OS X threading:
  673. * Thread safe
  674. * AVLCount is thread safe as long as no other thread tries to
  675. * modify the tree by inserting or removing an item, or disposing of
  676. * the tree itself.
  677. *
  678. * Parameters:
  679. *
  680. * tree:
  681. * The tree to return the count of items for.
  682. *
  683. * count:
  684. * On return, the count of items ( 1-based ) in the tree.
  685. *
  686. * Availability:
  687. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  688. * CarbonLib: in CarbonLib 1.0 and later
  689. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  690. }
  691. function AVLCount( tree: AVLTreePtr; var count: UInt32 ): OSErr; external name '_AVLCount';
  692. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  693. {
  694. * AVLGetIndItem() *** DEPRECATED ***
  695. *
  696. * Summary:
  697. * Return the data of the index-th item from the tree.
  698. *
  699. * Discussion:
  700. * Return the one-based index-th item from the tree by putting it's
  701. * data at dataPtr if dataPtr is non-nil, and it's size into
  702. * *itemSize if itemSize is non-nil. If index is out of range,
  703. * return errItemNotFoundInTree. ( Internally, this does an
  704. * AVLWalk(), so the tree can not be modified while this call is in
  705. * progress ).
  706. *
  707. * Mac OS X threading:
  708. * Thread safe
  709. * AVLGetIndItem is thread safe as long as no other thread tries to
  710. * modify the tree by inserting or removing an item, or disposing of
  711. * the tree itself.
  712. *
  713. * Parameters:
  714. *
  715. * tree:
  716. * The tree to return the index-th items for.
  717. *
  718. * index:
  719. * A index of the item to return. The 'first' item in the tree is
  720. * index = 1, the last item is index = the count of items in the
  721. * tree.
  722. *
  723. * dataPtr:
  724. * An address in memory to return the data for the item, or NULL
  725. * if you don not want data returned. The memory point to must be
  726. * large enough to hold all of the data for the item.
  727. *
  728. * itemSize:
  729. * On return, the size of the data for the index-th item. If you
  730. * do not care about the size of the data, pass NULL.
  731. *
  732. * Availability:
  733. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  734. * CarbonLib: in CarbonLib 1.0 and later
  735. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  736. }
  737. function AVLGetIndItem( tree: AVLTreePtr; index: UInt32; dataPtr: UnivPtr; var itemSize: ByteCount ): OSErr; external name '_AVLGetIndItem';
  738. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  739. {
  740. * AVLInsert() *** DEPRECATED ***
  741. *
  742. * Summary:
  743. * Insert an item into the tree.
  744. *
  745. * Discussion:
  746. * Insert the given item into the tree. This will call the tree's
  747. * sizeItemProc to determine how big the item at data is, and then
  748. * will make a copy of the item and insert it into the tree in the
  749. * appropriate place. If an item already exists in the tree with
  750. * the same key ( so that the compareItemsUPP returns 0 when asked
  751. * to compare this item to an existing one ), then it will return
  752. * errItemNotFoundInTree.
  753. *
  754. * Mac OS X threading:
  755. * Thread safe
  756. * AVLInsert is thread safe as long as no other thread tries to walk
  757. * or modify the tree by inserting or removing an item, or disposing
  758. * of the tree itself.
  759. *
  760. * Parameters:
  761. *
  762. * tree:
  763. * The tree to return the index-th items for.
  764. *
  765. * data:
  766. * A pointer to the item to be inserted.
  767. *
  768. * Availability:
  769. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  770. * CarbonLib: in CarbonLib 1.0 and later
  771. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  772. }
  773. function AVLInsert( tree: AVLTreePtr; data: {const} UnivPtr ): OSErr; external name '_AVLInsert';
  774. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  775. {
  776. * AVLRemove() *** DEPRECATED ***
  777. *
  778. * Summary:
  779. * Remove an item from the tree.
  780. *
  781. * Discussion:
  782. * Remove any item from the tree with the given key. If dataPtr !=
  783. * nil, then copy the item's data to dataPtr before removing it from
  784. * the tree. Before removing the item, call the tree's
  785. * disposeItemProc to let it release anything used by the data in
  786. * the tree. It is not necessary to fill in a complete record for
  787. * key, only that the compareItemsProc return 0 when asked to
  788. * compare the data at key with the node in the tree to be deleted.
  789. * If the item cannot be found in the tree, this will return
  790. * errItemNotFoundInTree.
  791. *
  792. * Mac OS X threading:
  793. * Thread safe
  794. * AVLRemove is thread safe as long as no other thread tries to walk
  795. * or modify the tree by inserting or removing an item, or disposing
  796. * of the tree itself.
  797. *
  798. * Parameters:
  799. *
  800. * tree:
  801. * The tree to return the index-th items for.
  802. *
  803. * key:
  804. * A pointer to the item to be removed ( or, enough of the item
  805. * that it can be found in the tree ).
  806. *
  807. * dataPtr:
  808. * An address in memory to return the data for the item, or NULL
  809. * if you don not want data returned. The memory point to must be
  810. * large enough to hold all of the data for the item.
  811. *
  812. * itemSize:
  813. * On return, the size of the data for the index-th item. If you
  814. * do not care about the size of the data, pass NULL.
  815. *
  816. * Availability:
  817. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  818. * CarbonLib: in CarbonLib 1.0 and later
  819. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  820. }
  821. function AVLRemove( tree: AVLTreePtr; key: {const} UnivPtr; dataPtr: UnivPtr; var itemSize: ByteCount ): OSErr; external name '_AVLRemove';
  822. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  823. {
  824. * AVLFind() *** DEPRECATED ***
  825. *
  826. * Summary:
  827. * Remove an item from the tree.
  828. *
  829. * Discussion:
  830. * Find the item in the tree with the given key, and return it's
  831. * data in dataPtr ( if dataPtr != nil ), and it's size in *itemSize
  832. * ( if itemSize != nil ). It is not necessary to fill in a
  833. * complete record for key, only that the compareItemsProc return 0
  834. * when asked to compare the data at key with the node in the tree
  835. * to be deleted. If the item cannot be found in the tree, this
  836. * will return errItemNotFoundInTree.
  837. *
  838. * Mac OS X threading:
  839. * Thread safe
  840. * AVLRemove is thread safe as long as no other thread tries to walk
  841. * or modify the tree by inserting or removing an item, or disposing
  842. * of the tree itself.
  843. *
  844. * Parameters:
  845. *
  846. * tree:
  847. * The tree to return the index-th items for.
  848. *
  849. * key:
  850. * A pointer to the item to be found ( or, enough of the item that
  851. * it can be found in the tree ).
  852. *
  853. * dataPtr:
  854. * An address in memory to return the data for the item, or NULL
  855. * if you don not want data returned. The memory point to must be
  856. * large enough to hold all of the data for the item.
  857. *
  858. * itemSize:
  859. * On return, the size of the data for the index-th item. If you
  860. * do not care about the size of the data, pass NULL.
  861. *
  862. * Availability:
  863. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  864. * CarbonLib: in CarbonLib 1.0 and later
  865. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  866. }
  867. function AVLFind( tree: AVLTreePtr; key: {const} UnivPtr; dataPtr: UnivPtr; var itemSize: ByteCount ): OSErr; external name '_AVLFind';
  868. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  869. {
  870. * AVLGetRefcon() *** DEPRECATED ***
  871. *
  872. * Summary:
  873. * Return the refCon set when the tree was created.
  874. *
  875. * Discussion:
  876. * Get the refCon for the given tree ( set in AVLInit ) and return
  877. * it.
  878. *
  879. * Mac OS X threading:
  880. * Thread safe
  881. * AVLGetRefcon is thread safe as long as no other thread tries to
  882. * dispose of the tree itself.
  883. *
  884. * Parameters:
  885. *
  886. * tree:
  887. * The tree to return the refcon for.
  888. *
  889. * refCon:
  890. * On return, the refCon for the tree, or NULL if tree is invalid.
  891. *
  892. * Availability:
  893. * Mac OS X: in version 10.0 and later in CoreServices.framework [32-bit only] but deprecated in 10.5
  894. * CarbonLib: in CarbonLib 1.0 and later
  895. * Non-Carbon CFM: in InterfaceLib 9.0 and later
  896. }
  897. function AVLGetRefcon( tree: AVLTreePtr; var refCon: UnivPtr ): OSErr; external name '_AVLGetRefcon';
  898. (* __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  899. {$endc} {not TARGET_CPU_64}
  900. {$endc} {TARGET_OS_MAC}
  901. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  902. end.
  903. {$endc} {not MACOSALLINCLUDE}