📄 hbplustreebytes.java
字号:
package NET.sourceforge.BplusJ.BplusJ;
/// <summary>
/// Btree mapping unlimited length key Strings to fixed length hash values
/// </summary>
public class hBplusTreeBytes extends xBplusTreeBytes
{
public hBplusTreeBytes(BplusTreeBytes tree, int hashLength) //: base(tree, hashLength)
throws Exception
{
// null out the culture context to use the naive comparison
super(tree, hashLength);
this.tree.NoCulture();
}
public static xBplusTreeBytes Initialize(String treefileName, String blockfileName, int PrefixLength, int CultureId,
int nodesize, int buffersize)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefileName, blockfileName, PrefixLength, CultureId, nodesize, buffersize),
PrefixLength);
}
public static xBplusTreeBytes Initialize(String treefileName, String blockfileName, int PrefixLength, int CultureId)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefileName, blockfileName, PrefixLength, CultureId),
PrefixLength);
}
public static xBplusTreeBytes Initialize(String treefileName, String blockfileName, int PrefixLength)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefileName, blockfileName, PrefixLength),
PrefixLength);
}
public static xBplusTreeBytes Initialize(java.io.RandomAccessFile treefile, java.io.RandomAccessFile blockfile, int PrefixLength, int CultureId,
int nodesize, int buffersize)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefile, blockfile, PrefixLength, CultureId, nodesize, buffersize),
PrefixLength);
}
public static xBplusTreeBytes Initialize(java.io.RandomAccessFile treefile, java.io.RandomAccessFile blockfile, int PrefixLength, int CultureId)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefile, blockfile, PrefixLength, CultureId),
PrefixLength);
}
public static xBplusTreeBytes Initialize(java.io.RandomAccessFile treefile, java.io.RandomAccessFile blockfile, int PrefixLength)
throws Exception
{
return new hBplusTreeBytes(
BplusTreeBytes.Initialize(treefile, blockfile, PrefixLength),
PrefixLength);
}
public static xBplusTreeBytes ReOpen(java.io.RandomAccessFile treefile, java.io.RandomAccessFile blockfile) throws Exception
{
BplusTreeBytes tree = BplusTreeBytes.ReOpen(treefile, blockfile);
int prefixLength = tree.MaxKeyLength();
return new hBplusTreeBytes(tree, prefixLength);
}
public static xBplusTreeBytes ReOpen(String treefileName, String blockfileName) throws Exception
{
BplusTreeBytes tree = BplusTreeBytes.ReOpen(treefileName, blockfileName);
int prefixLength = tree.MaxKeyLength();
return new hBplusTreeBytes(tree, prefixLength);
}
public static xBplusTreeBytes ReadOnly(String treefileName, String blockfileName) throws Exception
{
BplusTreeBytes tree = BplusTreeBytes.ReadOnly(treefileName, blockfileName);
int prefixLength = tree.MaxKeyLength();
return new hBplusTreeBytes(tree, prefixLength);
}
public String PrefixForByteCount(String s, int maxbytecount) throws Exception
{
// compute a hash code as a String which has maxbytecount size as a byte sequence
byte[] resultbytes = new byte[maxbytecount];
byte[] inputbytes = BplusTree.StringToBytes(s);
int sevenbits = 127;
int eighthbit = 128;
boolean invert = false;
for (int i=0; i<maxbytecount; i++)
{
resultbytes[i] = (byte) (i & sevenbits);
}
for (int i=0; i<inputbytes.length; i++)
{
int inputbyte = inputbytes[i];
int outputindex = i % maxbytecount;
int outputbyte = resultbytes[outputindex];
int rotator = (i/maxbytecount) % 8;
if (rotator!=0)
{
int hipart = inputbyte << rotator;
int lowpart = inputbyte >> (8-rotator);
inputbyte = (hipart | lowpart);
}
outputbyte = ((inputbyte ^ outputbyte) % sevenbits);
if ( (inputbyte&eighthbit)!=0 )
{
invert = !invert;
}
if (invert)
{
outputbyte = (outputbyte ^ sevenbits) % eighthbit;
}
resultbytes[outputindex] = (byte) outputbyte;
}
String result = BplusTree.BytesToString(resultbytes);
if (result.length()!=maxbytecount)
{
throw new BplusTreeException("bad hash value generated with length: "+result.length()+" not "+maxbytecount);
}
return result;
}
// public String toHtml()
// {
// System.Text.StringBuilder sb = new System.Text.StringBuilder();
// sb.Append(((BplusTreeBytes) this.tree).toHtml());
// sb.Append("\r\n<br><b>key / hash / value dump</b><br>");
// String currentkey = this.FirstKey();
// while (currentkey!=null)
// {
// sb.Append("\r\n<br>"+currentkey);
// sb.Append(" / "+BplusNode.PrintableString(this.PrefixForByteCount(currentkey, this.prefixLength)));
// try
// {
// sb.Append( " / value found " );
// }
// catch (Exception)
// {
// sb.Append( " !!!!!!! FAILED TO GET VALUE");
// }
// currentkey = this.NextKey(currentkey);
// }
// return sb.ToString();
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -