home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / amiga / programm / 17476 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  2.9 KB

  1. Path: sparky!uunet!mcsun!julienas!sophia!modja.inria.fr!beust
  2. From: beust@modja.inria.fr (Cedric Beust)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Small database package
  5. Message-ID: <35892@sophia.inria.fr>
  6. Date: 10 Dec 92 09:33:36 GMT
  7. Sender: news@sophia.inria.fr
  8. Organization: University of Nice Sophia-Antipolis, France
  9. Lines: 87
  10.  
  11.  
  12.     While writing a program, I happened to need badly a generic way
  13.     to handle data. So I decided to write a small generic module
  14.     that helped me a great deal. It occured to me that if someone
  15.     had posted this kind of thing on Usenet, it would have saved
  16.     me some development time. That's why I'm posting the header
  17.     of the module. It should be enough for any programmers to decide
  18.     whether they need it or not.
  19.  
  20.     Depending on the interest, I'll wrap a distribution and make it
  21.     available on ftp site (or by mail, it's very short), so let me
  22.     know if you're interested.
  23.  
  24.     I won't insist on the Genericity interest, nor the "abstract
  25.     type" concept. All you have to know is that you can change
  26.     the implementation to improve it and you won't have to modify
  27.     your programs...
  28.  
  29.     One last point : the database module is completely dynamic and
  30.     will only be limited by your memory.
  31.  
  32.     The excerpt from the header file follows.
  33.  
  34.  
  35. --
  36. Cedric BEUST, beust@sa.inria.fr, Bull Research Koala proj, KoalaBus & xforum
  37. Pho:(33) 93.65.78.07(.66 Fax), INRIA, B.P.93 - 06902 Sophia Antipolis, FRANCE.
  38.  
  39.  
  40.  
  41. /* Generic module to handle dynamically allocated database */
  42.  
  43. DataBase
  44. DB_NewDataBase(int size);
  45. /* Initialize a new database, which objects have size 'size' */
  46. /* Alter the internal pointer */
  47.  
  48. Bool
  49. DB_EndOfDataBase(DataBase db);
  50. /* True if we reached the end of the database */
  51.  
  52. void
  53. DB_ClearDataBase(DataBase db);
  54. /* Clear the database */
  55.  
  56. Bool
  57. DB_AddEntry(DataBase db, Generic entry);
  58. /* Add the following entry into the database */
  59. /* Return 0 if the operation was successful */
  60.  
  61. Bool
  62. DB_RemoveEntry(DataBase db, Generic entry);
  63. /* Remove the specified entry */
  64. /* Return 0 if the operation was successful */
  65.  
  66. Bool
  67. DB_RemoveNthEntry(DataBase db, int n);
  68. /* Remove the nth DB_NextEntry from the database (0 = first entry) */
  69. /* Return 0 if the operation was successful */
  70.  
  71. Bool
  72. DB_ReplaceEntry(DataBase db, Generic old, Generic new);
  73. /* Replace the old entry with the new one */
  74. /* Return 0 if the operation was successful */
  75.  
  76. void
  77. DB_Rewind(DataBase db);
  78. /* Rewind the database so that a subsequent NextEntry returns the */
  79. /* first occupied element */
  80.  
  81. Generic
  82. DB_NextEntry(DataBase db);
  83. /* Return the next entry, or NULL if we reached the end of the database */
  84.  
  85. Generic
  86. DB_NthEntry(DataBase db, int n);
  87. /* Return the nth "DB_NextEntry" of the database (0 = first entry) */
  88.  
  89. int
  90. DB_Count(DataBase db);
  91. /* Return the number of entries in the databae */
  92.  
  93. void
  94. DB_Sort(DataBase db, int (* compareFunction)(Generic a, Generic b));
  95. /* Sort the database, so that */
  96. /*     compareFunction(DB_NextEntry(db), DB_NextEntry(db)) < 0  */
  97.  
  98.