예제 #1
0
        /* Private members */

        private bool Merge()
        {
            Ui.View.Subtitles subtitles = Base.Document.Subtitles;
            int firstPathInt            = Util.PathToInt(this.FirstPath);
            int lastPathInt             = Util.PathToInt(this.LastPath);

            /* Store selected subtitles */
            int subtitleCount = lastPathInt - firstPathInt + 1;

            this.subtitlesBefore    = new Subtitle[subtitleCount];
            this.subtitlesBefore[0] = subtitles[firstPathInt].Clone(subtitles.Properties);     //only the first needs to be cloned, the rest won't be changed
            for (int index = 1, currentPath = firstPathInt + 1; index < subtitleCount; index++, currentPath++)
            {
                this.subtitlesBefore[index] = subtitles[currentPath];
            }

            /* Merge subtitles */
            MergeOperator mergeOperator = new MergeOperator(subtitles);

            if (!mergeOperator.Merge(firstPathInt, lastPathInt))
            {
                return(false);
            }

            TreePath secondPath = Util.IntToPath(firstPathInt + 1);

            subtitles.RemoveRange(secondPath, this.LastPath);
            Base.Ui.View.RedrawPath(this.FirstPath);
            Base.Ui.View.Selection.Select(this.FirstPath, true, true);
            return(true);
        }
	public override bool Execute () {
		GnomeSubtitles.Ui.View.Subtitles subtitles = Base.Document.Subtitles;
		int firstPathInt = Util.PathToInt(this.FirstPath);
		int lastPathInt = Util.PathToInt(this.LastPath);

		/* Store selected subtitles */
		int subtitleCount = lastPathInt - firstPathInt + 1;
		this.subtitlesBefore = new Subtitle[subtitleCount];
		this.subtitlesBefore[0] = subtitles[firstPathInt].Clone(subtitles.Properties); //only the first needs to be cloned, the rest won't be changed
		for (int index = 1, currentPath = firstPathInt + 1 ; index < subtitleCount ; index++, currentPath++) {
			this.subtitlesBefore[index] = subtitles[currentPath];
		}

		/* Merge subtitles */
		MergeOperator mergeOperator = new MergeOperator(Base.Document.Subtitles);
		if (!mergeOperator.Merge(firstPathInt, lastPathInt))
			return false;
		else {
			TreePath secondPath = Util.IntToPath(firstPathInt + 1);
			subtitles.RemoveRange(secondPath, this.LastPath);
			Base.Ui.View.RedrawPath(this.FirstPath);
			Base.Ui.View.Selection.Select(this.FirstPath, true, true);
			PostProcess();
			return true;
		}
	}
예제 #3
0
 /// <summary>コンストラクタ</summary>
 /// <param name="length">長さ</param>
 /// <param name="operatorIdentityElement">作用素の単位元</param>
 /// <param name="operate">作用素を作用させる関数</param>
 /// <param name="mergeOperator">作用素をマージする関数</param>
 public LazySegmentTree(int length, T valueIdentityElement, E operatorIdentityElement, MergeOperator mergeOperator, Operate operate)
 {
     length--;
     this.length        = 1;
     this.mergeOperator = mergeOperator;
     this.operate       = operate;
     while (length != 0)
     {
         length      >>= 1;
         this.length <<= 1;
     }
     ValueIdentityElement    = valueIdentityElement;
     OperatorIdentityElement = operatorIdentityElement;
     nodesOp    = Enumerable.Repeat(OperatorIdentityElement, this.length << 1).ToArray();
     operators  = Enumerable.Repeat(OperatorIdentityElement, this.length << 1).ToArray();
     isRemained = Enumerable.Repeat(false, this.length << 1).ToArray();
 }
예제 #4
0
        /// <summary>
        /// REQUIRES: The client must provide a merge operator if Merge operation
        /// needs to be accessed. Calling Merge on a DB without a merge operator
        /// would result in Status::NotSupported. The client must ensure that the
        /// merge operator supplied here has the same name and *exactly* the same
        /// semantics as the merge operator provided to previous open calls on
        /// the same DB. The only exception is reserved for upgrade, where a DB
        /// previously without a merge operator is introduced to Merge operation
        /// for the first time. It's necessary to specify a merge operator when
        /// openning the DB in this case.
        /// Default: nullptr
        /// </summary>
        public ColumnFamilyOptions SetMergeOperator(MergeOperator mergeOperator)
        {
            // Allocate some memory for the name bytes
            var name      = mergeOperator.Name ?? mergeOperator.GetType().FullName;
            var nameBytes = Encoding.UTF8.GetBytes(name + "\0");
            var namePtr   = Marshal.AllocHGlobal(nameBytes.Length);

            Marshal.Copy(nameBytes, 0, namePtr, nameBytes.Length);

            // Hold onto a reference to everything that needs to stay alive
            MergeOperatorRef = new MergeOperatorReferences
            {
                GetMergeOperator     = () => mergeOperator,
                DestructorDelegate   = MergeOperator_Destroy,
                NameDelegate         = MergeOperator_GetNamePtr,
                DeleteValueDelegate  = MergeOperator_DeleteValue,
                FullMergeDelegate    = MergeOperator_FullMerge,
                PartialMergeDelegate = MergeOperator_PartialMerge,
            };

            // Allocate the state
            var state = new MergeOperatorState
            {
                NamePtr             = namePtr,
                GetMergeOperatorPtr = CurrentFramework.GetFunctionPointerForDelegate <GetMergeOperator>(MergeOperatorRef.GetMergeOperator)
            };
            var statePtr = Marshal.AllocHGlobal(Marshal.SizeOf(state));

            Marshal.StructureToPtr(state, statePtr, false);

            // Create the merge operator
            IntPtr handle = Native.Instance.rocksdb_mergeoperator_create(
                state: statePtr,
                destructor: MergeOperatorRef.DestructorDelegate,
                delete_value: MergeOperatorRef.DeleteValueDelegate,
                full_merge: MergeOperatorRef.FullMergeDelegate,
                partial_merge: MergeOperatorRef.PartialMergeDelegate,
                name: MergeOperatorRef.NameDelegate
                );

            return(SetMergeOperator(handle));
        }
예제 #5
0
 /// <summary>コンストラクタ</summary>
 /// <param name="length">長さ</param>
 /// <param name="elementIdentityElement">各要素の単位元</param>
 /// <param name="operatorIdentityElement">作用素の単位元</param>
 /// <param name="operate">作用素を作用させる関数</param>
 /// <param name="mergeOperator">作用素をマージする関数</param>
 public LazySegmentTree(int length, T valueIdentityElement, E operatorIdentityElement, MergeElement mergeElement, MergeOperator mergeOperator, Operate operate) : this(length, valueIdentityElement, operatorIdentityElement, mergeOperator, operate)
 {
     this.mergeElement = mergeElement;
 }