473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
namespace RemoveDuplicate BitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
arr.Add(myBA1);

myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLi ne(i++);
DisplayBitArray (x);
}

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

Console.ReadLin e();
}//Main

public static void DisplayBitArray (IEnumerable myList)
{
int i = 0;
System.Collecti ons.IEnumerator myEnumerator =
myList.GetEnume rator();
while ( myEnumerator.Mo veNext() )
{
Console.WriteLi ne( "\t[{0}]:\t{1}", i++,
myEnumerator.Cu rrent );
Console.WriteLi ne();
}
}//DisplayBitArray

public static void RemoveDuplicate BitArraysinArra yList(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.Index Of(arr[i], i+1);
while( index>i )
{
arr.Remove(inde x);
if( i<(arr.Count-1) )
{
index=arr.Index Of(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicate BitArraysinArra yList

}//Class1

}//namespace RemoveDuplicate BitArrays

Nov 16 '05 #1
9 5101
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(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
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(fa lse);

// Set values normally.
myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);

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

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Collecti ons;
namespace RemoveDuplicate BitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
arr.Add(myBA1);

myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLi ne(i++);
DisplayBitArray (x);
}

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

Console.ReadLin e();
}//Main

public static void DisplayBitArray (IEnumerable myList)
{
int i = 0;
System.Collecti ons.IEnumerator myEnumerator =
myList.GetEnume rator();
while ( myEnumerator.Mo veNext() )
{
Console.WriteLi ne( "\t[{0}]:\t{1}", i++,
myEnumerator.Cu rrent );
Console.WriteLi ne();
}
}//DisplayBitArray

public static void RemoveDuplicate BitArraysinArra yList(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.Index Of(arr[i], i+1);
while( index>i )
{
arr.Remove(inde x);
if( i<(arr.Count-1) )
{
index=arr.Index Of(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicate BitArraysinArra yList

}//Class1

}//namespace RemoveDuplicate BitArrays

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 RemoveDuplicate BitArrays below)

I pinched this code from the net - here I assume "index=arr.Inde xOf(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(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
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(fa lse);

// Set values normally.
myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);

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

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Collecti ons;
namespace RemoveDuplicate BitArrays
{
class Class1
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
BitArray myBA1 = new BitArray( 4 );
myBA1.SetAll(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
arr.Add(myBA1);

myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);
i = 0;
foreach (BitArray x in arr)
{
Console.WriteLi ne(i++);
DisplayBitArray (x);
}

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

Console.ReadLin e();
}//Main

public static void DisplayBitArray (IEnumerable myList)
{
int i = 0;
System.Collecti ons.IEnumerator myEnumerator =
myList.GetEnume rator();
while ( myEnumerator.Mo veNext() )
{
Console.WriteLi ne( "\t[{0}]:\t{1}", i++,
myEnumerator.Cu rrent );
Console.WriteLi ne();
}
}//DisplayBitArray

public static void RemoveDuplicate BitArraysinArra yList(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.Index Of(arr[i], i+1);
while( index>i )
{
arr.Remove(inde x);
if( i<(arr.Count-1) )
{
index=arr.Index Of(arr[i], i+1);
}
else
{
index=-1;
}
}
}
} //RemoveDuplicate BitArraysinArra yList

}//Class1

}//namespace RemoveDuplicate BitArrays


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.co m

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:FD******** *************** ***********@mic rosoft.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 RemoveDuplicate BitArrays below)

I pinched this code from the net - here I assume
"index=arr.Inde xOf(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(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
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(fa lse);

// Set values normally.
myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);

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

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Collecti ons;
> namespace RemoveDuplicate BitArrays
> {
> class Class1
> {
> static void Main(string[] args)
> {
> ArrayList arr = new ArrayList();
> BitArray myBA1 = new BitArray( 4 );
> myBA1.SetAll(fa lse);
>
> myBA1.Set(0,fal se);
> myBA1.Set(1,fal se);
> myBA1.Set(2,fal se);
> myBA1.Set(3,tru e);
> arr.Add(myBA1);
>
> myBA1.SetAll(fa lse);
> myBA1.Set(0,fal se);
> myBA1.Set(1,tru e);
> myBA1.Set(2,fal se);
> myBA1.Set(3,fal se);
> arr.Add(myBA1);
>
>
> i = 0;
> foreach (BitArray x in arr)
> {
> Console.WriteLi ne(i++);
> DisplayBitArray (x);
> }
>
> //Alternative way to access the BitArrays in the ArrayList
> // for(int j=0; j<(arr.Count-1); j++)
> // {
> // Console.WriteLi ne("Array element is {0}",????); Not
> sure
> how to
> // access bits of bitarray here
> // }
>
> Console.ReadLin e();
> }//Main
>
>
>
> public static void DisplayBitArray (IEnumerable myList)
> {
> int i = 0;
> System.Collecti ons.IEnumerator myEnumerator =
> myList.GetEnume rator();
> while ( myEnumerator.Mo veNext() )
> {
> Console.WriteLi ne( "\t[{0}]:\t{1}", i++,
> myEnumerator.Cu rrent );
> Console.WriteLi ne();
> }
> }//DisplayBitArray
>
> public static void RemoveDuplicate BitArraysinArra yList(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.Index Of(arr[i], i+1);
> while( index>i )
> {
> arr.Remove(inde x);
> if( i<(arr.Count-1) )
> {
> index=arr.Index Of(arr[i], i+1);
> }
> else
> {
> index=-1;
> }
> }
> }
> } //RemoveDuplicate BitArraysinArra yList
>
> }//Class1
>
> }//namespace RemoveDuplicate BitArrays
>


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.co m

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:FD******** *************** ***********@mic rosoft.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 RemoveDuplicate BitArrays below)

I pinched this code from the net - here I assume
"index=arr.Inde xOf(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(fa lse);

myBA1.Set(0,fal se);
myBA1.Set(1,fal se);
myBA1.Set(2,fal se);
myBA1.Set(3,tru e);
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(fa lse);

// Set values normally.
myBA1.SetAll(fa lse);
myBA1.Set(0,fal se);
myBA1.Set(1,tru e);
myBA1.Set(2,fal se);
myBA1.Set(3,fal se);
arr.Add(myBA1);

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

"vbportal" <vb******@discu ssions.microsof t.com> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Collecti ons;
> namespace RemoveDuplicate BitArrays
> {
> class Class1
> {
> static void Main(string[] args)
> {
> ArrayList arr = new ArrayList();
> BitArray myBA1 = new BitArray( 4 );
> myBA1.SetAll(fa lse);
>
> myBA1.Set(0,fal se);
> myBA1.Set(1,fal se);
> myBA1.Set(2,fal se);
> myBA1.Set(3,tru e);
> arr.Add(myBA1);
>
> myBA1.SetAll(fa lse);
> myBA1.Set(0,fal se);
> myBA1.Set(1,tru e);
> myBA1.Set(2,fal se);
> myBA1.Set(3,fal se);
> arr.Add(myBA1);
>
>
> i = 0;
> foreach (BitArray x in arr)
> {
> Console.WriteLi ne(i++);
> DisplayBitArray (x);
> }
>
> //Alternative way to access the BitArrays in the ArrayList
> // for(int j=0; j<(arr.Count-1); j++)
> // {
> // Console.WriteLi ne("Array element is {0}",????); Not
> sure
> how to
> // access bits of bitarray here
> // }
>
> Console.ReadLin e();
> }//Main
>
>
>
> public static void DisplayBitArray (IEnumerable myList)
> {
> int i = 0;
> System.Collecti ons.IEnumerator myEnumerator =
> myList.GetEnume rator();
> while ( myEnumerator.Mo veNext() )
> {
> Console.WriteLi ne( "\t[{0}]:\t{1}", i++,
> myEnumerator.Cu rrent );
> Console.WriteLi ne();
> }
> }//DisplayBitArray
>
> public static void RemoveDuplicate BitArraysinArra yList(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.Index Of(arr[i], i+1);
> while( index>i )
> {
> arr.Remove(inde x);
> if( i<(arr.Count-1) )
> {
> index=arr.Index Of(arr[i], i+1);
> }
> else
> {
> index=-1;
> }
> }
> }
> } //RemoveDuplicate BitArraysinArra yList
>
> }//Class1
>
> }//namespace RemoveDuplicate BitArrays
>


Nov 16 '05 #5
vbportal <vb******@discu ssions.microsof t.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.co m>
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******@discu ssions.microsof t.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
vbportal <vb******@discu ssions.microsof t.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Hi Jon,
The method "RemoveDuplicat eBitArraysinArr ayList" 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******@discu ssions.microsof t.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #9
vbportal <vb******@discu ssions.microsof t.com> wrote:
The method "RemoveDuplicat eBitArraysinArr ayList" 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.co m>
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
16989
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 through a dictionary, looking for things, then remove them.... John
24
4403
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 we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
3
1315
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 Response.Cookies.Remove("username") If Not Request.Cookies("password") Is Nothing Then Response.Cookies.Remove("password")
7
1754
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 the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
6
6116
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 more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
4
1454
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 easiest way to add all of the +contents+ of one arraylist to another.
12
20806
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 a function that processes the array so that any duplicate values are eliminated. Write an output function that prints out the values of the array. You can assume that there are no more than 20 integers in the input. But there may be less. Zero...
1
2264
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
1798
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 have any duplicates? This might be bass-ackwards, but I'm trying to get something to work really quick that I don't have time right now to research. I am able to sort but I keep getting index errors, which I assume are happening when I get to the...
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.