This project is read-only.
1

Closed

Bug in TermPart.cs

description

There are 2 lines missing in this method, se comment (These lines are missing)
        public int Compare(TermPart x, TermPart y) {

            // if two nodes have the same parent, then compare by weight, then by path 
            // /1/2/3 vs /1/2/4 => 3 vs 4
            if (x.Path == y.Path) {
                var weight = y.Weight.CompareTo(x.Weight);

                if (weight != 0) {
                    return weight;
                }

                // if same parent path and same weight, compare by name
                return String.CompareOrdinal(x.Name, y.Name);
            } 

            // if two nodes have different parents

            //    if the two nodes have the same root, the deeper is after (i.e. one starts with the other)
            //    /1/2 vs /1/2/3 => /1/2 first

            if (x.FullPath.StartsWith(y.FullPath, StringComparison.OrdinalIgnoreCase)) {
                return 1;
            }

            if (y.FullPath.StartsWith(x.FullPath, StringComparison.OrdinalIgnoreCase)) {
                return -1;
            }

            //    otherwise compare first none matching parent
            //    /1/2 vs /1/3 => 2 vs 3
            //    /2/3 vs /4 => 2 vs 4

            var xPath = x.FullPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var yPath = y.FullPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            string xFullPath = "/", yFullPath = "/";

            for(int i=0; i< Math.Min(xPath.Length, yPath.Length); i++) {
                xFullPath += xPath[i];
                yFullPath += yPath[i];

                if(!xFullPath.Equals(yFullPath,StringComparison.OrdinalIgnoreCase)) {
                    var xParent = _index[xFullPath];
                    var yParent = _index[yFullPath];

                    return Compare(xParent, yParent);
                }
                // These lines are missing
                xFullPath += "/";
                yFullPath += "/";

            }

            return 0;
        }
Closed Feb 20, 2013 at 12:58 AM by sebastienros
Fixed

comments