cachesim/oracle_cache/
mod.rs

1//! Oracle Cache Examples.
2//! 
3//! Oracle cache hit on every access with exact 0 latency.
4
5use crate::cache_behav::{general_cache_behavior::*};
6
7/// Oracle Cache struct.
8#[derive(Debug)]
9pub struct OracleCache {
10    cachetype:String
11}
12
13impl OracleCache {
14    pub fn new() -> Self {
15        OracleCache{ cachetype:String::from("oracle") }
16    }
17}
18
19impl GeneralCacheBehavior for OracleCache {
20    fn init(&mut self, filename:&str) -> Result<(), String> {
21        use std::fs::*;
22
23        let content = read_to_string(filename);
24        match content {
25            Err(_) => Err(format!("failed to read {}", filename)),
26            Ok(_) => {
27                // verifing type is oracle.
28                let content = content.unwrap();
29                match content.find("type=oracle") {
30                    None => Err(format!("type mismatched: except oracle")),
31                    Some(_) => Ok(()),
32                }
33            },
34        }
35    }
36    fn get_type(&self) -> &str {
37        &self.cachetype
38    }
39    fn access(&mut self, _addr:u32) -> AccessResult {
40        AccessResult(HitOrMiss::Hit, 0.0)
41    }
42    fn clear(&mut self) {}
43
44    fn size(&self) -> usize { 0 }
45}