Exemplo n.º 1
0
        private void SplitLinkedNodeAndAddNewKeyNode(int start, int end, int value, int matchingCharCount)
        {
            //Splits "this" into two LinkedNodes and adds new KeyNode for current suffix
            var newLinkedNode = new LinkedNode(Start + matchingCharCount, End)
            {
                Children = Children
            };

            Children = new LinkedList <IChildNode>();
            Children.AddLast(newLinkedNode);
            End = Start + matchingCharCount;
            var newKeyNode = new KeyNode(start + matchingCharCount, end, value);

            Children.AddLast(newKeyNode);
        }
Exemplo n.º 2
0
        private void SplitKeyNodeAndAddBothToNewLinkedNode(string text, KeyNode node, int start, int end, int value)
        {
            //Count matching chars
            var count = CountMatchingChars(text, start, end, node.Start);

            //Replace node with new LinkedNode with lenth og the count of charmatches and add two KeyNodes.
            //One for node and one for the current value
            var newLinkedNode = new LinkedNode(node.Start, node.Start + count);
            var newKeyNode1   = new KeyNode(node.Start + count, node.End, node.Value);
            var newKeyNode2   = new KeyNode(start + count, end, value);

            newLinkedNode.Children.AddLast(newKeyNode1);
            newLinkedNode.Children.AddLast(newKeyNode2);
            Children.Remove(node);
            Children.AddFirst(newLinkedNode);
        }
Exemplo n.º 3
0
        public new LinkedNode Add(Key key, int value)
        {
            var tmp           = More;
            var matchingChars = Key.CountMatchingCharacters(key);
            var nextKey       = new Key(Key.WordKey,
                                        MathClamp(Key.StartIndex + matchingChars, Key.StartIndex, Key.LastIndex), Key.LastIndex,
                                        Key.lowerWord);
            var nextMoreKey = new Key(key.WordKey,
                                      MathClamp(key.StartIndex + matchingChars, key.StartIndex, key.LastIndex), key.LastIndex,
                                      key.lowerWord);

//            if (Key.Length == 1 && nextMoreKey.Length == 1)
//            {
//                var tmp1 = More;
//                var node = new LinkedNode(Key)
//                {
//                    More = new KeyNode(Key, Value)
//                    {
//                        More = new KeyNode(nextMoreKey, value)
//                        {
//                            More = tmp1
//                        }
//                    },
//                };
//                return node;
//            }

            Key.LastIndex = MathClamp(Key.StartIndex + matchingChars - 1, Key.StartIndex, Key.LastIndex);
            var newNode = new LinkedNode(Key)
            {
                Next = new KeyNode(nextKey, Value)
                {
                    More = new KeyNode(nextMoreKey, value)
                },
                More = tmp
            };

            return(newNode);
        }