-
Notifications
You must be signed in to change notification settings - Fork 0
ConfidenceStack Class
Represents a collection that tracks unique values and their associated confidence scores, allowing items to be added, updated, removed, and enumerated in order of descending score.
Namespace: Rheo.Storage.Analyzing.Models.Result
Assembly: Rheo.Storage.dll
public class ConfidenceStack<T> : IEnumerable<Confidence<T>>, ICollection<Confidence<T>>
where T : notnullT
The type of values stored in the collection. Must be non-nullable.
| Constructor | Description |
|---|---|
| ConfidenceStack() | Initializes a new instance of the ConfidenceStack<T> class. |
| Property | Type | Description |
|---|---|---|
| Item[Int32] | Confidence<T> | Gets the element at the specified index in the collection. |
| TotalScore | Int32 | Gets the sum of the score values for all items in the collection. |
| Count | Int32 | Gets the number of elements contained in the collection. |
| Values | IEnumerable<T> | Gets an enumerable collection containing all values in the collection. |
| IsReadOnly | Boolean | Gets a value indicating whether the collection is read-only. |
| Method | Description |
|---|---|
| Push(T, Int32) | Adds the specified value to the collection with the given score, or increases its score if it already exists. |
| Pop() | Removes and returns the item with the highest confidence score from the collection. |
| Pop(T) | Removes the specified subject from the collection and returns its associated confidence value. |
| Add(Confidence<T>) | Adds a confidence instance to the collection. |
| Clear() | Removes all items from the collection. |
| Contains(Confidence<T>) | Determines whether the collection contains a specific confidence instance. |
| CopyTo(Confidence<T>[], Int32) | Copies the elements to an array, starting at a particular index. |
| Remove(Confidence<T>) | Removes a specific confidence instance from the collection. |
| ToList() | Creates a list of confidence values for each item, ordered from highest to lowest confidence. |
| GetEnumerator() | Returns an enumerator that iterates through the collection. |
| ToString() | Returns a string representation of the collection. |
Each value in the collection is associated with an integer confidence score. Adding a value that already exists increases its score by the specified amount. Items can be removed individually or all at once, and enumeration yields results ordered by descending score. This collection is not thread-safe.
The confidence percentage for each item is calculated dynamically based on its score relative to the total score of all items in the collection.
Gets the element at the specified index in the collection.
public Confidence<T> this[int index] { get; }index Int32
The zero-based index of the element to retrieve.
Confidence<T>
The element at the specified index.
The index is based on the sorted list (by descending confidence), not insertion order.
Gets the sum of the score values for all items in the collection.
public int TotalScore { get; }The total score of all items.
This value is used to calculate the confidence percentage for each item.
Gets the number of elements contained in the collection.
public int Count { get; }The number of elements in the collection.
Gets an enumerable collection containing all values in the collection.
public IEnumerable<T> Values { get; }IEnumerable<T>
An enumerable of all values without confidence information.
Gets a value indicating whether the collection is read-only.
public bool IsReadOnly { get; }Always returns false.
Adds the specified value to the collection with the given score, or increases its score if it already exists.
public void Push(T value, int score = 1)value T
The value to add to the collection or whose score to increase.
score Int32
The score to associate with the value. Defaults to 1. Must be a positive integer.
Removes and returns the item with the highest confidence score from the collection.
public Confidence<T>? Pop()Confidence<T>?
A Confidence<T> representing the item with the highest confidence score, or null if the collection is empty.
Removes the specified subject from the collection and returns its associated confidence value.
public Confidence<T> Pop(T subject)subject T
The subject to remove from the collection. Must exist in the collection.
Confidence<T>
A Confidence<T> instance representing the removed subject and its confidence percentage.
Thrown if the specified subject does not exist in the collection.
Adds a confidence instance to the collection.
public void Add(Confidence<T> item)item Confidence<T>
The confidence instance to add.
Removes all items from the collection.
public void Clear()Determines whether the collection contains a specific confidence instance.
public bool Contains(Confidence<T> item)item Confidence<T>
The confidence instance to locate.
true if the item's subject is found in the collection; otherwise, false.
Copies the elements to an array, starting at a particular index.
public void CopyTo(Confidence<T>[] array, int arrayIndex)array Confidence<T>[]
The destination array.
arrayIndex Int32
The zero-based index at which copying begins.
Removes a specific confidence instance from the collection.
public bool Remove(Confidence<T> item)item Confidence<T>
The confidence instance to remove.
true if the item was successfully removed; otherwise, false.
Creates a list of confidence values for each item, ordered from highest to lowest confidence.
public List<Confidence<T>> ToList()List<Confidence<T>>
A list of Confidence<T> objects sorted by descending confidence value.
The returned list is a snapshot of the collection at the time of access. Subsequent changes to the underlying collection are not reflected in the returned list.
Returns an enumerator that iterates through the collection.
public IEnumerator<Confidence<T>> GetEnumerator()An enumerator for the collection.
Returns a string representation of the collection.
public override string ToString()A string showing the count and total score.
The following example demonstrates basic usage:
using Rheo.Storage.Analyzing.Models.Result;
var stack = new ConfidenceStack<string>();
stack.Push("PNG", 1000);
stack.Push("JPEG", 500);
stack.Push("GIF", 250);
Console.WriteLine($"Total Score: {stack.TotalScore}");
Console.WriteLine($"Count: {stack.Count}");
foreach (var confidence in stack)
{
Console.WriteLine(confidence);
}
// Output:
// PNG (57.14%)
// JPEG (28.57%)
// GIF (14.29%)The following example shows how to update scores:
using Rheo.Storage.Analyzing.Models.Result;
var stack = new ConfidenceStack<string>();
stack.Push("PNG", 100);
stack.Push("PNG", 50); // Adds to existing score
stack.Push("JPEG", 75);
var topItem = stack[0];
Console.WriteLine($"{topItem.Subject}: {topItem.Value:F2}%");
// Output: PNG: 66.67%The following example demonstrates removing items:
using Rheo.Storage.Analyzing.Models.Result;
var stack = new ConfidenceStack<string>();
stack.Push("PNG", 100);
stack.Push("JPEG", 75);
stack.Push("GIF", 50);
// Remove top item
var top = stack.Pop();
Console.WriteLine($"Removed: {top}");
// Remove specific item
var jpeg = stack.Pop("JPEG");
Console.WriteLine($"Removed: {jpeg}");
Console.WriteLine($"Remaining: {stack.Count} items");The following example shows typical usage with file analysis results:
using Rheo.Storage.Analyzing;
using Rheo.Storage.Analyzing.Models.Result;
string filePath = @"C:\Documents\image.png";
AnalysisResult result = FileAnalyzer.AnalyzeFile(filePath);
var definitions = result.Definitions;
Console.WriteLine($"Found {definitions.Count} matches");
Console.WriteLine($"Total Score: {definitions.TotalScore}");
// Get top 3 matches
var top3 = definitions.ToList().Take(3);
foreach (var match in top3)
{
Console.WriteLine($"{match.Subject.FileType}: {match.Value:F2}%");
}This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress