当前位置: 首页>>代码示例>>C#>>正文


C# BlobBuilder.CheckInvariants方法代码示例

本文整理汇总了C#中Microsoft.Cci.BlobBuilder.CheckInvariants方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.CheckInvariants方法的具体用法?C# BlobBuilder.CheckInvariants怎么用?C# BlobBuilder.CheckInvariants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Cci.BlobBuilder的用法示例。


在下文中一共展示了BlobBuilder.CheckInvariants方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LinkSuffix

        /// <exception cref="ArgumentNullException"><paramref name="suffix"/> is null.</exception>
        /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception>
        public void LinkSuffix(BlobBuilder suffix)
        {
            if (suffix == null)
            {
                throw new ArgumentNullException(nameof(suffix));
            }

            // TODO: consider copying data from right to left while there is space

            if (!IsHead || !suffix.IsHead)
            {
                ThrowHeadRequired();
            }

            // avoid chaining empty chunks:
            if (suffix.Count == 0)
            {
                return;
            }

            // swap buffers of the heads:
            var suffixBuffer = suffix._buffer;
            uint suffixLength = suffix._length;
            suffix._buffer = _buffer;
            suffix._length = FrozenLength; // suffix is not a head anymore
            _buffer = suffixBuffer;
            _length = suffixLength;

            int suffixPreviousLength = suffix._previousLength;
            suffix._previousLength = _previousLength;
            _previousLength = _previousLength + suffix.Length + suffixPreviousLength;

            // First and last chunks:
            //
            // [First]->[]->[Last] <- [this]    [SuffixFirst]->[]->[SuffixLast]  <- [suffix]
            //    ^___________|                       ^_________________|
            //
            // Degenerate cases:
            // this == First == Last and/or suffix == SuffixFirst == SuffixLast.
            var first = FirstChunk;
            var suffixFirst = suffix.FirstChunk;
            var last = _nextOrPrevious;
            var suffixLast = suffix._nextOrPrevious;

            // Relink like so:
            // [First]->[]->[Last] -> [suffix] -> [SuffixFirst]->[]->[SuffixLast]  <- [this]
            //    ^_______________________________________________________|
            _nextOrPrevious = suffixLast;
            suffix._nextOrPrevious = (suffixFirst != suffix) ? suffixFirst : (first != this) ? first : suffix;

            if (last != this)
            {
                last._nextOrPrevious = suffix;
            }

            if (suffixLast != suffix)
            {
                suffixLast._nextOrPrevious = (first != this) ? first : suffix;
            }

            CheckInvariants();
            suffix.CheckInvariants();
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:65,代码来源:BlobBuilder.cs

示例2: LinkPrefix

        /// <exception cref="ArgumentNullException"><paramref name="prefix"/> is null.</exception>
        /// <exception cref="InvalidOperationException">Builder is not writable, it has been linked with another one.</exception>
        public void LinkPrefix(BlobBuilder prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            // TODO: consider copying data from right to left while there is space

            if (!prefix.IsHead || !IsHead)
            {
                ThrowHeadRequired();
            }

            // avoid chaining empty chunks:
            if (prefix.Count == 0)
            {
                return;
            }

            _previousLength += prefix.Count;

            // prefix is not a head anymore:
            prefix._length = prefix.FrozenLength;

            // First and last chunks:
            //
            // [PrefixFirst]->[]->[PrefixLast] <- [prefix]    [First]->[]->[Last] <- [this]    
            //       ^_________________|                          ^___________|                 
            //
            // Degenerate cases:
            // this == First == Last and/or prefix == PrefixFirst == PrefixLast.
            var first = FirstChunk;
            var prefixFirst = prefix.FirstChunk;
            var last = _nextOrPrevious;
            var prefixLast = prefix._nextOrPrevious;

            // Relink like so:
            // [PrefixFirst]->[]->[PrefixLast] -> [prefix] -> [First]->[]->[Last] <- [this] 
            //      ^________________________________________________________|

            _nextOrPrevious = (last != this) ? last : prefix;
            prefix._nextOrPrevious = (first != this) ? first : (prefixFirst != prefix) ? prefixFirst : prefix;

            if (last != this)
            {
                last._nextOrPrevious = (prefixFirst != prefix) ? prefixFirst : prefix;
            }

            if (prefixLast != prefix)
            {
                prefixLast._nextOrPrevious = prefix;
            }

            prefix.CheckInvariants();
            CheckInvariants();
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:59,代码来源:BlobBuilder.cs


注:本文中的Microsoft.Cci.BlobBuilder.CheckInvariants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。