Jump to content

Can I create an array of bitarrays

- - - - -

  • Please log in to reply
12 replies to this topic

#1
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
:) If so how?
This looks silly:
 BitArray bitArray0 = new BitArray(ped.Length, false);

            BitArray bitArray1 = new BitArray(ped.Length, false);

            BitArray bitArray2 = new BitArray(ped.Length, false);

            BitArray bitArray3 = new BitArray(ped.Length, false);

            BitArray bitArray4 = new BitArray(ped.Length, false);

            BitArray bitArray5 = new BitArray(ped.Length, false);

            BitArray bitArray6 = new BitArray(ped.Length, false);

            

            SymbolNotInBracket(pedigree, '<', out bitArray0);

            SymbolNotInBracket(pedigree, '/', out bitArray1);

            SymbolNotInBracket(pedigree, '*', out bitArray2);

            SymbolNotInBracket(pedigree, '+', out bitArray3);

            SymbolNotInBracket(pedigree, ':', out bitArray4);

            SymbolNotInBracket(pedigree, ';', out bitArray5);

            SymbolNotInBracket(pedigree, '^', out bitArray6);



#2
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
I am providing you with a insight into the arrays here u go Array Collection Type

#3
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
I understand how to create arrays. I don't understand how to do it with bitarrays.

#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
perhaps
BitArray[] array_of_bitarrays = new BitArray[10];
array_of_bitarrays[0] = new BitArray(ped.Length, false);
array_of_bitarrays[1] = new BitArray(ped.Length, false);


though to be honest, so long as your using out, you really don't need to initialize them ahead of time. Your function that you are handing them into as an outward parameter can create them for you.

#5
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
I get errors when I dont initialize the bitarrays ahead of time. Maybe I shouldn't be using out?

#6
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
to be honest, I've never tried exactly what you're trying to do, have an output parameter set an index of an array. But to be honest, you really don't need the out on a reference type like a BitArray.

but, using out is fine. it would look more like this
BitArray buffer;
SymbolNotInBracket(pedigree, '<', out buffer); array[0] = buffer;
SymbolNotInBracket(pedigree, '/', out buffer); array[1] = buffer;

in order for your app to build though, you need to make sure you're setting buffer from within your method.

#7
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I forget what your SymbolNotInBracket method is returning, you could also just have that method return the BitArray
and use array[x] = SymbolNotInBracket(pedigree, '<');

#8
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Wow have you got me confused. I just have a function that indexes the postion of each symbol into a bitarray. So if it were left brackets and the string was [hocus[pocus]] my bitarray would have 10000010000000 in it.

So I pass a string and symbol to a function and it passes me back a bitarray. Could you explain that difference it will have doing it the way you mentioned vs the way it currently is?

Thanks!

#9
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I know I helped you out with this function before, I just cant remember what it looks like. Can you post that function here again,. and I'll show you what I mean.

#10
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
        public void SymbolNotInBracket(string FullpedX, char symbol, out BitArray Final_Result)
        {
            bool flag;
            byte starts = 0;
            string new_ped = FullpedX;
            Final_Result = new BitArray(FullpedX.Length, false);
            int len = new_ped.Length;
            BitArray bitArray_lb = new BitArray(new bool[FullpedX.Length]);
            BitArray bitArray_rb = new BitArray(new bool[FullpedX.Length]);
            BitArray bitArray_s = new BitArray(new bool[FullpedX.Length]);


            symbol_index_numbers(new_ped, '[', out bitArray_lb);
            symbol_index_numbers(new_ped, ']', out bitArray_rb);
            symbol_index_numbers(new_ped, symbol, out bitArray_s);            

            if (bitArray_s.Cast<bool>().Any(x => x) && bitArray_lb.Cast<bool>().Any(x => x))   // if any contain true values
            {

                byte check_LB = 0;
                for (check_LB = 0; check_LB < len; check_LB++)
                    if (bitArray_lb[check_LB] == true)
                    {
                        flag = false;
                        byte k = 0;
                        for (k = 0; k < len; k++)
                        {
                            if (bitArray_lb[k] == true)
                            {
                                starts = k;
                                flag = true;
                            }
                            else if (bitArray_rb[k] == true & flag)
                            {
                                bitArray_lb[starts] = false;
                                bitArray_rb[k] = false;
                                for (int z = starts; z < k; z++)
                                {
                                    bitArray_s.Set(z, false);
                                }
                                flag = false;
                            }
                        }
                    }
                if (bitArray_s.Cast<bool>().Any(x => x)) { Final_Result = bitArray_s; }  
            }
            else if (bitArray_s.Cast<bool>().Any(x => x))
            {
                Final_Result = bitArray_s;
            }
       


#11
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
ok, so remove the parameter out BitArray Final_Result

and change your return type from void to BitArray

and instead of setting Final_result
use return

eg return bitArray_s


public BitArray SymbolNotInBracket(string FullpedX, char symbol)
        {
            bool flag;
            byte starts = 0;
            string new_ped = FullpedX;
            Final_Result = new BitArray(FullpedX.Length, false);
            int len = new_ped.Length;
            BitArray bitArray_lb = new BitArray(new bool[FullpedX.Length]);
            BitArray bitArray_rb = new BitArray(new bool[FullpedX.Length]);
            BitArray bitArray_s = new BitArray(new bool[FullpedX.Length]);


            symbol_index_numbers(new_ped, '[', out bitArray_lb);
            symbol_index_numbers(new_ped, ']', out bitArray_rb);
            symbol_index_numbers(new_ped, symbol, out bitArray_s);            

            if (bitArray_s.Cast<bool>().Any(x => x) && bitArray_lb.Cast<bool>().Any(x => x))   // if any contain true values
            {

                byte check_LB = 0;
                for (check_LB = 0; check_LB < len; check_LB++)
                    if (bitArray_lb[check_LB] == true)
                    {
                        flag = false;
                        byte k = 0;
                        for (k = 0; k < len; k++)
                        {
                            if (bitArray_lb[k] == true)
                            {
                                starts = k;
                                flag = true;
                            }
                            else if (bitArray_rb[k] == true & flag)
                            {
                                bitArray_lb[starts] = false;
                                bitArray_rb[k] = false;
                                for (int z = starts; z < k; z++)
                                {
                                    bitArray_s.Set(z, false);
                                }
                                flag = false;
                            }
                        }
                    }
                if (bitArray_s.Cast<bool>().Any(x => x)) { return bitArray_s; }  
            }
            else if (bitArray_s.Cast<bool>().Any(x => x))
            {
                return bitArray_s;
            }


I didnt test this, it feels like a } may be missing, but you can see my point

by doing this, you can assign elements within an array, using the function (without needing a 'bucket' to store it in)

eg
array[0] = SymbolNotInBracket(pedigree, '<'); //this works now because the result of running SymbolNotInBracket returns an instance of a bit array

#12
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
Thanks for your help. :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users