Exemplo n.º 1
0
        protected void AddMetadataBlock(long start, long length)
        {
            MetadataBlock new_block = new MetadataBlock(start, length);

            for (int i = 0; i < metadata_blocks.Count; i++)
            {
                var block = metadata_blocks[i];
                if (new_block.OverlapsWith(block))
                {
                    block.Add(new_block);
                    i++;
                    while (i < metadata_blocks.Count)
                    {
                        var next_block = metadata_blocks[i];
                        if (block.OverlapsWith(next_block))
                        {
                            block.Add(next_block);
                            metadata_blocks.Remove(next_block);
                        }
                        else
                        {
                            return;
                        }
                    }
                    return;
                }
                else if (new_block.Before(block))
                {
                    metadata_blocks.Insert(i, new_block);
                    return;
                }
            }
            metadata_blocks.Add(new_block);
        }
Exemplo n.º 2
0
 public bool OverlapsWith(MetadataBlock block)
 {
     if (block.Start >= Start && block.Start <= Start + Length)
     {
         return(true);
     }
     if (Start >= block.Start && Start <= block.Start + block.Length)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        ///    Adds a range to be treated as metadata.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="System.Int64"/> with the start index of the metadata block
        /// </param>
        /// <param name="length">
        ///    A <see cref="System.Int64"/> with the length of the metadata block
        /// </param>
        protected void AddMetadataBlock(long start, long length)
        {
            MetadataBlock new_block = new MetadataBlock(start, length);

            // We keep the list sorted and unique. Therefore, we add the new block to
            // the list and join overlapping blocks if necessary.

            // iterate through all existing blocks.
            for (int i = 0; i < metadata_blocks.Count; i++)
            {
                var block = metadata_blocks[i];

                // if one block overlaps with the new one, join them.
                if (new_block.OverlapsWith(block))
                {
                    block.Add(new_block);

                    // Since we joined two blocks, they may overlap with
                    // other blocks which follows in the list. Therfore,
                    // we iterate through the tail of the list and join
                    // blocks which are now contained.
                    i++;
                    while (i < metadata_blocks.Count)
                    {
                        var next_block = metadata_blocks[i];

                        if (block.OverlapsWith(next_block))
                        {
                            block.Add(next_block);
                            metadata_blocks.Remove(next_block);
                        }
                        else
                        {
                            return;
                        }
                    }

                    return;

                    // if the new block is 'smaller' than the one in the list,
                    // just add it to the list.
                }
                else if (new_block.Before(block))
                {
                    metadata_blocks.Insert(i, new_block);
                    return;
                }
            }

            // if the new block is 'bigger' than all other blocks, at it to the end.
            metadata_blocks.Add(new_block);
        }
Exemplo n.º 4
0
 public void Add(MetadataBlock block)
 {
     if (block.Start >= Start && block.Start <= Start + Length)
     {
         Length = Math.Max(Length, block.Start + block.Length - Start);
         return;
     }
     if (Start >= block.Start && Start <= block.Start + block.Length)
     {
         Length = Math.Max(block.Length, Start + Length - block.Start);
         Start  = block.Start;
         return;
     }
     throw new ArgumentException(String.Format("blocks do not overlap: {0} and {1}", this, block));
 }
Exemplo n.º 5
0
            /// <summary>
            ///    Adds the given block to the current instance, if this is possible.
            /// </summary>
            /// <param name="block">
            ///    A <see cref="MetadataBlock"/> with the block to add.
            /// </param>
            public void Add(MetadataBlock block)
            {
                if (block.Start >= Start && block.Start <= Start + Length)
                {
                    Length = Math.Max(Length, block.Start + block.Length - Start);
                    return;
                }

                if (Start >= block.Start && Start <= block.Start + block.Length)
                {
                    Length = Math.Max(block.Length, Start + Length - block.Start);
                    Start  = block.Start;
                    return;
                }

                throw new ArgumentException($"blocks do not overlap: {this} and {block}");
            }
Exemplo n.º 6
0
 /// <summary>
 ///    Checks, if the one block is before the other. That means,
 ///    if the current instance ends before the given block starts.
 /// </summary>
 /// <param name="block">
 ///    A <see cref="MetadataBlock"/> to compare with.
 /// </param>
 /// <returns>
 ///    A <see cref="System.Boolean"/> which is true if the current
 ///    instance is before the given block.
 /// </returns>
 public bool Before(MetadataBlock block)
 {
     return(Start + Length < block.Start);
 }
        /// <summary>
        ///    Adds a range to be treated as metadata.
        /// </summary>
        /// <param name="start">
        ///    A <see cref="System.Int64"/> with the start index of the metadata block
        /// </param>
        /// <param name="length">
        ///    A <see cref="System.Int64"/> with the length of the metadata block
        /// </param>
        protected void AddMetadataBlock(long start, long length)
        {
            MetadataBlock new_block = new MetadataBlock (start, length);

            // We keep the list sorted and unique. Therefore, we add the new block to
            // the list and join overlapping blocks if necessary.

            // iterate through all existing blocks.
            for (int i = 0; i < metadata_blocks.Count; i++) {

                var block = metadata_blocks[i];

                // if one block overlaps with the new one, join them.
                if (new_block.OverlapsWith (block)) {
                    block.Add (new_block);

                    // Since we joined two blocks, they may overlap with
                    // other blocks which follows in the list. Therfore,
                    // we iterate through the tail of the list and join
                    // blocks which are now contained.
                    i++;
                    while (i < metadata_blocks.Count) {
                        var next_block = metadata_blocks[i];

                        if (block.OverlapsWith (next_block)) {
                            block.Add (next_block);
                            metadata_blocks.Remove (next_block);
                        } else {
                            return;
                        }

                    }

                    return;

                    // if the new block is 'smaller' than the one in the list,
                    // just add it to the list.
                } else if (new_block.Before (block)) {
                    metadata_blocks.Insert (i, new_block);
                    return;
                }
            }

            // if the new block is 'bigger' than all other blocks, at it to the end.
            metadata_blocks.Add (new_block);
        }
            /// <summary>
            ///    Checks if the given block overlaps with this instance.
            /// </summary>
            /// <param name="block">
            ///    A <see cref="MetadataBlock"/> with the block to check
            ///    overlapping.
            /// </param>
            /// <returns>
            ///    A <see cref="System.Boolean"/> which is true, if the given
            ///    block overlapps with the current instance.
            /// </returns>
            /// <remarks>
            ///    Overlapping means here also that blocks directly follow.
            /// </remarks>
            public bool OverlapsWith(MetadataBlock block)
            {
                if (block.Start >= Start && block.Start <= Start + Length)
                    return true;

                if (Start >= block.Start && Start <= block.Start + block.Length)
                    return true;

                return false;
            }
 /// <summary>
 ///    Checks, if the one block is before the other. That means,
 ///    if the current instance ends before the given block starts.
 /// </summary>
 /// <param name="block">
 ///    A <see cref="MetadataBlock"/> to compare with.
 /// </param>
 /// <returns>
 ///    A <see cref="System.Boolean"/> which is true if the current
 ///    instance is before the given block.
 /// </returns>
 public bool Before(MetadataBlock block)
 {
     return (Start + Length < block.Start);
 }
Exemplo n.º 10
0
            /// <summary>
            ///    Adds the given block to the current instance, if this is possible.
            /// </summary>
            /// <param name="block">
            ///    A <see cref="MetadataBlock"/> with the block to add.
            /// </param>
            public void Add(MetadataBlock block)
            {
                if (block.Start >= Start && block.Start <= Start + Length) {
                    Length = Math.Max (Length, block.Start + block.Length - Start);
                    return;
                }

                if (Start >= block.Start && Start <= block.Start + block.Length) {
                    Length = Math.Max (block.Length, Start + Length - block.Start);
                    Start = block.Start;
                    return;
                }

                throw new ArgumentException (String.Format ("blocks do not overlap: {0} and {1}", this, block));
            }