/* 
   (c) J. Dean Brock, 1998, 2002
   Written for UNCA CSCI 343
   Include file for the B+-tree
*/

#ifndef _BTREE_HXX_
#define _BTREE_HXX_

#include <fstream>
using namespace std ;

// This defines blockRecT...
//     a very sleazy way to make both C and C++ happy
#include "btree.h"

class bTree {
public:
  // constructors -- We're keeping this simple
  bTree() ;
  ~bTree() ;
  void create(char *fileName) ;
  void open(char *fileName) ;
  void update(char *key, int value) ;
  int io_ok() const ;
private:
  // File pointer
  fstream btFile ;
  // status of operation -- 1 if OK, 0 if not
  int btState ;
  // B+-tree root
  blockRecT btRoot ;
  // B+-tree node buff -- should someday be an array
  blockRecT btNode ;

  // the BIG internal update routine
  void updateInt(int, const simpRecT &, char[KEYSIZE], int &) ;

  // node manipulation routines
  void findLEslot(const blockRecT &, const char[KEYSIZE], int &, int &) ;
  void insertRec(blockRecT &, int, const simpRecT &) ;
  void splitBlock(blockRecT &, blockRecT &,
		  char[KEYSIZE], const simpRecT &, int) ;

  // I/O routines
  void updateBlock(int, const blockRecT &) ;
  int addBlock(const blockRecT &) ;
  void readBlock(int, blockRecT &) ;

} ;
#endif
