home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568a.lha / RexxRMF_v1.1 / avl.structs.h < prev    next >
C/C++ Source or Header  |  1991-09-11  |  8KB  |  225 lines

  1.  
  2. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
  3.  *::                                                                       ::*
  4.  *::  An implementaion of an AVL-Tree (balanced binary tree).              ::*
  5.  *::                                                                       ::*
  6.  *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  7.  
  8. #define MAXKEYLEN     ((ULONG) 100)       /* maximum length of a key      */
  9.  
  10. #define MAXINDICES    ((ULONG) 8)         /* maximum number of indices    */
  11.                                           /* 0-5, 0=primary, 1-5=alt      */ 
  12.                                           /* 6=notused                    */
  13.                                           /* 7=deleted file blocks        */
  14.  
  15. #define DELETEINDEX   ((ULONG)  7)
  16.                                           
  17. #define MAXINDEXNUM   ((ULONG) 5)         /* max user index               */                                 
  18.  
  19.  
  20. /*** Key Data Structure ***/
  21.  
  22. struct Keydata 
  23. {
  24.    USHORT occurence; /* when duplicate keys allowed, specifies the  */
  25.                      /* occurence number of the node. Otherwise = 1 */
  26.                        
  27.    USHORT keylen;    /* length of the key data */
  28.    
  29.    char   *kdata;    /* pointer to key data */
  30.    
  31. };
  32.  
  33.  
  34.  
  35.  
  36. /***   Tree Node Structure  ***/
  37. /*  The binary tree is built  */  
  38. /*  using this structure      */
  39.  
  40. struct AvlNode
  41. {
  42.        struct AvlNode *llink;    /* points to the left child of this node   */
  43.        
  44.        struct AvlNode *rlink;    /* points to the right child of this node  */
  45.        
  46.        struct AvlNode *parent;   /* points to the parent of this node       */
  47.                                  /* follow up the tree, gives you the path  */
  48.                                
  49.        struct AvlNode *primary;  /* alternates point to their primary node  */
  50.  
  51.        struct AvlNode *alternatekeys[MAXINDICES]; /* primary points to alts */
  52.  
  53.        /* following fields used internally by AVL algorithm */
  54.        struct AvlNodeInfo {
  55.        
  56.               SHORT   balance;
  57.               USHORT  inxnum;
  58.               ULONG   rank;
  59.        } avi;
  60.        
  61.        
  62.        /* this part of the node stores data associated with the key */
  63.        struct AvlUserData
  64.        {
  65.               ULONG  recaddr;          /* This is assumed to be record   */
  66.                                        /* location in some external file */
  67.                                        /* for this key. This value gets  */
  68.                                        /* saved in the index file.       */
  69.                                        
  70.               ULONG  blklen;           /* block length of data           */
  71.  
  72.               struct Keydata *key;     /* pointer to the key value       */
  73.               
  74.               APTR   userdata1;        /* any data/pointer to data       */
  75.               APTR   userdata2;        /* any data/pointer to data       */
  76.                                        /* userdata1&2 are not saved in   */
  77.                                        /* the index file.                */
  78.               
  79.        } aud;
  80.        
  81.        
  82. } ;  /* End Structure AvlNode */
  83.  
  84.  
  85.  
  86.  
  87.  
  88. /***  Structure of the Index File  ***/
  89. /*                                   */
  90. /*  this is the index file header    */
  91. /*  It is loaded when the index file */
  92. /*  is opened. The AVL functions     */
  93. /*  return a pointer to this struct  */
  94. /*  for use in accessing the index   */
  95. /*  OPEN_RMF/MAKE_INDEX return a     */
  96. /*  pointer to this structure        */
  97. /*                                   */
  98. /*************************************/
  99.  
  100. struct IndexFile
  101.            
  102.    USHORT xid;                      /* identifies file as an index        */
  103.    ULONG  datestamp;                /* not used                           */
  104.    ULONG  numberofrecords;          /* number of keys in the index        */
  105.  
  106.    ULONG  compares;                 /* number of comparisons made during  */
  107.                                     /* search. (has no meaning at open)   */
  108.  
  109.    ULONG  height;                   /* the height of the binary tree      */
  110.                                     /* (has no meaning at open time)      */
  111.  
  112.    USHORT doserror;                 /* set to 0 if no errors occured      */
  113.  
  114.    USHORT rmferror;                 /* set to 0 if no errors occured      */
  115.                                     /* otherwise set to error code as     */
  116.                                     /* defined above.                     */
  117.  
  118.    ULONG prevpos;                   /* relative positions of previous key */
  119.                                     /* retrieved. (meaningless at open)   */
  120.  
  121.    ULONG rba_primary;               /* location where index entries begin.*/
  122.                                     /* should be valued. Tells where the  */
  123.                                     /* first index entry is located in    */
  124.                                     /* the index file.                    */
  125.  
  126.    ULONG fd_primary;                /* file handle for the index file     */
  127.                                     /* filled in at open time             */
  128.  
  129.    ULONG fd_data;                   /* file handle for the data  file     */
  130.                                     /* filled in at open time             */
  131.    UBYTE *indxname;                 /* points to filename of index file   */
  132.    UBYTE *filename;                 /* points to filename of data file    */
  133.    UBYTE *cmp1;
  134.    UBYTE *cmp2;
  135.    LONG  cmpl1;
  136.    LONG  cmpl2;
  137.    struct AvlNode *MRNode;          /* most recent AvlNode returned       */
  138.  
  139.    struct AvlNode *PrevSrchKey[MAXINDICES]; 
  140.    
  141.    struct AvlNode *SearchNode[MAXINDICES]; 
  142.    
  143.    struct AvlNode *IndexRoot[MAXINDICES];
  144.    
  145.    /* previous search type 'K','P','R', 'U'  */
  146.    UBYTE  prev_srch_type[MAXINDICES]; 
  147.    
  148.    UBYTE  dups;                     /* set to 1 if duplicates allowed     */
  149.                                     /* otherwise set to 0                 */
  150.            
  151. };
  152.  
  153.  
  154. /***   Structure of the Index File Entries   ***/
  155. /*     repeats for each primary key in file    */
  156.  
  157. struct DiskIndex 
  158. {
  159.  
  160.     struct DI_Info {
  161.     
  162.     ULONG  recaddr;             /* record location for this key     */
  163.                                 /* this is the location of a data   */
  164.                                 /* record in some external file.    */
  165.                                 
  166.     USHORT blklength;           /* length of record                 */                            
  167.     
  168.     UBYTE  rectype;             /* record type ??? dreaming I guess */
  169.     
  170.     UBYTE  recstatus;           /* record status = 'A'/'D'             */
  171.                                 /* 'A' active record                   */
  172.                                 /* a 'A' will have its keys (from      */
  173.                                 /* below) loaded in the corresponding  */
  174.                                 /* index. ie. if keylen[3] is non zero */
  175.                                 /* then keydata[3] is loaded in index  */
  176.                                 /* three.                              */
  177.                                 /* 'D' deleted record                  */
  178.                                 /* a 'D' record block automatically    */
  179.                                 /* gets loaded into the DELETEINDEX    */
  180.                                 /* regardless of the keylen info.      */
  181.  
  182.     USHORT keylen[MAXINDICES];  /* length of the key                   */
  183.     
  184.     } di_info;
  185.     
  186.     UBYTE  keydata[MAXKEYLEN*MAXINDICES]; /* the actual key value. */
  187.                                           /* keylen says how long, */
  188.                                           /* these are not NULL    */
  189.                                           /* terminated.           */
  190. } ;
  191.  
  192.  
  193.  
  194.  
  195. struct RecordHeader 
  196. {
  197.     SHORT blockid;                        /* not used */
  198.     LONG  blocklength;
  199.     SHORT dataoffset;
  200.     SHORT spare0;                         /* not used */
  201.     SHORT recordlength;
  202.     SHORT numberoffields;
  203.     ULONG datestamp;                      /* not used */
  204.     LONG  spare1;
  205.     SHORT spare2;
  206.     SHORT numaltindx;
  207. };
  208.  
  209. struct DataFileHeader 
  210. {
  211.     SHORT  fileid;                        /* not used */
  212.     ULONG  datestamp;                     /* not used */
  213.     LONG   spare0;
  214.     LONG   spare1;
  215.     SHORT  spare2;
  216.     SHORT  spare3;
  217.     SHORT  spare4;
  218. };
  219.  
  220. struct EOR_Trailer 
  221. {
  222.   UBYTE eor[4];
  223. };
  224.