Ejemplo n.º 1
0
 /// <summary>
 /// 排列递归方法。
 /// </summary>
 /// <param name="array">元素数组。</param>
 /// <param name="ii">已循环到的元素数组的索引。</param>
 /// <param name="created">排列完成一组元素后的回调函数。</param>
 /// <param name="userState">传递用户参数。</param>
 private static void Permutate(IList <T> array, int ii, CreatedCallback created, object userState)
 {
     if (ii == array.Count - 1)
     {
         T[] result = new T[array.Count];
         array.CopyTo(result, 0);
         created?.Invoke(result, userState);
     }
     else
     {
         for (int i = ii; i < array.Count; i++)
         {
             if (i == ii)
             {
                 Permutate(array, ii + 1, created, userState);
             }
             else
             {
                 Swap(array, i, ii);
                 Permutate(array, ii + 1, created, userState);
                 Swap(array, i, ii);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 每生成一组集合后调用回调函数。如果元素的类型是引用类型,排列的结果是元素的浅表复制。
 /// </summary>
 /// <param name="created">排列完成一组元素后的回调函数。</param>
 /// <param name="userState">传递用户参数。</param>
 public void Output(CreatedCallback created, object userState)
 {
     if (_m == _array.Count)
     {
         Permutate(_array, 0, created, userState);
     }
     else
     {
         Combination <T> combination = new Combination <T>(_array, _m);
         combination.Output((cr, cs) =>
         {
             Permutate(new ArraySegment <T>(cr), 0, created, cs);
         }, userState);
     }
 }
Ejemplo n.º 3
0
        public async Task ExecuteAsync <TCreatingAnimal, TAnimalDetails>(
            TCreatingAnimal createAnimal,
            CreatedCallback <TAnimalDetails> created,
            NotCreatedCallback <AnimalCreating> notCreated) where TCreatingAnimal : AnimalCreating
        {
            var createError = createAnimal.Validate();

            if (createError is IModelError)
            {
                notCreated(createError);
                return;
            }

            var createdAnimal =
                await this.animalsRegistrationAdapter.RegisterAsync <TCreatingAnimal, TAnimalDetails>(createAnimal);

            created(createdAnimal);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 组合递归方法。
 /// </summary>
 /// <param name="array">元素数组。</param>
 /// <param name="m">指定选择的元素数量。</param>
 /// <param name="ii">循环到的主要分段元素数组的索引。</param>
 /// <param name="jj">循环到的盈余分段元素数组的索引。</param>
 /// <param name="created">组合完成一组元素后的回调函数。</param>
 /// <param name="userState">传递用户参数。</param>
 private static void Combine(IList <T> array, int m, int ii, int jj, CreatedCallback created, object userState)
 {
     for (int i = ii; i < m; i++)
     {
         for (int j = jj; j < array.Count; j++)
         {
             Swap(array, i, j);
             Combine(array, m, i + 1, j + 1, created, userState);
             Swap(array, i, j);
         }
     }
     T[] result = new T[m];
     for (int i = 0; i < result.Length; i++)
     {
         result[i] = array[i];
     }
     created?.Invoke(result, userState);
 }
Ejemplo n.º 5
0
 internal static extern WebRTCErrorCode SetCreatedByPeerCb(IntPtr handle, CreatedCallback callback, IntPtr userData = default);
Ejemplo n.º 6
0
 /// <summary>
 /// 每生成一组集合后调用回调函数。如果元素的类型是引用类型,组合的结果是元素的浅表复制。
 /// </summary>
 /// <param name="created">组合完成一组元素后的回调函数。</param>
 /// <param name="userState">传递用户参数。</param>
 public void Output(CreatedCallback created, object userState)
 {
     Combine(_array, _m, 0, _m, created, userState);
 }