Ejemplo n.º 1
0
        /// <summary>
        /// Implements an optimized algorithm for the following function
        ///    node-set difference(node-set, node-set)
        /// Uses document identification and binary search,
        /// based on the fact that a node-set is always in document order.
        /// </summary>
        /// <param name="nodeset1">An input nodeset</param>
        /// <param name="nodeset2">Another input nodeset</param>
        /// <returns>The those nodes that are in the node set
        /// passed as the first argument that are not in the node set
        /// passed as the second argument.</returns>
        /// <author>Dimitre Novatchev</author>

        private XPathNodeIterator Difference2(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2)
        {
            List <DocPair> arDocs = new List <DocPair>();

            List <XPathNavigator> arNodes2 = new List <XPathNavigator>(nodeset2.Count);

            while (nodeset2.MoveNext())
            {
                arNodes2.Add(nodeset2.Current.Clone());
            }

            AuxExslt.FindDocs(arNodes2, arDocs);

            XPathNavigatorIterator enlResult = new XPathNavigatorIterator();

            while (nodeset1.MoveNext())
            {
                XPathNavigator currNode = nodeset1.Current;

                if (!AuxExslt.FindNode(arNodes2, arDocs, currNode))
                {
                    enlResult.Add(currNode.Clone());
                }
            }

            enlResult.Reset();
            return(enlResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implements
        ///    boolean hassamenode2(node-set, node-set)
        ///
        /// Optimized by using a document identification and
        /// binary search algorithm
        /// </summary>
        /// <param name="nodeset1">The first nodeset</param>
        /// <param name="nodeset2">The second nodeset</param>
        /// <returns>true if both nodeset contain
        /// at least one of the same node</returns>
        /// <author>Dimitre Novatchev</author>
        private bool HasSameNode2(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2)
        {
            XPathNodeIterator it1 =
                (nodeset1.Count > nodeset2.Count) ? nodeset1
                                : nodeset2;

            XPathNodeIterator it2 =
                (nodeset1.Count > nodeset2.Count) ? nodeset2
                                : nodeset1;

            List <DocPair> arDocs = new List <DocPair>();

            List <XPathNavigator> arNodes1 = new List <XPathNavigator>(it1.Count);

            while (it1.MoveNext())
            {
                arNodes1.Add(it1.Current.Clone());
            }

            AuxExslt.FindDocs(arNodes1, arDocs);

            XPathNavigatorIterator enlResult = new XPathNavigatorIterator();

            while (it2.MoveNext())
            {
                XPathNavigator currNode = it2.Current;

                if (AuxExslt.FindNode(arNodes1, arDocs, currNode))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Implements the following function
        ///    boolean subset(node-set, node-set)
        /// This is an optimized version, using document identification
        /// and binary search techniques.
        /// </summary>
        /// <param name="nodeset1">An input nodeset</param>
        /// <param name="nodeset2">Another input nodeset</param>
        /// <returns>True if all the nodes in the first nodeset are contained
        /// in the second nodeset</returns>
        /// <author>Dimitre Novatchev</author>
        /// <remarks>THIS FUNCTION IS NOT PART OF EXSLT!!!</remarks>
        public bool Subset2(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2)
        {
            List <DocPair> arDocs = new List <DocPair>();

            List <XPathNavigator> arNodes2 = new List <XPathNavigator>(nodeset2.Count);

            while (nodeset2.MoveNext())
            {
                arNodes2.Add(nodeset2.Current.Clone());
            }

            AuxExslt.FindDocs(arNodes2, arDocs);

            while (nodeset1.MoveNext())
            {
                XPathNavigator currNode = nodeset1.Current;

                if (!AuxExslt.FindNode(arNodes2, arDocs, currNode))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Implements the following function
        ///   node-set intersection3(node-set, node-set)
        ///
        ///   This is an optimisation of the initial implementation
        ///   of intersection(). It uses a document identification
        ///   and a binary search algorithm, based on the fact
        ///   that a node-set is always in document order.
        /// </summary>
        /// <param name="nodeset1">The first node-set</param>
        /// <param name="nodeset2">The second node-set</param>
        /// <returns>The node-set, which is the intersection
        ///          of nodeset1 and nodeset2
        /// </returns>
        /// <author>Dimitre Novatchev</author>

        private XPathNodeIterator Intersection3(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2)
        {
            XPathNodeIterator it1 =
                (nodeset1.Count > nodeset2.Count) ? nodeset1
                                : nodeset2;

            XPathNodeIterator it2 =
                (nodeset1.Count > nodeset2.Count) ? nodeset2
                                : nodeset1;

            List <DocPair> arDocs = new List <DocPair>();

            List <XPathNavigator> arNodes1 = new List <XPathNavigator>(it1.Count);

            while (it1.MoveNext())
            {
                arNodes1.Add(it1.Current.Clone());
            }

            AuxExslt.FindDocs(arNodes1, arDocs);

            XPathNavigatorIterator enlResult = new XPathNavigatorIterator();

            while (it2.MoveNext())
            {
                XPathNavigator currNode = it2.Current;

                if (AuxExslt.FindNode(arNodes1, arDocs, currNode))
                {
                    enlResult.Add(currNode.Clone());
                }
            }

            enlResult.Reset();
            return(enlResult);
        }