home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / btree.zip / BTREE.HPP < prev    next >
C/C++ Source or Header  |  1992-02-16  |  3KB  |  127 lines

  1. //    C++ B+Tree
  2. //    (c) 1990,1991 Larry A. Walker
  3. //    This source is proprietary information which cannot be distributed 
  4. //    without written permission of Larry A. Walker
  5. #ifndef BTREE_H
  6. #define BTREE_H
  7.  
  8. #include "bfh.hpp"
  9.  
  10. class Btree : public BFHClass {
  11.     
  12.     int         index_fd;        // open file
  13.     struct         Trunk trunk;        // btree info
  14.     int         vector;        // Hierarchy list position
  15.     int        blocks_to_flush;    // total hierarchy blocks
  16.     int         ActiveHeight;        // count of nodes in hierarchy
  17.     static struct     HierarchyBlock * hierarchy_list;
  18.     struct     KeyGroup * active_key;        // the active key
  19.     struct  KeyGroup * key_copy;        // copy of the returned key
  20.     struct     Node *     active_node;        // the active node 
  21.     int         key_position;        // the active key's position
  22.         long         left;            // left address
  23.             // variable length compare function
  24.     int        (*compare_funct)(union Key *,struct KeyGroup *,int);    
  25.     int          LocateExact(union Key *); // internal key locate 
  26.     int          LocateInsert(union Key *,int); // internal key locate 
  27.     int          Insert(struct KeyGroup *, int);// internal key insert
  28.     long         save_right_interior_node; // temporary place holder for 
  29.                     // delete and combine
  30.     int        past_exact_key; // signal that there was an exact key
  31.     int KeyGroupSize(struct KeyGroup *);    // what is the key group size
  32.     struct KeyGroup *CopyKey();    // copy the active key into a user area
  33.  
  34.         // ++++++ Low Level Hierarchy operations
  35.  
  36.     int OpenHierarchy();        // --------- Create the Hierarchy
  37.  
  38.     int FlushHierarchy();           // Flush the entire Hierarchy
  39.  
  40.     int LoadHierarchyNode(long);    // Load a single Hierarchy block
  41.  
  42.     struct Node * Parent();        // return the parent
  43.  
  44.     void OpenKeyNode(struct Node *);
  45.  
  46.     int  InsertNodeKeyGroup(struct KeyGroup *);
  47.                 // insert a key at the current position
  48.  
  49.     int  InsertSpareKeyGroup(struct KeyGroup *,struct Node *);
  50.                 // insert a key into the spare key group
  51.  
  52.     int  DeleteNodeKeyGroup();     // delete a key
  53.  
  54.     long LeftAddress();        // return the left address
  55.         
  56.     int  IncrementPosition();
  57.         // increment the position to the next key
  58.         // return Success or fail if no more keys
  59.                 // at the end of the node, we are actually looking left at the
  60.                 // most far right position
  61.  
  62.     void Rewind();            // first key in node
  63.  
  64.         int  Compare(union Key *); // routines to return comparison of key
  65.                     // value to the KeyGroup key
  66.  
  67.     int Currentkey (struct KeyGroup * );
  68.  
  69.         // ++++++ Intermediate level operations
  70.  
  71.     int Combine();
  72.         // combine with left node, if fail combine with right
  73.  
  74.     int UnlinkNode();
  75.         // release an empty node
  76.  
  77.         // ++++++ High level user interface operations
  78.  
  79.     public:
  80.  
  81.     Btree(char *, int = 0, int = UNDEF_KEY, int = 0, int = 0);
  82.  
  83.     ~Btree(){
  84.     }
  85.  
  86.     Close();
  87.  
  88.     int  InstallCompare( int (*) (union Key *, struct KeyGroup *,int) );
  89.  
  90.     int  Locate(union Key *);
  91.  
  92.     // operator overloads ------------
  93.  
  94.     int  operator += (struct KeyGroup *);
  95.  
  96.     int  operator -= (union Key *);
  97.  
  98.     struct KeyGroup *  operator ++();     // next, prefix only
  99.  
  100.     struct KeyGroup *  operator --();     // previous, prefix only
  101.     
  102.     //--------------------------------
  103.  
  104.     struct KeyGroup * First();
  105.  
  106.     struct KeyGroup * Last();
  107.  
  108.     struct KeyGroup * CurrentKey();
  109.  
  110.         void Debug(struct Node * , int);
  111.  
  112.     void DisplayHeader();
  113.  
  114.     void DisplayKey(struct KeyGroup *);
  115.  
  116.     void DUMP ();
  117.  
  118.     void CHECK (int);
  119.  
  120.     long ReportState(int);
  121.  
  122.     long NodePosn();
  123.  
  124. };
  125.  
  126. #endif BTREE_H
  127.