473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Removing duplicate BitArrays in an ArrayList

Hi,
I would like to add BitArrays to an ArrayList and then remove any duplicates
- can someone please help me forward. I seem to have (at leaset ;-) )2
problems/lack of understanding (see test code below):
(a)When adding BitArrays to the ArrayList and then looping through the
ArrayList I seem to access only the latest added BitArray and I'm not exactly
clear on best way to access each BItArray in the ArrayList

(b)When I try to remove duplicate BItArrays, I seem only to identify the
current index as being "the duplicate" (I am assuming IndexOf and the Equals
which it uses should function here).

Thanks in advance,
Vjeko

using System;
using System.Collections;
namespace RemoveDuplicateBitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLine(i++);
DisplayBitArray(x);
}

//Alternative way to access the BitArrays in the ArrayList
// for(int j=0; j<(arr.Count-1); j++)
// {
// Console.WriteLine("Array element is {0}",????); Not sure
how to
// access bits of bitarray here
// }

Console.ReadLine();
}//Main

public static void DisplayBitArray(IEnumerable myList)
{
int i = 0;
System.Collections.IEnumerator myEnumerator =
myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
Console.WriteLine( "\t[{0}]:\t{1}", i++,
myEnumerator.Current );
Console.WriteLine();
}
}//DisplayBitArray

public static void RemoveDuplicateBitArraysinArrayList(ArrayList arr)
{
//Step through ArrayList such that
//BitArray element is taken and XOR with each element further down
//the ArrayList if result is false, remove it as it is a duplicate

int index;

for(int i=0; i<(arr.Count-1); i++)
{
index=arr.IndexOf(arr[i], i+1);
while( index>i )
{
arr.Remove(index);
if( i<(arr.Count-1) )
{
index=arr.IndexOf(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicateBitArraysinArrayList

}//Class1

}//namespace RemoveDuplicateBitArrays

Nov 16 '05 #1
9 5070
vbportal,

The problem is that you are adding the same bit array over and over
again. What you need to do is create a new bit array before you set the
values again, like so:

ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

// Need to create a new one here, or you will add the same reference to the
array list.
myBA1 = new BitArray(4);
myBA1.SetAll(false);

// Set values normally.
myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Hi,
I would like to add BitArrays to an ArrayList and then remove any
duplicates
- can someone please help me forward. I seem to have (at leaset ;-) )2
problems/lack of understanding (see test code below):
(a)When adding BitArrays to the ArrayList and then looping through the
ArrayList I seem to access only the latest added BitArray and I'm not
exactly
clear on best way to access each BItArray in the ArrayList

(b)When I try to remove duplicate BItArrays, I seem only to identify the
current index as being "the duplicate" (I am assuming IndexOf and the
Equals
which it uses should function here).

Thanks in advance,
Vjeko

using System;
using System.Collections;
namespace RemoveDuplicateBitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLine(i++);
DisplayBitArray(x);
}

//Alternative way to access the BitArrays in the ArrayList
// for(int j=0; j<(arr.Count-1); j++)
// {
// Console.WriteLine("Array element is {0}",????); Not sure
how to
// access bits of bitarray here
// }

Console.ReadLine();
}//Main

public static void DisplayBitArray(IEnumerable myList)
{
int i = 0;
System.Collections.IEnumerator myEnumerator =
myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
Console.WriteLine( "\t[{0}]:\t{1}", i++,
myEnumerator.Current );
Console.WriteLine();
}
}//DisplayBitArray

public static void RemoveDuplicateBitArraysinArrayList(ArrayList
arr)
{
//Step through ArrayList such that
//BitArray element is taken and XOR with each element further down
//the ArrayList if result is false, remove it as it is a duplicate

int index;

for(int i=0; i<(arr.Count-1); i++)
{
index=arr.IndexOf(arr[i], i+1);
while( index>i )
{
arr.Remove(index);
if( i<(arr.Count-1) )
{
index=arr.IndexOf(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicateBitArraysinArrayList

}//Class1

}//namespace RemoveDuplicateBitArrays

Nov 16 '05 #2
Hi Nicholas - thanks for the answer - this sorted out my first problem.
I'm still not sure how to solve (b) i.e. for the removal of duplicate
BitArrays
(see subroutine RemoveDuplicateBitArrays below)

I pinched this code from the net - here I assume "index=arr.IndexOf(arr[i],
i+1);" will check for duplicate BitArrays (where as I read IndexOf uses
Equals for the equality check)starting at present ArrayList index and
stepping one ahead till end of ArrayList (duplicates are identified by
"index" and removed - but it doesn't work - any clue (I must admit I'm quite
new to C# and my debugging skills are far from good - but we have to start
somewhere ;-) ?

If it's not too much bother could you also indicate if there is any good
source of info how BitArrays fit in ArrayLists from a Collections perspective
- I seem to have a problem understanding how to address the BItArray bits /
how IEnumerator ties in (have checked quite a few books etc but haven't found
a satisfactory explanation.

Thanks,Vjeko

"Nicholas Paldino [.NET/C# MVP]" wrote:
vbportal,

The problem is that you are adding the same bit array over and over
again. What you need to do is create a new bit array before you set the
values again, like so:

ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

// Need to create a new one here, or you will add the same reference to the
array list.
myBA1 = new BitArray(4);
myBA1.SetAll(false);

// Set values normally.
myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Hi,
I would like to add BitArrays to an ArrayList and then remove any
duplicates
- can someone please help me forward. I seem to have (at leaset ;-) )2
problems/lack of understanding (see test code below):
(a)When adding BitArrays to the ArrayList and then looping through the
ArrayList I seem to access only the latest added BitArray and I'm not
exactly
clear on best way to access each BItArray in the ArrayList

(b)When I try to remove duplicate BItArrays, I seem only to identify the
current index as being "the duplicate" (I am assuming IndexOf and the
Equals
which it uses should function here).

Thanks in advance,
Vjeko

using System;
using System.Collections;
namespace RemoveDuplicateBitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLine(i++);
DisplayBitArray(x);
}

//Alternative way to access the BitArrays in the ArrayList
// for(int j=0; j<(arr.Count-1); j++)
// {
// Console.WriteLine("Array element is {0}",????); Not sure
how to
// access bits of bitarray here
// }

Console.ReadLine();
}//Main

public static void DisplayBitArray(IEnumerable myList)
{
int i = 0;
System.Collections.IEnumerator myEnumerator =
myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
Console.WriteLine( "\t[{0}]:\t{1}", i++,
myEnumerator.Current );
Console.WriteLine();
}
}//DisplayBitArray

public static void RemoveDuplicateBitArraysinArrayList(ArrayList
arr)
{
//Step through ArrayList such that
//BitArray element is taken and XOR with each element further down
//the ArrayList if result is false, remove it as it is a duplicate

int index;

for(int i=0; i<(arr.Count-1); i++)
{
index=arr.IndexOf(arr[i], i+1);
while( index>i )
{
arr.Remove(index);
if( i<(arr.Count-1) )
{
index=arr.IndexOf(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicateBitArraysinArrayList

}//Class1

}//namespace RemoveDuplicateBitArrays


Nov 16 '05 #3
Vjeko,

I don't know if I would cycle through all of the duplicate bit arrays
the way you are. Since the sizes of the bit arrays are all the same, you
can just place it in a format that is easier to compare.

Basically, since it is four bits, you can copy that to a byte array with
one element. Then, you can just compare the bytes for equality.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
Hi Nicholas - thanks for the answer - this sorted out my first problem.
I'm still not sure how to solve (b) i.e. for the removal of duplicate
BitArrays
(see subroutine RemoveDuplicateBitArrays below)

I pinched this code from the net - here I assume
"index=arr.IndexOf(arr[i],
i+1);" will check for duplicate BitArrays (where as I read IndexOf uses
Equals for the equality check)starting at present ArrayList index and
stepping one ahead till end of ArrayList (duplicates are identified by
"index" and removed - but it doesn't work - any clue (I must admit I'm
quite
new to C# and my debugging skills are far from good - but we have to start
somewhere ;-) ?

If it's not too much bother could you also indicate if there is any good
source of info how BitArrays fit in ArrayLists from a Collections
perspective
- I seem to have a problem understanding how to address the BItArray bits
/
how IEnumerator ties in (have checked quite a few books etc but haven't
found
a satisfactory explanation.

Thanks,Vjeko

"Nicholas Paldino [.NET/C# MVP]" wrote:
vbportal,

The problem is that you are adding the same bit array over and over
again. What you need to do is create a new bit array before you set the
values again, like so:

ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

// Need to create a new one here, or you will add the same reference to
the
array list.
myBA1 = new BitArray(4);
myBA1.SetAll(false);

// Set values normally.
myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
> Hi,
> I would like to add BitArrays to an ArrayList and then remove any
> duplicates
> - can someone please help me forward. I seem to have (at leaset ;-) )2
> problems/lack of understanding (see test code below):
> (a)When adding BitArrays to the ArrayList and then looping through the
> ArrayList I seem to access only the latest added BitArray and I'm not
> exactly
> clear on best way to access each BItArray in the ArrayList
>
> (b)When I try to remove duplicate BItArrays, I seem only to identify
> the
> current index as being "the duplicate" (I am assuming IndexOf and the
> Equals
> which it uses should function here).
>
> Thanks in advance,
> Vjeko
>
> using System;
> using System.Collections;
> namespace RemoveDuplicateBitArrays
> {
> class Class1
> {
> static void Main(string[] args)
> {
> ArrayList arr = new ArrayList();
> BitArray myBA1 = new BitArray( 4 );
> myBA1.SetAll(false);
>
> myBA1.Set(0,false);
> myBA1.Set(1,false);
> myBA1.Set(2,false);
> myBA1.Set(3,true);
> arr.Add(myBA1);
>
> myBA1.SetAll(false);
> myBA1.Set(0,false);
> myBA1.Set(1,true);
> myBA1.Set(2,false);
> myBA1.Set(3,false);
> arr.Add(myBA1);
>
>
> i = 0;
> foreach (BitArray x in arr)
> {
> Console.WriteLine(i++);
> DisplayBitArray(x);
> }
>
> //Alternative way to access the BitArrays in the ArrayList
> // for(int j=0; j<(arr.Count-1); j++)
> // {
> // Console.WriteLine("Array element is {0}",????); Not
> sure
> how to
> // access bits of bitarray here
> // }
>
> Console.ReadLine();
> }//Main
>
>
>
> public static void DisplayBitArray(IEnumerable myList)
> {
> int i = 0;
> System.Collections.IEnumerator myEnumerator =
> myList.GetEnumerator();
> while ( myEnumerator.MoveNext() )
> {
> Console.WriteLine( "\t[{0}]:\t{1}", i++,
> myEnumerator.Current );
> Console.WriteLine();
> }
> }//DisplayBitArray
>
> public static void RemoveDuplicateBitArraysinArrayList(ArrayList
> arr)
> {
> //Step through ArrayList such that
> //BitArray element is taken and XOR with each element further down
> //the ArrayList if result is false, remove it as it is a duplicate
>
> int index;
>
> for(int i=0; i<(arr.Count-1); i++)
> {
> index=arr.IndexOf(arr[i], i+1);
> while( index>i )
> {
> arr.Remove(index);
> if( i<(arr.Count-1) )
> {
> index=arr.IndexOf(arr[i], i+1);
> }
> else
> {
> index=-1;
> }
> }
> }
> } //RemoveDuplicateBitArraysinArrayList
>
> }//Class1
>
> }//namespace RemoveDuplicateBitArrays
>


Nov 16 '05 #4
Hi Nicholas,
The actual BitArrays I need to use are 50bits wide and I need to do a lot
of searches for specific bit patterns in other ArrayLists i.e. I thought
XORing BitArrays would be the fastest. I will consider your advice for the
final solution but could you please indicate if you have any ideas re:
problems identified in my last e-mail ?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Vjeko,

I don't know if I would cycle through all of the duplicate bit arrays
the way you are. Since the sizes of the bit arrays are all the same, you
can just place it in a format that is easier to compare.

Basically, since it is four bits, you can copy that to a byte array with
one element. Then, you can just compare the bytes for equality.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
Hi Nicholas - thanks for the answer - this sorted out my first problem.
I'm still not sure how to solve (b) i.e. for the removal of duplicate
BitArrays
(see subroutine RemoveDuplicateBitArrays below)

I pinched this code from the net - here I assume
"index=arr.IndexOf(arr[i],
i+1);" will check for duplicate BitArrays (where as I read IndexOf uses
Equals for the equality check)starting at present ArrayList index and
stepping one ahead till end of ArrayList (duplicates are identified by
"index" and removed - but it doesn't work - any clue (I must admit I'm
quite
new to C# and my debugging skills are far from good - but we have to start
somewhere ;-) ?

If it's not too much bother could you also indicate if there is any good
source of info how BitArrays fit in ArrayLists from a Collections
perspective
- I seem to have a problem understanding how to address the BItArray bits
/
how IEnumerator ties in (have checked quite a few books etc but haven't
found
a satisfactory explanation.

Thanks,Vjeko

"Nicholas Paldino [.NET/C# MVP]" wrote:
vbportal,

The problem is that you are adding the same bit array over and over
again. What you need to do is create a new bit array before you set the
values again, like so:

ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(false);

myBA1.Set(0,false);
myBA1.Set(1,false);
myBA1.Set(2,false);
myBA1.Set(3,true);
arr.Add(myBA1);

// Need to create a new one here, or you will add the same reference to
the
array list.
myBA1 = new BitArray(4);
myBA1.SetAll(false);

// Set values normally.
myBA1.SetAll(false);
myBA1.Set(0,false);
myBA1.Set(1,true);
myBA1.Set(2,false);
myBA1.Set(3,false);
arr.Add(myBA1);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vbportal" <vb******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
> Hi,
> I would like to add BitArrays to an ArrayList and then remove any
> duplicates
> - can someone please help me forward. I seem to have (at leaset ;-) )2
> problems/lack of understanding (see test code below):
> (a)When adding BitArrays to the ArrayList and then looping through the
> ArrayList I seem to access only the latest added BitArray and I'm not
> exactly
> clear on best way to access each BItArray in the ArrayList
>
> (b)When I try to remove duplicate BItArrays, I seem only to identify
> the
> current index as being "the duplicate" (I am assuming IndexOf and the
> Equals
> which it uses should function here).
>
> Thanks in advance,
> Vjeko
>
> using System;
> using System.Collections;
> namespace RemoveDuplicateBitArrays
> {
> class Class1
> {
> static void Main(string[] args)
> {
> ArrayList arr = new ArrayList();
> BitArray myBA1 = new BitArray( 4 );
> myBA1.SetAll(false);
>
> myBA1.Set(0,false);
> myBA1.Set(1,false);
> myBA1.Set(2,false);
> myBA1.Set(3,true);
> arr.Add(myBA1);
>
> myBA1.SetAll(false);
> myBA1.Set(0,false);
> myBA1.Set(1,true);
> myBA1.Set(2,false);
> myBA1.Set(3,false);
> arr.Add(myBA1);
>
>
> i = 0;
> foreach (BitArray x in arr)
> {
> Console.WriteLine(i++);
> DisplayBitArray(x);
> }
>
> //Alternative way to access the BitArrays in the ArrayList
> // for(int j=0; j<(arr.Count-1); j++)
> // {
> // Console.WriteLine("Array element is {0}",????); Not
> sure
> how to
> // access bits of bitarray here
> // }
>
> Console.ReadLine();
> }//Main
>
>
>
> public static void DisplayBitArray(IEnumerable myList)
> {
> int i = 0;
> System.Collections.IEnumerator myEnumerator =
> myList.GetEnumerator();
> while ( myEnumerator.MoveNext() )
> {
> Console.WriteLine( "\t[{0}]:\t{1}", i++,
> myEnumerator.Current );
> Console.WriteLine();
> }
> }//DisplayBitArray
>
> public static void RemoveDuplicateBitArraysinArrayList(ArrayList
> arr)
> {
> //Step through ArrayList such that
> //BitArray element is taken and XOR with each element further down
> //the ArrayList if result is false, remove it as it is a duplicate
>
> int index;
>
> for(int i=0; i<(arr.Count-1); i++)
> {
> index=arr.IndexOf(arr[i], i+1);
> while( index>i )
> {
> arr.Remove(index);
> if( i<(arr.Count-1) )
> {
> index=arr.IndexOf(arr[i], i+1);
> }
> else
> {
> index=-1;
> }
> }
> }
> } //RemoveDuplicateBitArraysinArrayList
>
> }//Class1
>
> }//namespace RemoveDuplicateBitArrays
>


Nov 16 '05 #5
vbportal <vb******@discussions.microsoft.com> wrote:
The actual BitArrays I need to use are 50bits wide and I need to do a lot
of searches for specific bit patterns in other ArrayLists i.e. I thought
XORing BitArrays would be the fastest. I will consider your advice for the
final solution but could you please indicate if you have any ideas re:
problems identified in my last e-mail ?


If your bit arrays are only 50 bits wide, why not just use a long
instead? That way you can just compare the longs directly. If you need
the convenience of bit array, you could always write a struct which
contains a long and provides methods for access.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Hi Jon and Nicholas,
Thanks a lot for the input - I see that I have overlooked
some obvious alternative solutions and I will dig in these directions
but before doing so, I really want to see at least some working test code
using the idea of BitArrays - for the sake of learning/knowledge/experience
- right now it doesn't work and I don't know why - you know
how that feels. If possible, please give me some pointers towards the
solution to the problems described in my last mail.

Thanks,Vjeko

"Jon Skeet [C# MVP]" wrote:
vbportal <vb******@discussions.microsoft.com> wrote:
The actual BitArrays I need to use are 50bits wide and I need to do a lot
of searches for specific bit patterns in other ArrayLists i.e. I thought
XORing BitArrays would be the fastest. I will consider your advice for the
final solution but could you please indicate if you have any ideas re:
problems identified in my last e-mail ?


If your bit arrays are only 50 bits wide, why not just use a long
instead? That way you can just compare the longs directly. If you need
the convenience of bit array, you could always write a struct which
contains a long and provides methods for access.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
vbportal <vb******@discussions.microsoft.com> wrote:
Hi Jon and Nicholas,
Thanks a lot for the input - I see that I have overlooked
some obvious alternative solutions and I will dig in these directions
but before doing so, I really want to see at least some working test code
using the idea of BitArrays - for the sake of learning/knowledge/experience
- right now it doesn't work and I don't know why - you know
how that feels. If possible, please give me some pointers towards the
solution to the problems described in my last mail.


Which problems, exactly? I'm not exactly sure which bit still needs
sorting out. One thing you might think of doing is deriving a class
from BitArray and overriding Equals and GetHashCode - that might make
the code doing the comparisons a bit easier.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Hi Jon,
The method "RemoveDuplicateBitArraysinArrayList" is not working (See first
post for test code I wrote)

Problem:
(a)"IndexOf" doesn't seem to be doing "what I expect" or maybe I'm not
addressing the BitArrays correctly (I thought BitArray was "inbuilt" so
Equals etc should work & IndexOf should work straight off)

(b)AND/OR your idea about deriving a class from BitArray
to get Equals working has something to do with it if I assumed wrong for (a)
but I'm afraid I'm not sure how to proceed.

"Jon Skeet [C# MVP]" wrote:
vbportal <vb******@discussions.microsoft.com> wrote:
Hi Jon and Nicholas,
Thanks a lot for the input - I see that I have overlooked
some obvious alternative solutions and I will dig in these directions
but before doing so, I really want to see at least some working test code
using the idea of BitArrays - for the sake of learning/knowledge/experience
- right now it doesn't work and I don't know why - you know
how that feels. If possible, please give me some pointers towards the
solution to the problems described in my last mail.


Which problems, exactly? I'm not exactly sure which bit still needs
sorting out. One thing you might think of doing is deriving a class
from BitArray and overriding Equals and GetHashCode - that might make
the code doing the comparisons a bit easier.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9
vbportal <vb******@discussions.microsoft.com> wrote:
The method "RemoveDuplicateBitArraysinArrayList" is not working (See first
post for test code I wrote)

Problem:
(a)"IndexOf" doesn't seem to be doing "what I expect" or maybe I'm not
addressing the BitArrays correctly (I thought BitArray was "inbuilt" so
Equals etc should work & IndexOf should work straight off)
No - BitArray doesn't override Equals, which is why it's not working.
(Admittedly it's slightly odd that it doesn't - it could do a rather
more efficient job of it than you'll be able to.)
(b)AND/OR your idea about deriving a class from BitArray
to get Equals working has something to do with it if I assumed wrong for (a)
but I'm afraid I'm not sure how to proceed.


Just derive your own class from BitArray which overrides Equals and
GetHashCode. Then you need to make sure you use that everywhere instead
of BitArray.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JohnK | last post by:
ok, ya got me here. I'm trying to removing items from a dictionary inside a loop. Obviously using enumeration does not work as that assumes the dictionary stays unchanged. So how so I iterate...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
3
by: Nathan Sokalski | last post by:
I am having trouble removing cookies that I created with my site. Here is the code I am using to try and remove them: If Not Request.Cookies("username") Is Nothing Then...
7
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
4
by: | last post by:
I have three Arraylists that hold strings corresponding to addresses of an e-mail list: ArrayList masterList ArrayList optInToMasterList ArrayList optOutFromMasterList I want to know the...
12
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input into an array. Write...
1
by: PerumalSamy | last post by:
Hi I am having table with more 13 lakhs records. I am having duplicate records in it. i need to remove that. I wrote the following query SELECT *
1
by: AllBeagle | last post by:
Here is what might seem to be an odd request. Does anyone know how I can find a duplicate in an arraylist and delete both the duplicate and the original, leaving me with only the items that didn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.