C# Класс StopGuessing.DataStructures.DecayingDouble

A class that represents a double that decays over time using a half life, to borrow a concept from radioactive decay. A value that is assigned a value 1d and a half life of one day will have value 0.5d after one day, .25d after two days, and so on. More generally, if you assign the value x, after e half lives it's value will be x/(2^e). Since a double that decays with time will have a constantly-changing real value, it should never be used as the key into a Dictionary or kept in a HashSet. It should not be compared for exact equality.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Add ( System.TimeSpan halfLife, DecayingDouble amountToAdd ) : DecayingDouble
Add ( double amountToAdd, System.TimeSpan halfLife, System.DateTime timeOfAddOperationUtc = null ) : void

In-place addition

AddInPlace ( System.TimeSpan halfLife, DecayingDouble amountToAdd ) : void
AddInPlace ( System.TimeSpan halfLife, double amountToAdd, System.DateTime whenToAddIt ) : void
Decay ( double valueLastSetTo, System.TimeSpan halfLife, System.DateTime whenLastSetUtc, System.DateTime timeToDecayTo = null ) : double
DecayingDouble ( double initialValue = 0d, System.DateTime initialLastUpdateUtc = null ) : System

A double that decays with time

GetValue ( System.TimeSpan halfLife, System.DateTime whenUtc = null ) : double

Get the value of the double at a given instant in time. If using the current system time, the preferred way to get the value is not to call this method but to simply access the Value field.

SetValue ( DecayingDouble source ) : void
SetValue ( double newValue, System.DateTime whenUtc = null ) : void

Set the value at a point in time. If setting using the current system time, the preferred approach is to simply set the Value field.

Subtract ( System.TimeSpan halfLife, DecayingDouble amountToRemove ) : DecayingDouble
SubtractInPlace ( System.TimeSpan halfLife, DecayingDouble amountToSubtract ) : void
SubtractInPlace ( System.TimeSpan halfLife, double amountToSubtract, System.DateTime whenToSubtractIt ) : void

Описание методов

Add() публичный Метод

public Add ( System.TimeSpan halfLife, DecayingDouble amountToAdd ) : DecayingDouble
halfLife System.TimeSpan
amountToAdd DecayingDouble
Результат DecayingDouble

Add() публичный Метод

In-place addition
public Add ( double amountToAdd, System.TimeSpan halfLife, System.DateTime timeOfAddOperationUtc = null ) : void
amountToAdd double The amount to add to the existing value.
halfLife System.TimeSpan The half life to use when determining the existing value.
timeOfAddOperationUtc System.DateTime When to add it, in UTC time (if NULL, sets it to the current clock time)
Результат void

AddInPlace() публичный Метод

public AddInPlace ( System.TimeSpan halfLife, DecayingDouble amountToAdd ) : void
halfLife System.TimeSpan
amountToAdd DecayingDouble
Результат void

AddInPlace() публичный Метод

public AddInPlace ( System.TimeSpan halfLife, double amountToAdd, System.DateTime whenToAddIt ) : void
halfLife System.TimeSpan
amountToAdd double
whenToAddIt System.DateTime
Результат void

Decay() публичный статический Метод

public static Decay ( double valueLastSetTo, System.TimeSpan halfLife, System.DateTime whenLastSetUtc, System.DateTime timeToDecayTo = null ) : double
valueLastSetTo double
halfLife System.TimeSpan
whenLastSetUtc System.DateTime
timeToDecayTo System.DateTime
Результат double

DecayingDouble() публичный Метод

A double that decays with time
public DecayingDouble ( double initialValue = 0d, System.DateTime initialLastUpdateUtc = null ) : System
initialValue double The initial value of the double, which defaults to zero.
initialLastUpdateUtc System.DateTime The time when the value was set, which defaults to now.
Результат System

GetValue() публичный Метод

Get the value of the double at a given instant in time. If using the current system time, the preferred way to get the value is not to call this method but to simply access the Value field.
public GetValue ( System.TimeSpan halfLife, System.DateTime whenUtc = null ) : double
halfLife System.TimeSpan The half life to use when determining the current value.
whenUtc System.DateTime The instant of time for which the value should be calcualted, factoring in /// the decay rate. The default time is the current UTC time.
Результат double

SetValue() публичный Метод

public SetValue ( DecayingDouble source ) : void
source DecayingDouble
Результат void

SetValue() публичный Метод

Set the value at a point in time. If setting using the current system time, the preferred approach is to simply set the Value field.
public SetValue ( double newValue, System.DateTime whenUtc = null ) : void
newValue double The new value to set.
whenUtc System.DateTime When the set happened so as to correctly calculate future decay rates. /// Should be adjusted to UTC time. /// The default time is the current system time adjusted to UTC.
Результат void

Subtract() публичный Метод

public Subtract ( System.TimeSpan halfLife, DecayingDouble amountToRemove ) : DecayingDouble
halfLife System.TimeSpan
amountToRemove DecayingDouble
Результат DecayingDouble

SubtractInPlace() публичный Метод

public SubtractInPlace ( System.TimeSpan halfLife, DecayingDouble amountToSubtract ) : void
halfLife System.TimeSpan
amountToSubtract DecayingDouble
Результат void

SubtractInPlace() публичный Метод

public SubtractInPlace ( System.TimeSpan halfLife, double amountToSubtract, System.DateTime whenToSubtractIt ) : void
halfLife System.TimeSpan
amountToSubtract double
whenToSubtractIt System.DateTime
Результат void