LibiadaCore.Core.BaseChain.ClearAndSetNewLength C# (CSharp) Method

ClearAndSetNewLength() public method

Deletes chain (building and alphabet) and creates new empty chain with given length.
/// Thrown if length of new sequence is less then zero. ///
public ClearAndSetNewLength ( int length ) : void
length int /// New chain length. ///
return void
        public override void ClearAndSetNewLength(int length)
        {
            if (length < 0)
            {
                throw new ArgumentException("Chain length shouldn't be less than 0.");
            }

            building = new int[length];
            alphabet = new Alphabet { NullValue.Instance() };
        }

Usage Example

        /// <summary>
        /// Reorganizes source chain.
        /// </summary>
        /// <param name="source">
        /// Source chain.
        /// </param>
        /// <returns>
        /// <see cref="AbstractChain"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// Thrown if level is less than 0.
        /// </exception>
        public override AbstractChain Reorganize(AbstractChain source)
        {
            if (level < 0)
            {
                throw new InvalidOperationException("Markov chain level can't be less than 0");
            }

            if (level == 0)
            {
                return source;
            }

            var result = new BaseChain();
            result.ClearAndSetNewLength(source.GetLength() + level);
            for (int i = 0; i < source.GetLength(); i++)
            {
                result[i] = source[i];
            }

            var iterator = new IteratorStart(source, level, 1);
            iterator.Reset();
            iterator.Next();
            AbstractChain addition = iterator.Current();
            for (int i = 0; i < addition.GetLength(); i++)
            {
                result[source.GetLength() + i] = addition[i];
            }

            return result;
        }
All Usage Examples Of LibiadaCore.Core.BaseChain::ClearAndSetNewLength