public void Write(BinaryWriter output) { output.Write(_probs.Length); foreach (var p in _probs) { output.Write(p); } output.Write(_backpointers.Count); output.Write(_leaves.Length); foreach (var optimalStates in _backpointers) { foreach (var state in optimalStates) { output.Write(state); } } output.Write(Position); output.Write(LastLikelihood); //serializing compressed backpointers tree //3 * |H| - 2 is the upper bound of node number var nodeMap = new BiDictionary <HmmOnlineNode, int>(); // 3 * leaves.length - 2; var node = Tree.First; while (node != null) { MapNode(nodeMap, node); node = node.Next; } MapNode(nodeMap, Root); foreach (var leave in _leaves) { MapNode(nodeMap, leave); } var alreadyWritten = new HashSet <HmmOnlineNode>(); output.Write(nodeMap.Count); foreach (var entry in nodeMap.Keys) { HmmOnlineNode.Write(nodeMap, alreadyWritten, entry, output); } output.Write(Tree.Size); node = Tree.First; while (node != null) { HmmOnlineNode.Write(nodeMap, alreadyWritten, node, output); node = node.Next; } HmmOnlineNode.Write(nodeMap, alreadyWritten, Root, output); foreach (var leave in _leaves) { HmmOnlineNode.Write(nodeMap, alreadyWritten, leave, output); } }