Skip to content

Commit

Permalink
Fix Cumulation typos
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Nov 23, 2023
1 parent f27e1c7 commit cbe0885
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
50 changes: 25 additions & 25 deletions lib/core/include/qx/core/qx-cumulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Extra-component Includes
#include "qx/utility/qx-concepts.h"

/* TODO: An iterator can't be added to this class unless it deferences to a special class like the QJsonValueRef
/* TODO: An iterator can't be added to this class unless it dereferences to a special class like the QJsonValueRef
* approach since when the value is modified the running total would need to be changed as well. That or the running
* total needs to be done away with and the total() method needs to calculate the total each time its called (ehhhh)
*/
Expand All @@ -22,7 +22,7 @@ class Cumulation
//-Instance Variables----------------------------------------------------------------------------------------------
private:
QHash<K, V> mComponents;
QHash<K, V> mScalers;
QHash<K, V> mScalars;
V mTotal;

//-Constructor----------------------------------------------------------------------------------------------
Expand All @@ -47,31 +47,31 @@ class Cumulation
return !mComponents.isEmpty() ? mTotal/mComponents.count() : 0;
}

void basicInsert(K component, V value, V scaler)
void basicInsert(K component, V value, V scalar)
{
mTotal += value * scaler;
mTotal += value * scalar;
mComponents[component] = value;
mScalers[component] = scaler;
mScalars[component] = scalar;
}

public:
void insert(K component, V value, V scaler = 1)
void insert(K component, V value, V scalar = 1)
{
// If replacing an existing value, remove its portion from the running total if its not the same
if(mComponents.contains(component))
{
const V& curVal = mComponents[component];
const V& curScal = mScalers[component];
const V& curScal = mScalars[component];

// Remove old component portion from running total if different
if(curVal != value || curScal != scaler)
if(curVal != value || curScal != scalar)
mTotal -= curVal * curScal;
else
return;
}

// Insert/replace
basicInsert(component, value, scaler);
basicInsert(component, value, scalar);
}

void setValue(K component, V value)
Expand All @@ -81,36 +81,36 @@ class Cumulation
V& curVal = mComponents[component];
if(value != curVal)
{
const V& scaler = mScalers[component];
mTotal += (value * scaler) - (curVal * scaler);
const V& scalar = mScalars[component];
mTotal += (value * scalar) - (curVal * scalar);
curVal = value;
}
}
else
basicInsert(component, value, 1);
}

void setScaler(K component, V scaler)
void setScalar(K component, V scalar)
{
if(mComponents.contains(component))
{
V& curScaler = mScalers[component];
if(scaler != curScaler)
V& curScalar = mScalars[component];
if(scalar != curScalar)
{
const V& value = mComponents[component];
mTotal += (value * scaler) - (value * curScaler);
curScaler = scaler;
mTotal += (value * scalar) - (value * curScalar);
curScalar = scalar;
}
}
else
basicInsert(component, 0, scaler);
basicInsert(component, 0, scalar);
}

void increase(K component, V amount)
{
if(mComponents.contains(component))
{
mTotal += amount * mScalers[component];
mTotal += amount * mScalars[component];
mComponents[component] += amount;
}
else
Expand All @@ -121,7 +121,7 @@ class Cumulation
{
if(mComponents.contains(component))
{
mTotal -= amount * mScalers[component];
mTotal -= amount * mScalars[component];
mComponents[component] -= amount;
}
else
Expand All @@ -132,7 +132,7 @@ class Cumulation
{
if(mComponents.contains(component))
{
mTotal += mScalers[component];
mTotal += mScalars[component];
mComponents[component]++;
}
else
Expand All @@ -145,7 +145,7 @@ class Cumulation
{
if(mComponents.contains(component))
{
mTotal -= mScalers[component];
mTotal -= mScalars[component];
mComponents[component]--;
}
else
Expand All @@ -158,16 +158,16 @@ class Cumulation
{
if(mComponents.contains(component))
{
mTotal -= (mComponents[component] * mScalers[component]);
mTotal -= (mComponents[component] * mScalars[component]);
mComponents.remove(component);
mScalers.remove(component);
mScalars.remove(component);
}
}

void clear()
{
mComponents.clear();
mScalers.clear();
mScalars.clear();
mTotal = 0;
}

Expand All @@ -182,7 +182,7 @@ class Cumulation

bool operator==(const Cumulation& other) const
{
return mComponents == other.mComponents && mScalers == other.mScalers && mTotal == other.mTotal;
return mComponents == other.mComponents && mScalars == other.mScalars && mTotal == other.mTotal;
}

bool operator!=(const Cumulation& other) const { return !(*this == other); }
Expand Down
28 changes: 14 additions & 14 deletions lib/core/src/qx-cumulation.dox
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Qx
* contained values is always known, and any individual value can be added, removed, or updated through its
* corresponding key.
*
* Additionally, a cumulation can have optional scalers applied to its components in order to differently
* Additionally, a cumulation can have optional scalars applied to its components in order to differently
* weight their individual effect on the total.
*
* This is generally useful for keeping a running total, but when a previously added value may need to be
Expand All @@ -34,12 +34,12 @@ namespace Qx
//-Class Functions----------------------------------------------------------------------------------------------
//Public:
/*!
* @fn void Cumulation<K, V>::insert(K component, V value, V scaler = 1)
* @fn void Cumulation<K, V>::insert(K component, V value, V scalar = 1)
*
* Inserts a new component with key @a component, value @a value, and scaler @a scaler.
* Inserts a new component with key @a component, value @a value, and scalar @a scalar.
*
* If there is already a component with the same key, that component's value and scaler are replaced with
* @a value and @a scaler respectively.
* If there is already a component with the same key, that component's value and scalar are replaced with
* @a value and @a scalar respectively.
*/

/*!
Expand All @@ -48,19 +48,19 @@ namespace Qx
* Sets the value of @a component to @a value.
*
* If the cumulation does not contain the specified component it will be added with a value of
* @a value and a scaler of 1.
* @a value and a scalar of 1.
*/

/*!
* @fn void Cumulation<K, V>::setScaler(K component, V scaler)
* @fn void Cumulation<K, V>::setScalar(K component, V scalar)
*
* Sets the scaler of @a component to @a scaler.
* Sets the scalar of @a component to @a scalar.
*
* The amount that a component contributes to a cumulation's total is its value multiplied
* by its scaler.
* by its scalar.
*
* If the cumulation does not contain the specified component it will be added with a value of
* 0 and a scaler of @a scaler.
* 0 and a scalar of @a scalar.
*/

/*!
Expand All @@ -69,7 +69,7 @@ namespace Qx
* Adds @a amount to the value of @a component.
*
* If the cumulation does not contain the specified component it will be added with a value of
* @a amount and a scaler of 1.
* @a amount and a scalar of 1.
*/

/*!
Expand All @@ -78,7 +78,7 @@ namespace Qx
* Subtracts @a amount from the value of @a component.
*
* If the cumulation does not contain the specified component it will be added with a value of
* <em>-amount</em> and a scaler of 1.
* <em>-amount</em> and a scalar of 1.
*/

/*!
Expand All @@ -87,7 +87,7 @@ namespace Qx
* Increments the value of the given @a component and returns the new total.
*
* If the cumulation does not contain the specified component it will be added with a value of
* 1 and a scaler of 1.
* 1 and a scalar of 1.
*/

/*!
Expand All @@ -96,7 +96,7 @@ namespace Qx
* Decrements the value of the given @a component and returns the new total.
*
* If the cumulation does not contain the specified component it will be added with a value of
* -1 and a scaler of 1.
* -1 and a scalar of 1.
*/

/*!
Expand Down

0 comments on commit cbe0885

Please sign in to comment.