You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2016/11/10 11:33:24 UTC

[13/58] [abbrv] lucenenet git commit: Core.Support.TreeSet: Implemented ISet, since it was missing from the original C5 implementation

Core.Support.TreeSet: Implemented ISet<T>, since it was missing from the original C5 implementation


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/a0f684de
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/a0f684de
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/a0f684de

Branch: refs/heads/grouping
Commit: a0f684de9dbf46a7f9a0119609318584b6c16011
Parents: 5f19852
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Nov 6 20:28:27 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Mon Nov 7 18:44:12 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Support/TreeSet.cs | 185 +++++++++++++++++++++++++++-
 1 file changed, 184 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a0f684de/src/Lucene.Net.Core/Support/TreeSet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/TreeSet.cs b/src/Lucene.Net.Core/Support/TreeSet.cs
index 4ce8831..b77d711 100644
--- a/src/Lucene.Net.Core/Support/TreeSet.cs
+++ b/src/Lucene.Net.Core/Support/TreeSet.cs
@@ -21,6 +21,7 @@
 
 using Lucene.Net.Support.C5;
 using System;
+using System.Linq;
 using SCG = System.Collections.Generic;
 
 namespace Lucene.Net.Support
@@ -40,7 +41,7 @@ namespace Lucene.Net.Support
     /// leak possible with other usage modes.</i>
     /// </summary>
     [Serializable]
-    public class TreeSet<T> : SequencedBase<T>, IIndexedSorted<T>, IPersistentSorted<T>
+    public class TreeSet<T> : SequencedBase<T>, IIndexedSorted<T>, IPersistentSorted<T>, SCG.ISet<T>
     {
         #region Fields
 
@@ -539,6 +540,188 @@ namespace Lucene.Net.Support
 
         #endregion
 
+        #region ISet<T> Members
+
+        /// <summary>
+        /// Modifies the current <see cref="TreeSet{T}"/> object to contain all elements that are present in itself, the specified collection, or both.
+        /// </summary>
+        /// <param name="other"></param>
+        public void UnionWith(SCG.IEnumerable<T> other)
+        {
+            AddAll(other);
+        }
+
+        /// <summary>
+        /// Not implemented
+        /// </summary>
+        /// <param name="other"></param>
+        public void IntersectWith(SCG.IEnumerable<T> other)
+        {
+            throw new NotImplementedException("Implement as required");
+        }
+
+        /// <summary>
+        /// Not implemented
+        /// </summary>
+        /// <param name="other"></param>
+        public void ExceptWith(SCG.IEnumerable<T> other)
+        {
+            throw new NotImplementedException("Implement as required");
+        }
+
+        /// <summary>
+        /// Not implemented
+        /// </summary>
+        /// <param name="other"></param>
+        public void SymmetricExceptWith(SCG.IEnumerable<T> other)
+        {
+            throw new NotImplementedException("Implement as required");
+        }
+
+        /// <summary>
+        /// Determines whether a <see cref="TreeSet{T}"/> object is a subset of the specified collection.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/> object.</param>
+        /// <returns><c>true</c> if the <see cref="TreeSet{T}"/> object is a subset of other; otherwise, <c>false</c>.</returns>
+        public bool IsSubsetOf(SCG.IEnumerable<T> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException("other");
+            }
+            if (this.Count == 0)
+            {
+                return true;
+            }
+            // we just need to return true if the other set
+            // contains all of the elements of the this set,
+            // but we need to use the comparison rules of the current set.
+            int foundCount, unfoundCount;
+            this.GetFoundAndUnfoundCounts(other, out foundCount, out unfoundCount);
+            return foundCount == this.Count;
+        }
+
+        /// <summary>
+        /// Determines whether a <see cref="TreeSet{T}"/> object is a superset of the specified collection.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/> object.</param>
+        /// <returns><c>true</c> if the <see cref="TreeSet{T}"/> object is a superset of other; otherwise, <c>false</c>.</returns>
+        public bool IsSupersetOf(SCG.IEnumerable<T> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException("other");
+            }
+            ICollection<T> is2 = other as ICollection<T>;
+            if (is2 != null && is2.Count == 0)
+            {
+                return true;
+            }
+            return this.ContainsAll(other);
+        }
+
+        /// <summary>
+        /// Determines whether a <see cref="TreeSet{T}"/> object is a proper superset of the specified collection.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/> object.</param>
+        /// <returns><c>true</c> if the <see cref="TreeSet{T}"/> object is a proper superset of other; otherwise, <c>false</c>.</returns>
+        public bool IsProperSupersetOf(SCG.IEnumerable<T> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException("other");
+            }
+            if (this.Count == 0)
+            {
+                return false;
+            }
+            ICollection<T> is2 = other as ICollection<T>;
+            if (is2 != null && is2.Count == 0)
+            {
+                return true;
+            }
+            int foundCount, unfoundCount;
+            this.GetFoundAndUnfoundCounts(other, out foundCount, out unfoundCount);
+            return foundCount < this.Count && unfoundCount == 0;
+        }
+
+        /// <summary>
+        /// Determines whether a <see cref="TreeSet{T}"/> object is a proper subset of the specified collection.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/> object.</param>
+        /// <returns><c>true</c> if the <see cref="TreeSet{T}"/> object is a proper subset of other; otherwise, <c>false</c>.</returns>
+        public bool IsProperSubsetOf(SCG.IEnumerable<T> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException("other");
+            }
+            ICollection<T> is2 = other as ICollection<T>;
+            if (is2 != null && this.Count == 0)
+            {
+                return (is2.Count > 0);
+            }
+            // we just need to return true if the other set
+            // contains all of the elements of the this set plus at least one more,
+            // but we need to use the comparison rules of the current set.
+            int foundCount, unfoundCount;
+            this.GetFoundAndUnfoundCounts(other, out foundCount, out unfoundCount);
+            return foundCount == this.Count && unfoundCount > 0;
+        }
+
+        /// <summary>
+        /// Determines whether the current <see cref="TreeSet{T}"/> object and a specified collection share common elements.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/> object.</param>
+        /// <returns><c>true</c> if the <see cref="TreeSet{T}"/> object and other share at least one common element; otherwise, <c>false</c>.</returns>
+        public bool Overlaps(SCG.IEnumerable<T> other)
+        {
+            if (other == null)
+            {
+                throw new ArgumentNullException("other");
+            }
+            if (this.Count != 0)
+            {
+                foreach (var local in other)
+                {
+                    if (this.Contains(local))
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// Determines whether the current <see cref="TreeSet{T}"/> and the specified collection contain the same elements.
+        /// </summary>
+        /// <param name="other">The collection to compare to the current <see cref="TreeSet{T}"/>.</param>
+        /// <returns><c>true</c> if the current <see cref="TreeSet{T}"/> is equal to other; otherwise, <c>false</c>.</returns>
+        public bool SetEquals(SCG.IEnumerable<T> other)
+        {
+            return this.Count.Equals(other.Count()) && this.ContainsAll(other);
+        }
+
+        private void GetFoundAndUnfoundCounts(SCG.IEnumerable<T> other, out int foundCount, out int unfoundCount)
+        {
+            foundCount = 0;
+            unfoundCount = 0;
+            foreach (var item in other)
+            {
+                if (this.Contains(item))
+                {
+                    foundCount++;
+                }
+                else
+                {
+                    unfoundCount++;
+                }
+            }
+        }
+
+        #endregion
+
         #region IEnumerable<T> Members
 
         /// <summary>