private static T ReduceTask <T>(int start, int end, int grainSize, ReduceDelegate <T> loopbody, CombineDelegate <T> combineMethod) { int num = end - start; T result; if (num > grainSize) { int middle = (num / 2) + start; Future <T> task = new DelegateFuture <T>(delegate { return(ReduceTask(start, middle, grainSize, loopbody, combineMethod)); }).Start(); result = ReduceTask(middle, end, grainSize, loopbody, combineMethod); return(combineMethod(result, task.Result())); } // grainSize is never less than 1, thus num cannot be less than one. if (num == 1) { return(loopbody(start)); } result = combineMethod(loopbody(start), loopbody(start + 1)); for (int i = start + 2; i < end; i++) { result = combineMethod(result, loopbody(i)); } return(result); }
public SyncabilityHelper(UIDevice device) { this._device = device ?? UIDeviceList.NullDevice; this._isGuest = new DelegateFuture <bool>(() => this._device.IsGuest); this._userId = new DelegateFuture <int>(() => this._device.UserId); this._supportsUserCards = new DelegateFuture <bool>(() => this._device.SupportsUserCards); this._supportsChannels = new DelegateFuture <bool>(() => this._device.SupportsChannels); this._supportsApplications = new DelegateFuture <bool>(() => this._device.SupportsSyncApplications); this._supportsRental = new DelegateFuture <bool>(() => this._device.SupportsRental); this._supportsHD = new DelegateFuture <bool>(() => this._device.SupportsHD); this._isUnlinked = new DelegateFuture <bool>(() => this.UserID == 0); this._canSyncUserCards = new DelegateFuture <bool>(new CalculateValue <bool>(this.GetCanSyncUserCards)); this._canSyncChannels = new DelegateFuture <bool>(new CalculateValue <bool>(this.GetCanSyncChannels)); this._canSyncApplications = new DelegateFuture <bool>(new CalculateValue <bool>(this.GetCanSyncApplications)); this._canSyncRentalVideo = new DelegateFuture <bool>(new CalculateValue <bool>(this.GetCanSyncRentalVideo)); this._canSyncHDRentalVideo = new DelegateFuture <bool>(new CalculateValue <bool>(this.GetCanSyncHDRentalVideo)); }