pub struct ModelPricingMap { /* private fields */ }Expand description
Optimized pricing map with precomputed indices for O(1) exact matches and fast fuzzy matching.
Implementations§
Source§impl ModelPricingMap
impl ModelPricingMap
Sourcepub fn new(raw: HashMap<String, ModelPricing>) -> Self
pub fn new(raw: HashMap<String, ModelPricing>) -> Self
Creates a new pricing map with precomputed indices for optimized lookups.
This constructor processes the raw pricing data to build:
- Normalized key index for version-agnostic matching.
- Lowercase key list for substring and fuzzy matching.
§Examples
use std::collections::HashMap;
use vct_core::pricing::{ModelPricing, ModelPricingMap};
let mut raw = HashMap::new();
raw.insert("gpt-4".to_string(), ModelPricing::default());
let map = ModelPricingMap::new(raw);
assert!(!map.is_empty());Sourcepub fn get(&self, model_name: &str) -> ModelPricingResult
pub fn get(&self, model_name: &str) -> ModelPricingResult
Retrieves pricing for a model using a multi-tier matching strategy.
Matching strategy (in order of priority):
- Exact match (O(1) hash lookup).
- Normalized match (removes version suffixes).
- Substring match (bidirectional contains check).
- Fuzzy match (Jaro-Winkler ≥ 0.7 threshold).
- Default (zero cost) if no match found.
Results are cached per map. clear_pricing_cache invalidates every
existing map lazily, so even the “no match” outcome can be memoized
without leaking a result from one pricing table into another.
§Examples
use std::collections::HashMap;
use vct_core::pricing::{ModelPricing, ModelPricingMap};
let mut raw = HashMap::new();
raw.insert(
"gpt-4".to_string(),
ModelPricing { input_cost_per_token: 3e-5, ..Default::default() },
);
let map = ModelPricingMap::new(raw);
// Exact match: `matched_model` stays `None`.
let hit = map.get("gpt-4");
assert_eq!(hit.pricing.input_cost_per_token, 3e-5);
assert!(hit.matched_model.is_none());
// No match: zero-cost default.
let miss = map.get("does-not-exist-xyzzy");
assert_eq!(miss.pricing.input_cost_per_token, 0.0);Sourcepub fn get_exact(&self, model_name: &str) -> Option<ModelPricing>
pub fn get_exact(&self, model_name: &str) -> Option<ModelPricing>
Returns the pricing for an exact model-name match only.
Unlike get, this performs no normalization, substring, or
fuzzy matching: it returns Some only when model_name is a verbatim
key in the pricing table, and None otherwise. This is the lookup used
for providers (OpenCode) that carry their own authoritative cost and
should fall back to that stored cost rather than guess a price from a
loosely-similar model name.
Sourcepub fn raw(&self) -> &HashMap<Rc<str>, ModelPricing>
pub fn raw(&self) -> &HashMap<Rc<str>, ModelPricing>
Returns the raw pricing data with reference-counted keys.
Sourcepub fn tier_thresholds(&self) -> TierThresholds
pub fn tier_thresholds(&self) -> TierThresholds
Builds the Send + Sync “model → lowest context-tier threshold”
snapshot the usage scan hands to session parsers for per-request tier
classification. Models without threshold tiers are absent.
Trait Implementations§
Source§impl Clone for ModelPricingMap
impl Clone for ModelPricingMap
Source§fn clone(&self) -> ModelPricingMap
fn clone(&self) -> ModelPricingMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for ModelPricingMap
impl !RefUnwindSafe for ModelPricingMap
impl !Send for ModelPricingMap
impl !Sync for ModelPricingMap
impl Unpin for ModelPricingMap
impl UnsafeUnpin for ModelPricingMap
impl UnwindSafe for ModelPricingMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more