/****************************************************************************
 *   rtstore.h : 
 *   		header file for RTree Store class.
 *
 *   Change Log :
 *		 09-17-1997 Initial version,  Liujian Qian
 *
 *   $Id: rtstore.h,v 1.4 1998/12/02 04:03:46 qian Exp $
 ***************************************************************************/
#ifndef _RTSTORE_H_
#define _RTSTORE_H_

#include "rtentry.h"

#if defined(_WIN32) || defined(__WIN32__)
#define USE_MMAP    0
#undef  USE_MMAP
#else
//comment this out if you don't want the rtree files be mmaped in unix
#define  USE_MMAP   1
#endif

#ifdef   USE_MMAP
#include <sys/types.h>
#include <sys/mman.h>
#endif

/**
 * @internal
 * 
 * Header structure for on-disk RTree.
 */
struct RTHdr 
{
    double	avg_occupancy;
    double	x_min, x_max, y_min, y_max;
    
    int		n_levels;
    int		n_nodes;
    int		n_entries;
    int		n_leaf_nodes;
    int		host_id;	// used by distributed RTree
    int		n_pages;
    int		distributed;
#   ifdef USE_MMAP
    char*	map_region;	// returned by mmap()
    char*	last_map_region;// returned by last mmap()
    off_t	map_len;	// length of file mapping 
    off_t	last_map_len;	// length of last file mapping    
#   endif 

    void	init() 
    {
	avg_occupancy = x_min = x_max = y_min = y_max = 0.0;
	n_levels = n_nodes = n_entries = n_leaf_nodes = 0;
	host_id  = -1; distributed = 0;
#       ifdef USE_MMAP
	map_region = last_map_region = 0;
	map_len = last_map_len = 0;
#	endif	
    }
    friend ostream&	operator<<(ostream& os, const RTHdr& h);
};

class RTree;

/**
 * @internal
 *
 * The RTree storage class.
 *
 *
 *   This class provides a file-based storage for RTree nodes. The file
 *   is divided into pages, with each page corresponding to a RTree node.
 *   Each page has a page number (id), which is the core part of an 
 *   RTree pointer.  Page numbers start with 1. The page with number 0
 *   (the first page in a store) is reserved and never used as a
 *     node page.
 */
class RTStore
{
    friend 	class RTree;
    
    RTHdr hdr;
    int	  file_handle;
    bool  is_open;
    char  _buf[RTPAGE_SZ];	
    RNode *root_node;
    
public:    
    ///
    NOP			RTStore ();
    ///
    virtual NOP		~RTStore () { if(is_open) close(); };

    ///
    virtual bool	isOpen() {return is_open;}
    ///
    virtual void	setOpen(int s) {is_open=s;}
    
    //====================================================
    //====
    //==== GROUP:  RTree store mainipulation methods
    //====
    //====================================================
    
    ///
    virtual Result	create(const char* name);
    ///
    virtual Result	open(const char* name);
    ///
    virtual Result	close(void);
    ///
    virtual Result	read (PageID pg, char*& buf);
    ///
    virtual Result	write(PageID pg, const char* buf);
    ///
    virtual PageID	allocPage ();
    ///
    virtual Result	deallocPage(PageID pg);
    ///
    void		cleanBuf (void) { memset(_buf, 0, RTPAGE_SZ); }
    ///
    RTHdr*		rtHeader (void) {return &hdr; };
    
};


#endif





Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999