mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
Candidate release of source code.
This commit is contained in:
parent
db81e6b3b0
commit
79d8f164f8
12449 changed files with 2800756 additions and 16 deletions
151
Ghidra/Framework/DB/src/main/java/db/VarKeyNode.java
Normal file
151
Ghidra/Framework/DB/src/main/java/db/VarKeyNode.java
Normal file
|
@ -0,0 +1,151 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package db;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import db.buffers.DataBuffer;
|
||||
|
||||
/**
|
||||
* <code>VarKeyNode</code> is an abstract implementation of a BTree node
|
||||
* which utilizes variable-length Field key values.
|
||||
*/
|
||||
abstract class VarKeyNode implements BTreeNode {
|
||||
|
||||
private static final int KEY_TYPE_SIZE = 1;
|
||||
private static final int KEY_COUNT_SIZE = 4;
|
||||
|
||||
private static final int KEY_TYPE_OFFSET = NodeMgr.NODE_HEADER_SIZE;
|
||||
private static final int KEY_COUNT_OFFSET = KEY_TYPE_OFFSET + KEY_TYPE_SIZE;
|
||||
|
||||
static final int VARKEY_NODE_HEADER_SIZE = NodeMgr.NODE_HEADER_SIZE + KEY_TYPE_SIZE +
|
||||
KEY_COUNT_SIZE;
|
||||
|
||||
protected final Field keyType;
|
||||
protected final int maxKeyLength;
|
||||
|
||||
protected NodeMgr nodeMgr;
|
||||
protected DataBuffer buffer;
|
||||
protected VarKeyInteriorNode parent;
|
||||
protected int keyCount;
|
||||
|
||||
/**
|
||||
* Construct an existing variable-length-key node.
|
||||
* @param nodeMgr table node manager instance
|
||||
* @param buf node buffer
|
||||
*/
|
||||
VarKeyNode(NodeMgr nodeMgr, DataBuffer buf) {
|
||||
this.nodeMgr = nodeMgr;
|
||||
this.buffer = buf;
|
||||
keyType = Field.getField(buf.getByte(KEY_TYPE_OFFSET));
|
||||
keyCount = buffer.getInt(KEY_COUNT_OFFSET);
|
||||
maxKeyLength = VarKeyInteriorNode.getMaxKeyLength(buffer.length());
|
||||
nodeMgr.addNode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new variable-length-key node.
|
||||
* @param nodeMgr table node manager.
|
||||
* @param nodeType node type
|
||||
* @param keyType key Field type
|
||||
* @throws IOException thrown if IO error occurs
|
||||
*/
|
||||
VarKeyNode(NodeMgr nodeMgr, byte nodeType, Field keyType) throws IOException {
|
||||
this.nodeMgr = nodeMgr;
|
||||
this.buffer = nodeMgr.getBufferMgr().createBuffer();
|
||||
NodeMgr.setNodeType(buffer, nodeType);
|
||||
this.keyType = keyType.newField();
|
||||
buffer.putByte(KEY_TYPE_OFFSET, keyType.getFieldType());
|
||||
setKeyCount(0);
|
||||
maxKeyLength = VarKeyInteriorNode.getMaxKeyLength(buffer.length());
|
||||
nodeMgr.addNode(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ghidra.framework.store.db.BTreeNode#getBufferId()
|
||||
*/
|
||||
@Override
|
||||
public int getBufferId() {
|
||||
return buffer.getId();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ghidra.framework.store.db.BTreeNode#getBuffer()
|
||||
*/
|
||||
@Override
|
||||
public DataBuffer getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root for this node. If setParent has not been invoked, this node
|
||||
* is assumed to be the root.
|
||||
* @return TableNode
|
||||
*/
|
||||
VarKeyNode getRoot() {
|
||||
if (parent != null)
|
||||
return parent.getRoot();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ghidra.framework.store.db.BTreeNode#getKeyCount()
|
||||
*/
|
||||
@Override
|
||||
public int getKeyCount() {
|
||||
return keyCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ghidra.framework.store.db.BTreeNode#setKeyCount(int)
|
||||
*/
|
||||
@Override
|
||||
public void setKeyCount(int cnt) {
|
||||
keyCount = cnt;
|
||||
buffer.putInt(KEY_COUNT_OFFSET, keyCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the key value at a specific index.
|
||||
* @param index key index
|
||||
* @return key value
|
||||
* @throws IOException thrown if an IO error occurs
|
||||
*/
|
||||
abstract Field getKey(int index) throws IOException;
|
||||
|
||||
/**
|
||||
* Get the leaf node which contains the specified key.
|
||||
* @param key key value
|
||||
* @return leaf node
|
||||
* @throws IOException thrown if an IO error occurs
|
||||
*/
|
||||
abstract VarKeyRecordNode getLeafNode(Field key) throws IOException;
|
||||
|
||||
/**
|
||||
* Get the left-most leaf node within the tree.
|
||||
* @return left-most leaf node.
|
||||
* @throws IOException thrown if IO error occurs
|
||||
*/
|
||||
abstract VarKeyRecordNode getLeftmostLeafNode() throws IOException;
|
||||
|
||||
/*
|
||||
* @see ghidra.framework.store.db.BTreeNode#delete()
|
||||
*/
|
||||
@Override
|
||||
public abstract void delete() throws IOException;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue