function _tree_get_record($off, $len, $poff = 0, $key = '')
	{
		if ($len == 0)
			return (array('poff' => $poff));
		$this->_io_times++;
		
		// get the data & compare the key data
		fseek($this->fd, $off, SEEK_SET);
		$rlen = XDB_MAXKLEN + 17;
		if ($rlen > $len) $rlen = $len;
		$buf = fread($this->fd, $rlen);
		$rec = unpack('Iloff/Illen/Iroff/Irlen/Cklen', substr($buf, 0, 17));		
		$fkey = substr($buf, 17, $rec['klen']);
		$cmp = ($key ? strcmp($key, $fkey) : 0);
		if ($cmp > 0)
		{
			// --> right
			unset($buf);
			return $this->_tree_get_record($rec['roff'], $rec['rlen'], $off + 8, $key);
		}
		else if ($cmp < 0)
		{
			// <-- left
			unset($buf);
			return $this->_tree_get_record($rec['loff'], $rec['llen'], $off, $key);
		}
		else {
			// found!!
			$rec['poff'] = $poff;
			$rec['off'] = $off;
			$rec['len'] = $len;
			$rec['voff'] = $off + 17 + $rec['klen'];
			$rec['vlen'] = $len - 17 - $rec['klen'];
			$rec['key'] = $fkey;
			
			fseek($this->fd, $rec['voff'], SEEK_SET);
			$rec['value'] = fread($this->fd, $rec['vlen']);
			return $rec;
		}
	}
function _tree_get_record($off, $len, $poff = 0, $key = '')
	{
		if ($len == 0)
			return (array('poff' => $poff));
		$this->_io_times++;
		
		// get the data & compare the key data
		fseek($this->fd, $off, SEEK_SET);
		$rlen = XDB_MAXKLEN + 17;
		if ($rlen > $len) $rlen = $len;
		$buf = fread($this->fd, $rlen);
		$rec = unpack('Iloff/Illen/Iroff/Irlen/Cklen', substr($buf, 0, 17));		
		$fkey = substr($buf, 17, $rec['klen']);
		$cmp = ($key ? strcmp($key, $fkey) : 0);
		if ($cmp > 0)
		{
			// --> right
			unset($buf);
			return $this->_tree_get_record($rec['roff'], $rec['rlen'], $off + 8, $key);
		}
		else if ($cmp < 0)
		{
			// <-- left
			unset($buf);
			return $this->_tree_get_record($rec['loff'], $rec['llen'], $off, $key);
		}
		else {
			// found!!
			$rec['poff'] = $poff;
			$rec['off'] = $off;
			$rec['len'] = $len;
			$rec['voff'] = $off + 17 + $rec['klen'];
			$rec['vlen'] = $len - 17 - $rec['klen'];
			$rec['key'] = $fkey;
			
			fseek($this->fd, $rec['voff'], SEEK_SET);
			$rec['value'] = fread($this->fd, $rec['vlen']);
			return $rec;
		}
	}
function _tree_get_record ( $ off , $ len , $ poff = 0 , $ key = '' ) { if ( $ len == 0 ) return ( array ( 'poff' => $ poff ) ) ; $ this -> _io_times ++ ; // get the data & compare the key data fseek ( $ this -> fd , $ off , SEEK_SET ) ; $ rlen = XDB_MAXKLEN + 17 ; if ( $ rlen > $ len ) $ rlen = $ len ; $ buf = fread ( $ this -> fd , $ rlen ) ; $ rec = unpack ( 'Iloff/Illen/Iroff/Irlen/Cklen' , substr ( $ buf , 0 , 17 ) ) ; $ fkey = substr ( $ buf , 17 , $ rec [ 'klen' ] ) ; $ cmp = ( $ key ? strcmp ( $ key , $ fkey ) : 0 ) ; if ( $ cmp > 0 ) { // --> right unset ( $ buf ) ; return $ this -> _tree_get_record ( $ rec [ 'roff' ] , $ rec [ 'rlen' ] , $ off + 8 , $ key ) ; } else if ( $ cmp < 0 ) { // <-- left unset ( $ buf ) ; return $ this -> _tree_get_record ( $ rec [ 'loff' ] , $ rec [ 'llen' ] , $ off , $ key ) ; } else { // found!! $ rec [ 'poff' ] = $ poff ; $ rec [ 'off' ] = $ off ; $ rec [ 'len' ] = $ len ; $ rec [ 'voff' ] = $ off + 17 + $ rec [ 'klen' ] ; $ rec [ 'vlen' ] = $ len - 17 - $ rec [ 'klen' ] ; $ rec [ 'key' ] = $ fkey ; fseek ( $ this -> fd , $ rec [ 'voff' ] , SEEK_SET ) ; $ rec [ 'value' ] = fread ( $ this -> fd , $ rec [ 'vlen' ] ) ; return $ rec ; } }
get the record by tree
get the record by tree