Newer
Older
ubixfs-2 / btree.h
#ifndef BTREE_H
#define BTREE_H

#include "btypes.h"  // integer definitions
#include "btree_vfs.h" // bTreeVFS class

enum treeTypes { BT_CUSTOM, BT_PCHAR, BT_STRING, BT_SINGLE, BT_DOUBLE, BT_INT32, BT_INT64 };

typedef struct blockRun_t {
  int32  AG;
  uInt16 start;
  uInt16 len;
} __attribute__((__packed__));

typedef blockRun_t inodeAddr;

typedef union {
  int32     i;
  uInt32    u;
  float     f;
  double    d;
  void *    p;
  inodeAddr iAddr;
  int64     offset;
} uPtr;  

typedef struct bNodeData_t {
  uPtr      link;
  union {
    char    str[1];
    float   f;
    double  d;
    int32   i;
    int64   x;
  } key;
} __attribute__((__packed__));

typedef struct bTreeSearch {
  uPtr      value;
  void *    key;
  int       keySize;
}; // bTreeSearchRec

typedef struct bTreeInfo {
  int64     magic;
  uPtr      root;
  uPtr      firstDeleted;
  uInt32    nodes;
  uInt32    height;
  uInt32    keys;
  uInt32    bNodeSize;
  treeTypes treeType;
} __attribute__((__packed__));

typedef int (*compareKeyFunc)(void *, void *);
typedef void (*copyKeyProc)(void *, void *);
typedef int (*keySizeFunc)(void *);

class bTree {
 protected:
  compareKeyFunc compareKey;
  copyKeyProc    copyKey;
  keySizeFunc    keySize;
  bTreeInfo *    info;
  bTreeVFS *     vfs;
  bool           memoryTree;
  bool           treeChanged; 

  int      align(int);
 public:
           bTree(char *, uInt32, treeTypes, bTreeVFS *);
  void     InstallUserFunctions(compareKeyFunc, copyKeyProc, keySizeFunc);  
  virtual ~bTree(void);
};// bTree

#endif