Warning: session_start(): open(/var/lib/php/sessions/sess_9amnbnjaa87gm23glbpe00qu89, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass HuffmanTree is BitIO {
settable Node root;
/*
algebraic Node {
constructor Branch {
settable Node zero;
settable Node one;
}
constructor Leaf {
settable byte literal;
}
}
*/
abstract static class Node is BitIO {}
static class Branch > Node {
settable Node zero;
settable Node one;
public void readWrite(BitHead head) {
head.exchangeBit(1);
head.exchange(zero, -> zero = readNode(head));
head.exchange(one, -> one = readNode(head));
}
}
static class Leaf > Node {
settable byte literal;
*() {}
*(int literal) { literal((byte) literal); }
byte get() { ret literal; }
public void readWrite(BitHead head) {
head.exchangeBit(0);
head.exchangeByte(literal, l1 literal);
}
}
void makeRootIfEmpty {
root ifNull = new Leaf(0);
}
Node readNode(BitHead head) {
Node node = head.peekBit() ? new Branch : new Leaf;
node.readWrite(head);
}
public void readWrite(BitHead head) {
makeRootIfEmpty();
root.readWrite(head);
}
toString {
makeRootIfEmpty();
new LS out;
new StringBuilder symbol;
embedded void toString_collect(Node node) {
if (node cast Leaf) {
symbol.append("0");
out.add(symbol + ": " + /*ubyteToHex*/quote(codePoint(node!)));
removeLast(symbol);
} else {
cast node to Branch;
symbol.append("1");
toString_collect(node.zero());
toString_collect(node.one());
removeLast(symbol);
}
}
toString_collect(root);
ret lines(out);
}
}