/// <summary> /// Notifies this barrier that there will be additional participants. /// </summary> /// <param name="participantCount">The number of additional participants to add to the barrier.</param> /// <returns>The phase number of the barrier in which the new participants will first participate.</returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="participantCount"/> is less than 0.</exception> /// <exception cref="ObjectDisposedException">The current instance has already been disposed.</exception> public long AddParticipants(long participantCount) { ThrowIfDisposed(); countdown.TryAddCount(participantCount, true); // always returns true if autoReset==true participants.Add(participantCount); return(currentPhase); }
public RandomNumberRequestInformation GetRandomNumberRequestInformation() { var lastMinedMinerInformation = _currentRound.RealTimeMinersInformation.Values.OrderBy(i => i.Order) .LastOrDefault(i => i.OutValue != null); var minedMinersCount = lastMinedMinerInformation?.Order ?? 0; var leftMinersCount = _minersCount.Sub(minedMinersCount); if (leftMinersCount >= _minimumRequestMinersCount) { // It's possible for user to get random number in current round. return(new RandomNumberRequestInformation { TargetRoundNumber = _currentRound.RoundNumber, ExpectedBlockHeight = _currentHeight.Add( _minimumRequestMinersCount.Mul(AEDPoSContractConstants.MaximumTinyBlocksCount)), Order = minedMinersCount }); } var leftTinyBlocks = lastMinedMinerInformation == null ? 0 : AEDPoSContractConstants.MaximumTinyBlocksCount.Sub(lastMinedMinerInformation.ActualMiningTimes .Count); var leftBlocksCount = _currentHeight .Add(leftMinersCount.Mul(AEDPoSContractConstants.MaximumTinyBlocksCount)) .Add(leftTinyBlocks); return(new RandomNumberRequestInformation { TargetRoundNumber = _currentRound.RoundNumber.Add(1), ExpectedBlockHeight = _currentHeight.Add(leftBlocksCount), Order = minedMinersCount }); }
public static void Solve() { var(A, B, Q) = Scanner.Scan <int, int, int>(); var S = new long[A].Select(_ => Scanner.Scan <long>()).ToList(); var T = new long[B].Select(_ => Scanner.Scan <long>()).ToList(); var X = new long[Q].Select(_ => Scanner.Scan <long>()).ToArray(); const long inf = (long)1e18; S.Add(-inf); S.Add(inf); T.Add(-inf); T.Add(inf); S.Sort(); T.Sort(); foreach (var x in X) { var slb = ~S.BinarySearch(x); var tlb = ~T.BinarySearch(x); var answer = inf; foreach (var s in new[] { S[slb - 1], S[slb] }) { foreach (var t in new[] { T[tlb - 1], T[tlb] }) { answer = Math.Min(answer, Math.Abs(s - x) + Math.Abs(t - s)); answer = Math.Min(answer, Math.Abs(t - x) + Math.Abs(s - t)); } } Console.WriteLine(answer); } }
public void Deconstruct(out BlockchainMiningStatus status) { status = BlockchainMiningStatus.Normal; if (_libRoundNumber.Add(AbnormalThresholdRoundsCount) < _currentRoundNumber && _currentRoundNumber < _libRoundNumber.Add(SevereStatusRoundsThreshold)) { status = BlockchainMiningStatus.Abnormal; } if (_currentRoundNumber >= _libRoundNumber.Add(SevereStatusRoundsThreshold)) { status = BlockchainMiningStatus.Severe; } }
public void Int64_And_UInt64_Test() { ulong number1 = 6; long number2 = 6; number1.Mul(6).ShouldBe(36UL); number2.Mul(6).ShouldBe(36L); Should.Throw <DivideByZeroException>(() => { number1.Div(0); }); Should.Throw <DivideByZeroException>(() => { number2.Div(0); }); number1.Div(2).ShouldBe(3UL); number2.Div(-2).ShouldBe(-3L); Should.Throw <DivideByZeroException>(() => { 5.Div(0); }); Should.Throw <DivideByZeroException>(() => { (-5).Div(0); }); number1.Sub(5).ShouldBe(1UL); number2.Sub(5).ShouldBe(1L); Should.Throw <OverflowException>(() => { long.MaxValue.Sub(-5); }); Should.Throw <OverflowException>(() => { ulong.MinValue.Sub(5); }); number1.Add(5).ShouldBe(11UL); number2.Add(5).ShouldBe(11L); Should.Throw <OverflowException>(() => { long.MaxValue.Add(8); }); Should.Throw <OverflowException>(() => { ulong.MaxValue.Add(8); }); }
/// <summary> /// This method for now is able to handle the situation of a miner keeping offline so many rounds, /// by using missedRoundsCount. /// </summary> /// <param name="miningInterval"></param> /// <param name="missedRoundsCount"></param> /// <returns></returns> private Timestamp CalculateFutureRoundStartTime(long missedRoundsCount = 0, int miningInterval = 0) { if (miningInterval == 0) { miningInterval = GetMiningInterval(); } var totalMilliseconds = TotalMilliseconds(miningInterval); return(GetRoundStartTime().AddMilliseconds(missedRoundsCount.Add(1).Mul(totalMilliseconds))); }
private void addPoint(Polygon polygon, Vector3 point) { List <Vector3> points = null; if (!this.currentPoints.TryGetValue(polygon, out points)) { points = new List <Vector3>(); this.currentPoints[polygon] = points; this.polygonQueue.Enqueue(polygon); buildings++; } points.Add(point); polygon.ContainsPoints = true; }
/// <summary> /// Signals that a participant has reached the barrier and waits /// for all other participants to reach the barrier as well. /// </summary> /// <param name="timeout">The time to wait for phase completion.</param> /// <param name="token">The token that can be used to cancel the waiting operation.</param> /// <returns><see langword="true"/> if all other participants reached the barrier; otherwise, <see langword="false"/>.</returns> /// <exception cref="ObjectDisposedException">The current instance has already been disposed.</exception> public async Task <bool> SignalAndWaitAsync(TimeSpan timeout, CancellationToken token = default) { if (ParticipantCount == 0L) { throw new InvalidOperationException(); } if (countdown.Signal(1L, true)) { await PostPhase(currentPhase.Add(1L)).ConfigureAwait(false); return(true); } return(await WaitAsync(timeout, token).ConfigureAwait(false)); }
/// <summary> /// Just burn balance in general ledger. /// </summary> /// <param name="period"></param> /// <param name="profitsMap"></param> /// <param name="scheme"></param> /// <param name="profitsReceivingVirtualAddress"></param> /// <returns></returns> private Empty BurnProfits(long period, Dictionary <string, long> profitsMap, Scheme scheme, Address profitsReceivingVirtualAddress) { Context.LogDebug(() => "going to Burn Profits."); scheme.CurrentPeriod = period.Add(1); var distributedProfitsInfo = new DistributedProfitsInfo { IsReleased = true }; foreach (var profits in profitsMap) { var symbol = profits.Key; var amount = profits.Value; if (amount > 0) { var balanceOfToken = State.TokenContract.GetBalance.Call(new GetBalanceInput { Owner = scheme.VirtualAddress, Symbol = symbol }); if (balanceOfToken.Balance < amount) { continue; } State.TokenContract.TransferFrom.Send(new TransferFromInput { From = scheme.VirtualAddress, To = Context.Self, Amount = amount, Symbol = symbol }); State.TokenContract.Burn.Send(new BurnInput { Amount = amount, Symbol = symbol }); distributedProfitsInfo.AmountsMap.Add(symbol, -amount); } } State.SchemeInfos[scheme.SchemeId] = scheme; State.DistributedProfitsMap[profitsReceivingVirtualAddress] = distributedProfitsInfo; return(new Empty()); }
public long FindFirstDuplicateFrequency(string frequencyChangesString) { var summedChanges = new long[] { 0 }.ToList(); while (true) { foreach (var frequencyChange in ParseFrequencyChanges(frequencyChangesString)) { var lastSum = summedChanges.LastOrDefault(); var newSum = lastSum + frequencyChange; if (summedChanges.Contains(newSum)) { return(newSum); } summedChanges.Add(newSum); } } }
private void UpdateTreasurySubItemsShares(long termNumber) { var endPeriod = termNumber.Add(1); if (State.ElectionContract.Value == null) { State.ElectionContract.Value = Context.GetContractAddressByName(SmartContractConstants.ElectionContractSystemName); } var victories = State.ElectionContract.GetVictories.Call(new Empty()).Value.Select(bs => bs.ToHex()) .ToList(); var previousMiners = State.AEDPoSContract.GetPreviousMinerList.Call(new Empty()).Pubkeys.ToList(); var previousMinerAddress = previousMiners.Select(k => Address.FromPublicKey(k.ToByteArray())).ToList(); UpdateBasicMinerRewardWeights(endPeriod, victories, previousMinerAddress); UpdateReElectionRewardWeights(endPeriod, previousMiners.Select(m => m.ToHex()).ToList(), previousMinerAddress, victories); UpdateVotesWeightRewardWeights(endPeriod, victories, previousMinerAddress); }
internal Round GenerateFirstRoundOfNewTerm(int miningInterval, Timestamp currentBlockTime, long currentRoundNumber = 0, long currentTermNumber = 0) { var sortedMiners = (from obj in Pubkeys .ToDictionary <ByteString, string, int>(miner => miner.ToHex(), miner => miner[0]) orderby obj.Value descending select obj.Key).ToList(); var round = new Round(); for (var i = 0; i < sortedMiners.Count; i++) { var minerInRound = new MinerInRound(); // The first miner will be the extra block producer of first round of each term. if (i == 0) { minerInRound.IsExtraBlockProducer = true; } minerInRound.Pubkey = sortedMiners[i]; minerInRound.Order = i + 1; minerInRound.ExpectedMiningTime = currentBlockTime.AddMilliseconds(i.Mul(miningInterval).Add(miningInterval)); // Should be careful during validation. minerInRound.PreviousInValue = Hash.Empty; round.RealTimeMinersInformation.Add(sortedMiners[i], minerInRound); } round.RoundNumber = currentRoundNumber.Add(1); round.TermNumber = currentTermNumber.Add(1); round.IsMinerListJustChanged = true; return(round); }
public static long Inc(this long i) { return(i.Add(1)); }
/// <summary>Adds the specified percentage to the stream size.</summary> /// <param name="p"> /// The percentage to add. /// </param> public StreamSize Add(Percentage p) { return(m_Value.Add(p)); }
/// <summary> /// Добавление тиков и инкремент счетчика тиков /// </summary> /// <param name="item"></param> public void Add(TimeSpan item) { _count.Increment(); _ticks.Add(item.Ticks); }
public static IArray <long> Add(this long self, IArray <long> vector) { return(vector.Select(x => self.Add(x))); }