⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btreecursoruos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* BtreeCursorUos.java
 * ---------------------------------------------
 * Copyright (c) 2001 University of Saskatchewan
 * All Rights Reserved
 * --------------------------------------------- */
 
package dslib.file;

import dslib.base.*;
import dslib.exception.NoCurrentItemUosException;

/**	A cursor for the Btree data structure. */
public class BtreeCursorUos implements KeyedCursorUos
{
	/**	The file address of the current block. */
	protected long address;

	/**	The current block. */
	protected BtreeBlockUos block;

	/**	The index for the current item in the current block of the leaf. */
	protected int index;
	
	/**	Create a new cursor. <br>
		Analysis: Time = O(1) 
		@param curAddress The file address of the block that has the current item
		@param curBlock The block that has the current item
		@param curIndex The index of the current item in the block */
	public BtreeCursorUos(long curAddress, BtreeBlockUos curBlock, int curIndex)
	{
		address = curAddress;
		block = curBlock;
		index = curIndex;
	}

	/**	Is there a current item?. <br>
		Analysis: Time = O(1) */
	public boolean itemExists()
	{
		return address != -1;
	}

	/**	The key associated with the current item. <br>
		Analysis: Time = O(1) <br>
		PRECONDITION:  <br>
		<ul>
			itemExists()
		</ul> */
	public Comparable itemKey() throws NoCurrentItemUosException
	{
		if (!itemExists())
			throw new NoCurrentItemUosException("A current item must exist");
			
		return block.getRecord(index).key;
	}

	/**	The current item in the BtreeFile. <br>
		Analysis: Time = O(1) <br>
		PRECONDITION:  <br>
		<ul>
			itemExists()
		</ul> */
	public Object item() throws NoCurrentItemUosException
	{
		if (!itemExists())
			throw new NoCurrentItemUosException("A current item must exist");
			
		return block.getRecord(index).item;
	}

	/**	The current key-item pair. <br>
		Analysis: Time = O(1) <br>
		PRECONDITION:  <br>
		<ul>
			itemExists()
		</ul> */
	public PairUos keyItemPair() throws NoCurrentItemUosException
	{
		if (!itemExists())
			throw new NoCurrentItemUosException("A current item must exist");
			
		return new PairUos(itemKey(), item());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -