Beispiel #1
0
        public static MultiDawg <TPayload> LoadFrom(Stream stream, Func <BinaryReader, TPayload> readPayload)
        {
            var reader = new BinaryReader(stream);

            if (reader.ReadInt32() != Signature)
            {
                throw new Exception("Invalid signature.");
            }
            if (reader.ReadInt32() != Version)
            {
                throw new Exception("Invalid version.");
            }

            int nodeCount     = reader.ReadInt32();
            int rootNodeIndex = reader.ReadInt32();

            TPayload[][] payloads = reader.ReadArray(r => r.ReadArray(readPayload));

            char[] indexToChar = reader.ReadArray(r => r.ReadChar());

            ushort[] charToIndexPlusOne = CharToIndexPlusOneMap.Get(indexToChar);

            YaleReader.ReadChildren(indexToChar, nodeCount, reader, out var firstChildForNode, out var children);
            var yaleGraph = new YaleGraph(children, firstChildForNode, charToIndexPlusOne, rootNodeIndex, indexToChar);

            return(new MultiDawg <TPayload>(yaleGraph, payloads));
        }
Beispiel #2
0
        public YaleDawg(BinaryReader reader, Func <BinaryReader, TPayload> readPayload)
        {
            nodeCount = reader.ReadInt32();

            rootNodeIndex = reader.ReadInt32();

            payloads = reader.ReadArray(readPayload);

            indexToChar = reader.ReadArray(r => r.ReadChar());

            ushort[] charToIndexPlusOne = CharToIndexPlusOneMap.Get(indexToChar);

            YaleReader.ReadChildren(indexToChar, nodeCount, reader, out firstChildForNode, out children);

            yaleGraph = new YaleGraph(children, firstChildForNode, charToIndexPlusOne, rootNodeIndex, indexToChar);
        }
Beispiel #3
0
 internal MultiDawg(YaleGraph yaleGraph, TPayload[][] payloads)
 {
     this.yaleGraph = yaleGraph;
     this.payloads  = payloads;
 }