Newbie Spellweaver
- Joined
- Jun 14, 2009
- Messages
- 98
- Reaction score
- 12
Hello,
I have two arrays:
short[] LEAFS = new short[length]
short[] INTERNAL_NODES = new short[length - 1][2]
I read dicitonary and fill LEAFS with item ids and I fill INTERNAL_NODES array with left and right nodes which are positive and/or negative.
How can I find binary path for needed (short) item id ? I spent all day trying to implement this, but without success.
I can decompress data just fine, but I have no idea how to find path for compression.
I have two arrays:
short[] LEAFS = new short[length]
short[] INTERNAL_NODES = new short[length - 1][2]
I read dicitonary and fill LEAFS with item ids and I fill INTERNAL_NODES array with left and right nodes which are positive and/or negative.
Code:
public void loadDictionary()
{
if (LEAF_NODES != null && INTERNAL_NODES != null)
return;
Path path = Paths.get("./dictionary.dat");
try (DataInputStream bis = new DataInputStream(new ByteArrayInputStream(Files.readAllBytes(path))))
{
final short numIds = (short)((bis.readByte() & 0xFF) | bis.readByte() << 8);
this.LEAF_NODES = new short[numIds];
for (short n2 = 0; n2 < numIds; ++n2) {
this.LEAF_NODES[n2] = (short)(bis.readByte() << 8 | (short)(bis.readByte() & 0xFF));
}
this.INTERNAL_NODES = new short[numIds - 1][2];
for (short n3 = 0; n3 < numIds - 1; n3++) {
this.INTERNAL_NODES[n3][0] = (short)((bis.readByte() & 0xFF) | bis.readByte() << 8);
this.INTERNAL_NODES[n3][1] = (short)((bis.readByte() & 0xFF) | bis.readByte() << 8);
}
}
catch (IOException e)
{
_log.log(Level.SEVERE, "WARNING: The Server coud not load dictionary. Reason: "
+ e.getMessage(), e);
}
}
How can I find binary path for needed (short) item id ? I spent all day trying to implement this, but without success.
I can decompress data just fine, but I have no idea how to find path for compression.