// pre-order traversal
 private void writeRecursively(DataOutput out, TernaryTreeNode node) throws IOException {
   // write out the current node
   out.writeString(new String(new char[] {node.splitchar}, 0, 1));
   // prepare a mask of kids
   byte mask = 0;
   if (node.eqKid != null) mask |= EQ_KID;
   if (node.loKid != null) mask |= LO_KID;
   if (node.hiKid != null) mask |= HI_KID;
   if (node.token != null) mask |= HAS_TOKEN;
   if (node.val != null) mask |= HAS_VALUE;
   out.writeByte(mask);
   if (node.token != null) out.writeString(node.token);
   if (node.val != null) out.writeLong(((Number) node.val).longValue());
   // recurse and write kids
   if (node.loKid != null) {
     writeRecursively(out, node.loKid);
   }
   if (node.eqKid != null) {
     writeRecursively(out, node.eqKid);
   }
   if (node.hiKid != null) {
     writeRecursively(out, node.hiKid);
   }
 }
Ejemplo n.º 2
0
 private void writeRecursively(DataOutput out, TSTNode node) throws IOException {
   if (node == null) {
     return;
   }
   out.writeString(new String(new char[] {node.splitchar}, 0, 1));
   byte mask = 0;
   if (node.relatives[TSTNode.LOKID] != null) mask |= LO_KID;
   if (node.relatives[TSTNode.EQKID] != null) mask |= EQ_KID;
   if (node.relatives[TSTNode.HIKID] != null) mask |= HI_KID;
   if (node.data != null) mask |= HAS_VALUE;
   out.writeByte(mask);
   if (node.data != null) {
     out.writeLong(((Number) node.data).longValue());
   }
   writeRecursively(out, node.relatives[TSTNode.LOKID]);
   writeRecursively(out, node.relatives[TSTNode.EQKID]);
   writeRecursively(out, node.relatives[TSTNode.HIKID]);
 }