home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWCollec / SLSrtArr.h < prev   
Encoding:
Text File  |  1996-09-17  |  3.3 KB  |  104 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLSrtArr.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef SLSRTARR_H
  11. #define SLSRTARR_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. //========================================================================================
  18. // Forward Declarations
  19. //========================================================================================
  20.  
  21. struct FW_SPrivSortedArray;
  22. typedef FW_SPrivSortedArray* FW_HSortedArray;
  23.  
  24. //========================================================================================
  25. // Typedefs
  26. //========================================================================================
  27.  
  28. typedef int (*FW_SortedArray_CompareFunction)(void* first, void* second);
  29.     // return negative integer if first is less than second
  30.     // return 0 if first == second
  31.     // return positive integer if first is greater than second
  32.  
  33. //========================================================================================
  34. // Extern C Methods
  35. //========================================================================================
  36.  
  37. FW_EXTERN_C_BEGIN
  38.  
  39. #if defined(FW_ODFLIB_IMPORT)
  40. #pragma import on
  41. #elif defined(FW_ODFLIB)
  42. #pragma export on
  43. #endif
  44.  
  45. FW_HSortedArray    FW_PrivSortedArray_New(FW_PlatformError* error,
  46.                                         FW_SortedArray_CompareFunction compare);
  47.  
  48. void    FW_PrivSortedArray_Dispose(FW_HSortedArray self);
  49.  
  50. long FW_PrivSortedArray_GetLength(FW_HSortedArray self);
  51.     // Retrieve the number of items
  52.  
  53. void* FW_PrivSortedArray_GetItemAt(FW_HSortedArray self, long index);
  54.     // Retrieve the item at location index
  55.  
  56. FW_Boolean FW_PrivSortedArray_Find(FW_HSortedArray self, 
  57.                             void* item,
  58.                             long* index);
  59.     // Do a binary search for item
  60.     // If item is found, function result is true and index is the location of the item
  61.     // If item is not found, result is false, and index is location where item
  62.     // would be inserted
  63.  
  64. void FW_PrivSortedArray_Insert(FW_HSortedArray self, 
  65.                             void* newItem,
  66.                             long index,
  67.                             FW_PlatformError* error);
  68.     // Item is inserted into the array at location index.
  69.     // It is client's responsiblity to insert item in a location
  70.     // that preserves sorting. Use FW_PrivSortedArray_Find
  71.     // to find the correct location
  72.  
  73.  
  74. void FW_PrivSortedArray_Add(FW_HSortedArray self, 
  75.                             void* newItem,
  76.                             long* index,
  77.                             FW_PlatformError* error);
  78.     // Item is inserted into the array in the location that preserves sorting.
  79.     // The location is returned in *index.
  80.     // Items must be unique, so it is an error if there already exists an item
  81.     // in the array which when compared to newItem returns kEqual
  82.     
  83. void FW_PrivSortedArray_RemoveIndex(FW_HSortedArray self,
  84.                             long index,
  85.                             FW_PlatformError* error);
  86.     // The item at the specified index is removed from the array.
  87.     // It is an error if an out-of-bounds index is specified.
  88.     
  89. void FW_PrivSortedArray_RemoveItem(FW_HSortedArray self,
  90.                                 void* item,
  91.                                 FW_PlatformError* error);
  92.         // Item is removed from the array.
  93.         // It is an error if item does not exists.
  94.  
  95. #if defined(FW_ODFLIB_IMPORT)
  96. #pragma import off
  97. #elif defined(FW_ODFLIB)
  98. #pragma export off
  99. #endif
  100.  
  101. FW_EXTERN_C_END
  102.  
  103. #endif
  104.