<PackageReference Include="Microsoft.ApplicationInsights" Version="2.23.0" />

Microsoft.ApplicationInsights.Metrics.ConcurrentDatastructures.MultidimensionalCube<TDimensionValue, TPoint>

class MultidimensionalCube<TDimensionValue, TPoint>
Represents a multi-dimensional, discrete data cube. An N-dimensional discrete cube is a data structure containing elements of type TPoint. Each point can be addressed using a coordinate-vector containing N entries of type TDimensionValue. For example, the elements in the cube may be colors, space vectors or sold items (with its properties as coordinates). However, the key usage in this library are multidimensional metrics. In such usage the coordinates are metric dimensions (TDimensionValue is String) and the cube elements (TPoint) are metric data series. The cube refers to dimensions using their index: 0th, 1st, 2nd dimension and so on. For each dimension, the cube has a SubdimensionsCountLimit parameter. This limits the number of distinct values that may be specified for that specific sub-dimension (given concrete values for lower dimensions). Once the SubdimensionsCountLimit for some particular dimension is reached, the cube will no longer be able to create points whose coordinate vectors contain values for that particular dimension that do not occur in coordinate vectors for points already in the cube. The cube also has a TotalPointsCountLimit parameter that limits the total number of points in the cube. The elements of the coordinate vectors (i.e. the values of the dimensions of a point in the cube) are discrete. Even if their type implies a non-discrete space (e.g.when TDimensionValue is Double) they are always treated as discrete and separate. The cube is designed to work in concurrent scenarios while minimizing the number, the duration and the scope of locks taken. However, some locks are necessary to correctly impose the SubdimensionsCountLimits and the TotalPointsCountLimit constrains. This implementation assumes that creation and storage of TPoint-elements is resource intensive. It creates points lazily, only when requested. However, to minimize locking it uses pessimistic and optimistic concurrency mechanisms where possible. Two artifacts occur as a result: The specified pointsFactory delegate may be executed more than once for a particular coordinates vector. However, once a point for the specified coordinates-vector has been actually returned to the caller, always the same instance of that point will be returned by the cube. This behaviour is consistent with the ConcurrentDictionary in the .NET Framework.The TryGetOrCreatePoint(..) may return false, and then return true moments later when called with the same parameters. This is because in order to avoid locking the cube pre-books dimension value counts (and total points counts) and later frees them up if the creation of a new point did not complete. Notably, this artifact does not represent any problems in practice: It occurs only in concurrent races when the number of values of a dimension (or the total number of points) is close to the limit, where applications should not rely on a particular outcome of adding a point anyway. In common cases one can assume that the result of TryGetOrCreatePoint(..) is, indeed, stable. In order to control potential instability use TryGetOrCreatePointAsync(..) overloads. Note, however, that those overloads do not guarantee that the result of requesting a new point is completely stable. They merely make it very unlikely for it to change by re-trying the operation several times.
namespace Microsoft.ApplicationInsights.Metrics.ConcurrentDatastructures { }