Пример #1
0
        /// <summary>
        /// Union algorithm:
        /// 1. Add both sequences of items to a newly created sequence
        /// 2. Sort the items based on document position
        /// 3. Renumber positions in this new unionized sequence
        /// </summary>
        internal NodeSequence Union(ProcessingContext context, NodeSequence otherSeq)
        {
            NodeSequence seq = context.CreateSequence();

            SortedBuffer <QueryNode, QueryNodeComparer> buff = new SortedBuffer <QueryNode, QueryNodeComparer>(staticQueryNodeComparerInstance);

            for (int i = 0; i < this.count; ++i)
            {
                buff.Add(this.items[i].Node);
            }

            for (int i = 0; i < otherSeq.count; ++i)
            {
                buff.Add(otherSeq.items[i].Node);
            }

            for (int i = 0; i < buff.Count; ++i)
            {
                seq.Add(buff[i]);
            }

            seq.RenumberItems();
            return(seq);

            /*
             * // PERF, [....], I think we can do the merge ourselves and avoid the sort.
             * //               Need to verify that the sequences are always in document order.
             * for(int i = 0; i < this.count; ++i)
             * {
             *  seq.AddCopy(ref this.items[i]);
             * }
             *
             * for(int i = 0; i < otherSeq.count; ++i)
             * {
             *  seq.AddCopy(ref otherSeq.items[i]);
             * }
             *
             * seq.SortNodes();
             * seq.RemoveDuplicates();
             *
             * return seq;
             */
        }
        internal NodeSequence Union(ProcessingContext context, NodeSequence otherSeq)
        {
            NodeSequence sequence = context.CreateSequence();
            SortedBuffer <QueryNode, QueryNodeComparer> buffer = new SortedBuffer <QueryNode, QueryNodeComparer>(staticQueryNodeComparerInstance);

            for (int i = 0; i < this.count; i++)
            {
                buffer.Add(this.items[i].Node);
            }
            for (int j = 0; j < otherSeq.count; j++)
            {
                buffer.Add(otherSeq.items[j].Node);
            }
            for (int k = 0; k < buffer.Count; k++)
            {
                sequence.Add(buffer[k]);
            }
            sequence.RenumberItems();
            return(sequence);
        }