use crate::Value;
use indexmap::IndexMap;
pub const KIND_ARRAY_CACHE: &str = "ArrayCache";
pub const KIND_ARRAY_CACHE_BY_TIMESTAMP: &str = "ArrayCacheByTimestamp";
pub const KIND_ARRAY_CACHE_BY_SYMBOL_ID: &str = "ArrayCacheBySymbolById";
pub const KIND_ARRAY_CACHE_BY_SYMBOL_SIDE: &str = "ArrayCacheBySymbolBySide";
pub const KIND_ARRAY_CACHE_BY_OUTCOME_ID: &str = "ArrayCacheByOutcomeById";
fn new_marker(kind: &str, max_size: Value) -> Value {
let mut state: IndexMap<String, Value> = IndexMap::new();
state.insert("_data".to_string(), Value::Array(Vec::new()));
state.insert("hashmap".to_string(), Value::Map(IndexMap::new()));
state.insert("_newUpdatesBySymbol".to_string(), Value::Map(IndexMap::new()));
state.insert("_seenUpdatesBySymbol".to_string(), Value::Map(IndexMap::new()));
state.insert("_seenUpdatesAll".to_string(), Value::Map(IndexMap::new()));
state.insert("_clearUpdatesBySymbol".to_string(), Value::Map(IndexMap::new()));
state.insert("_allNewUpdates".to_string(), Value::Int(0));
state.insert("_clearAllUpdates".to_string(), Value::Bool(false));
state.insert("_sizeTracker".to_string(), Value::Map(IndexMap::new()));
state.insert("_newUpdates".to_string(), Value::Int(0));
state.insert("_clearUpdates".to_string(), Value::Bool(false));
let id = crate::value::alloc_cache_id(state);
let mut m = IndexMap::new();
m.insert("__cacheKind".to_string(), Value::Str(kind.to_string().into()));
m.insert("__cache_id".to_string(), Value::Int(id));
m.insert("maxSize".to_string(), max_size);
Value::Map(m)
}
pub struct ArrayCache;
impl ArrayCache {
pub fn new(max_size: Value) -> Value {
new_marker(KIND_ARRAY_CACHE, max_size)
}
}
pub struct ArrayCacheByTimestamp;
impl ArrayCacheByTimestamp {
pub fn new(max_size: Value) -> Value {
new_marker(KIND_ARRAY_CACHE_BY_TIMESTAMP, max_size)
}
}
pub struct ArrayCacheBySymbolById;
impl ArrayCacheBySymbolById {
pub fn new(max_size: Value) -> Value {
new_marker(KIND_ARRAY_CACHE_BY_SYMBOL_ID, max_size)
}
}
pub struct ArrayCacheBySymbolBySide;
impl ArrayCacheBySymbolBySide {
pub fn new(max_size: Value) -> Value {
new_marker(KIND_ARRAY_CACHE_BY_SYMBOL_SIDE, max_size)
}
}
pub struct ArrayCacheByOutcomeById;
impl ArrayCacheByOutcomeById {
pub fn new(max_size: Value) -> Value {
new_marker(KIND_ARRAY_CACHE_BY_OUTCOME_ID, max_size)
}
}