Skip to content

Confidence Struct

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

Confidence<T> Struct

Represents a subject and its associated confidence score as a percentage.

Namespace: Rheo.Storage.Analyzing.Models.Result

Assembly: Rheo.Storage.dll

Definition

public readonly struct Confidence<T> : IEquatable<Confidence<T>> 
    where T : notnull

Type Parameters

T

The type of the subject to which the confidence score applies. Must be non-null.

Constructors

Constructor Description
Confidence(T, Double) Initializes a new instance of the Confidence<T> struct with the specified subject and confidence value.

Properties

Property Type Description
Subject T Gets the subject associated with this instance.
Value Double Gets the confidence score as a percentage.

Methods

Method Description
Equals(Confidence<T>) Determines whether the specified Confidence<T> is equal to the current instance.
Equals(Object) Determines whether the specified object is equal to the current instance.
GetHashCode() Returns the hash code for this instance.
ToString() Returns a string representation of the confidence.

Operators

Operator Description
Equality(Confidence<T>, Confidence<T>) Determines whether two Confidence<T> instances are equal.
Inequality(Confidence<T>, Confidence<T>) Determines whether two Confidence<T> instances are not equal.

Remarks

Use this struct to associate a confidence value with a specific subject, such as a prediction, classification, or result. The confidence score indicates the degree of certainty or reliability for the given subject. This type is immutable and thread-safe.

The struct implements value equality based on the subject only, not the confidence value. This means two instances with the same subject but different values are considered equal.


Constructor Details

Confidence(T, Double)

Initializes a new instance of the Confidence<T> struct with the specified subject and confidence value.

public Confidence(T subject, double value)

Parameters

subject T

The subject for which the confidence score is calculated. Cannot be null.

value Double

The confidence score as a percentage, typically between 0.0 and 100.0.


Property Details

Subject

Gets the subject associated with this instance.

public T Subject { get; init; }

Property Value

T

The subject of the confidence score.


Value

Gets the confidence score as a percentage.

public double Value { get; init; }

Property Value

Double

The confidence value as a percentage (0.0 to 100.0).

Remarks

The confidence score is calculated as the ratio of the current score to the total score, expressed as a percentage. If the total score is zero, the confidence is zero.


Method Details

Equals(Confidence<T>)

Determines whether the specified Confidence<T> is equal to the current instance.

public bool Equals(Confidence<T> other)

Parameters

other Confidence<T>

The Confidence<T> to compare with the current instance.

Returns

Boolean

true if the subjects are equal; otherwise, false.

Remarks

Equality is based solely on the subject, not the confidence value.


Equals(Object)

Determines whether the specified object is equal to the current instance.

public override bool Equals(object? obj)

Parameters

obj Object

The object to compare with the current instance.

Returns

Boolean

true if the object is a Confidence<T> with an equal subject; otherwise, false.


GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

Int32

A hash code based on the subject.


ToString()

Returns a string representation of the confidence.

public override string ToString()

Returns

String

A string in the format: Subject (Value%)


Operator Details

Equality Operator

Determines whether two Confidence<T> instances are equal.

public static bool operator ==(Confidence<T> left, Confidence<T> right)

Parameters

left Confidence<T>

The first instance to compare.

right Confidence<T>

The second instance to compare.

Returns

Boolean

true if the instances are equal; otherwise, false.


Inequality Operator

Determines whether two Confidence<T> instances are not equal.

public static bool operator !=(Confidence<T> left, Confidence<T> right)

Parameters

left Confidence<T>

The first instance to compare.

right Confidence<T>

The second instance to compare.

Returns

Boolean

true if the instances are not equal; otherwise, false.


Examples

Creating and Using Confidence Instances

The following example demonstrates how to create and use confidence instances:

using Rheo.Storage.Analyzing.Models;
using Rheo.Storage.Analyzing.Models.Result;

var pngDef = new Definition { FileType = "PNG Image", MimeType = "image/png" };
var confidence = new Confidence<Definition>(pngDef, 95.5);

Console.WriteLine($"Subject: {confidence.Subject.FileType}");
Console.WriteLine($"Confidence: {confidence.Value}%");
Console.WriteLine(confidence.ToString());
// Output: PNG Image, image/png, [] (95.50%)

Comparing Confidence Instances

The following example shows equality comparison:

using Rheo.Storage.Analyzing.Models.Result;

var conf1 = new Confidence<string>("PNG", 95.0);
var conf2 = new Confidence<string>("PNG", 85.0);
var conf3 = new Confidence<string>("JPEG", 95.0);

Console.WriteLine(conf1 == conf2); // True (same subject)
Console.WriteLine(conf1 == conf3); // False (different subject)
Console.WriteLine(conf1.Value == conf2.Value); // False (different values)

Working with Generic Confidence Types

The following example demonstrates using confidence with different types:

using Rheo.Storage.Analyzing.Models.Result;

// Confidence with string
var extensionConfidence = new Confidence<string>(".png", 75.0);
Console.WriteLine(extensionConfidence);
// Output: .png (75.00%)

// Confidence with int
var priorityConfidence = new Confidence<int>(100, 90.0);
Console.WriteLine(priorityConfidence);
// Output: 100 (90.00%)

Using in Collections

The following example shows how confidence instances work in collections:

using Rheo.Storage.Analyzing.Models.Result;

var confidences = new List<Confidence<string>>
{
    new Confidence<string>("PNG", 95.0),
    new Confidence<string>("JPEG", 85.0),
    new Confidence<string>("GIF", 75.0)
};

// Sort by confidence value
var sorted = confidences.OrderByDescending(c => c.Value).ToList();

foreach (var c in sorted)
{
    Console.WriteLine(c);
}
// Output:
// PNG (95.00%)
// JPEG (85.00%)
// GIF (75.00%)

Thread Safety

This struct is immutable and thread-safe.

See Also

Clone this wiki locally