Return-Path: X-Original-To: apmail-lucenenet-commits-archive@www.apache.org Delivered-To: apmail-lucenenet-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E0E011140A for ; Mon, 15 Sep 2014 22:52:52 +0000 (UTC) Received: (qmail 71621 invoked by uid 500); 15 Sep 2014 22:52:52 -0000 Delivered-To: apmail-lucenenet-commits-archive@lucenenet.apache.org Received: (qmail 71503 invoked by uid 500); 15 Sep 2014 22:52:52 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 71347 invoked by uid 99); 15 Sep 2014 22:52:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Sep 2014 22:52:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7851DA148EA; Mon, 15 Sep 2014 22:52:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: synhershko@apache.org To: commits@lucenenet.apache.org Date: Mon, 15 Sep 2014 22:52:55 -0000 Message-Id: <147e5caec57e40d2aab8269097577705@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/13] git commit: Fixed TestOpenBitSet.TestSmall Fixed TestOpenBitSet.TestSmall Fixed problems from Java->C# conversion for OpenBitSet's Fill and Set methods. Found that Java's BitSet.Equals does a deep compare, while C#'s does a reference comparison; added a deep equals extension method to BitArray to support this case. We still need to modify occurrences of BitArray.Equals outside of this testcase. Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/2603ae8b Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/2603ae8b Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/2603ae8b Branch: refs/heads/master Commit: 2603ae8b51d1b3c640a5b19efeacf91cda61c0d4 Parents: fd5e63c Author: Prad Nelluru Authored: Thu Sep 11 14:50:23 2014 -0700 Committer: Prad Nelluru Committed: Thu Sep 11 14:50:23 2014 -0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Support/BitSetSupport.cs | 35 +++++++++++++++++++- src/Lucene.Net.Core/Util/OpenBitSet.cs | 5 +-- .../core/Util/TestOpenBitSet.cs | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/src/Lucene.Net.Core/Support/BitSetSupport.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Support/BitSetSupport.cs b/src/Lucene.Net.Core/Support/BitSetSupport.cs index 46ae2b4..7b816d0 100644 --- a/src/Lucene.Net.Core/Support/BitSetSupport.cs +++ b/src/Lucene.Net.Core/Support/BitSetSupport.cs @@ -21,6 +21,7 @@ using System; using System.Collections; +using Lucene.Net.Util; namespace Lucene.Net.Support { @@ -228,7 +229,6 @@ namespace Lucene.Net.Support } } - // Emulates the Java BitSet.Get() method. // Prevents exceptions from being thrown when the index is too high. public static bool SafeGet(this BitArray a, int loc) @@ -262,5 +262,38 @@ namespace Lucene.Net.Support } } } + + //Does a deep comparison of two BitArrays + public static bool BitWiseEquals(this BitArray bitsA, BitArray bitsB) + { + if (bitsA == bitsB) + return true; + if (bitsA.Count != bitsB.Count) + return false; + + for (int i = 0; i < bitsA.Count; i++) + { + if (bitsA[i] != bitsB[i]) + return false; + } + + return true; + } + + //Compares a BitArray with an OpenBitSet + public static bool Equals(BitArray a, OpenBitSet b) + { + var bitArrayCardinality = a.Cardinality(); + if (bitArrayCardinality != b.Cardinality()) + return false; + + for (int i = 0; i < bitArrayCardinality; i++) + { + if (a.Get(i) != b.Get(i)) + return false; + } + + return true; + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/src/Lucene.Net.Core/Util/OpenBitSet.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Util/OpenBitSet.cs b/src/Lucene.Net.Core/Util/OpenBitSet.cs index 8e5f698..2e3d265 100644 --- a/src/Lucene.Net.Core/Util/OpenBitSet.cs +++ b/src/Lucene.Net.Core/Util/OpenBitSet.cs @@ -344,7 +344,7 @@ namespace Lucene.Net.Util int endWord = ExpandingWordNum(endIndex - 1); long startmask = -1L << (int)startIndex; - long endmask = -(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap + long endmask = (long)(0xffffffffffffffffUL >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap if (startWord == endWord) { @@ -611,6 +611,7 @@ namespace Lucene.Net.Util { return; } + int startWord = (int)(startIndex >> 6); // since endIndex is one past the end, this is index of the last @@ -628,7 +629,7 @@ namespace Lucene.Net.Util //LUCENE TO-DO long startmask = -1L << (int)startIndex; - long endmask = -(int)((uint)1L >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap + long endmask = (long)(0xffffffffffffffffUL >> (int)-endIndex); // 64-(endIndex&0x3f) is the same as -endIndex due to wrap if (startWord == endWord) { http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2603ae8b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs index 03959df..db033a1 100644 --- a/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs +++ b/src/Lucene.Net.Tests/core/Util/TestOpenBitSet.cs @@ -267,7 +267,7 @@ namespace Lucene.Net.Util if (a0 != null) { - Assert.AreEqual(a.Equals(a0), b.Equals(b0)); + Assert.AreEqual(a.BitWiseEquals(a0), b.Equals(b0)); Assert.AreEqual(a.Cardinality(), b.Cardinality());