AVLTree.pas 33 KB

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