BitsetsNET.RLEBitset.CreateFrom C# (CSharp) Method

CreateFrom() public static method

Creates a RLEBitset from a BitArray.
public static CreateFrom ( BitArray bits ) : IBitset
bits System.Collections.BitArray a BitArray
return IBitset
        public static IBitset CreateFrom(BitArray bits)
        {
            RLEBitset rtnVal = new RLEBitset();
            rtnVal.length = bits.Length;
            Run currRun = new Run();
            for (int i = 0; i < bits.Count; i++)
            {
                if (bits.Get(i) == true)
                {
                    currRun.StartIndex = i;
                    currRun.EndIndex = i;
                    for (int j = i + 1; j < bits.Count; j++)
                    {
                        if (bits.Get(j))
                        {
                            currRun.EndIndex = j;
                        }
                        else
                        {
                            break;
                        }
                    }
                    i = currRun.EndIndex; //move the counter to the end of the run we just found
                    rtnVal.runArray.Add(currRun);
                    currRun = new Run();
                }

            }
            return rtnVal;
        }

Same methods

RLEBitset::CreateFrom ( int indices ) : IBitset
RLEBitset::CreateFrom ( int indices, int capacity ) : IBitset

Usage Example

Example #1
0
        /// <summary>
        /// Creates a RLEBitset from an array of indices.
        /// Each value in the input array represents the position (i.e. index) of a 1.
        /// </summary>
        /// <param name="indices">an array of integers representing the positions of 1's</param>
        /// <returns>an RLEBitset</returns>
        public static IBitset CreateFrom(int[] indices)
        {
            int capacity = 0;

            if (indices.Length > 0)
            {
                capacity = indices.Max() + 1;
            }
            return(RLEBitset.CreateFrom(indices, capacity));
        }
All Usage Examples Of BitsetsNET.RLEBitset::CreateFrom