Пример #1
0
            public override Node Register(StringTrieBuilder builder)
            {
                next = next.Register(builder);
                // Break the linear-match sequence into chunks of at most kMaxLinearMatchLength.
#pragma warning disable 612, 618
                int maxLinearMatchLength = builder.MaxLinearMatchLength;
#pragma warning restore 612, 618
                while (length > maxLinearMatchLength)
                {
                    int nextOffset = stringOffset + length - maxLinearMatchLength;
                    length -= maxLinearMatchLength;
                    LinearMatchNode suffixNode =
                        new LinearMatchNode(strings, nextOffset, maxLinearMatchLength, next);
                    suffixNode.SetHashCode();
                    next = builder.RegisterNode(suffixNode);
                }
                Node result;
#pragma warning disable 612, 618
                if (hasValue && !builder.MatchNodesCanHaveValues)
#pragma warning restore 612, 618
                {
                    int intermediateValue = value;
                    value    = 0;
                    hasValue = false;
                    SetHashCode();
                    result = new IntermediateValueNode(intermediateValue, builder.RegisterNode(this));
                }
                else
                {
                    SetHashCode();
                    result = this;
                }
                return(builder.RegisterNode(result));
            }
Пример #2
0
            private Node Register(StringTrieBuilder builder, int start, int limit)
            {
                int length = limit - start;

#pragma warning disable 612, 618
                if (length > builder.MaxBranchLinearSubNodeLength)
#pragma warning restore 612, 618
                {
                    // Branch on the middle unit.
                    int middle = start + length / 2;
                    return(builder.RegisterNode(
                               new SplitBranchNode(
                                   chars[middle],
                                   Register(builder, start, middle),
                                   Register(builder, middle, limit))));
                }
                ListBranchNode listNode = new ListBranchNode(length);
                do
                {
                    char c    = chars[start];
                    Node node = equal[start];
                    if (node.GetType() == typeof(ValueNode))
                    {
                        // Final value.
                        listNode.Add(c, ((ValueNode)node).Value);
                    }
                    else
                    {
                        listNode.Add(c, node.Register(builder));
                    }
                } while (++start < limit);
                return(builder.RegisterNode(listNode));
            }
Пример #3
0
            public override Node Register(StringTrieBuilder builder)
            {
                Node           subNode = Register(builder, 0, chars.Length);
                BranchHeadNode head    = new BranchHeadNode(chars.Length, subNode);
                Node           result  = head;

                if (hasValue)
                {
                    if (builder.MatchNodesCanHaveValues)
                    {
                        head.SetValue(value);
                    }
                    else
                    {
                        result = new IntermediateValueNode(value, builder.RegisterNode(head));
                    }
                }
                return(builder.RegisterNode(result));
            }