|
1 | | -from __future__ import annotations |
2 | | - |
3 | | -from typing import Protocol, TYPE_CHECKING |
4 | | - |
5 | | -if TYPE_CHECKING: |
6 | | - from .libcachesim_python import Request, CacheObject, Reader, Analyzer |
7 | | - |
8 | | - |
9 | | -class CacheProtocol(Protocol): |
10 | | - def get(self, req: Request) -> bool: ... |
11 | | - |
12 | | - def find(self, req: Request, update_cache: bool = True) -> CacheObject: ... |
13 | | - |
14 | | - def can_insert(self, req: Request) -> bool: ... |
| 1 | +""" |
| 2 | +Reader protocol for libCacheSim Python bindings. |
15 | 3 |
|
16 | | - def insert(self, req: Request) -> CacheObject: ... |
| 4 | +ReaderProtocol defines the interface contract for trace readers, |
| 5 | +enabling different implementations (Python/C++) to work interchangeably. |
| 6 | +""" |
17 | 7 |
|
18 | | - def need_eviction(self, req: Request) -> bool: ... |
19 | | - |
20 | | - def evict(self, req: Request) -> CacheObject: ... |
21 | | - |
22 | | - def remove(self, obj_id: int) -> bool: ... |
23 | | - |
24 | | - def to_evict(self, req: Request) -> CacheObject: ... |
25 | | - |
26 | | - def get_occupied_byte(self) -> int: ... |
27 | | - |
28 | | - def get_n_obj(self) -> int: ... |
29 | | - |
30 | | - def print_cache(self) -> str: ... |
| 8 | +from __future__ import annotations |
| 9 | +from typing import Protocol, runtime_checkable, TYPE_CHECKING |
31 | 10 |
|
32 | | - def process_trace(self, reader: "ReaderProtocol", start_req: int = 0, max_req: int = -1) -> tuple[float, float]: ... |
| 11 | +if TYPE_CHECKING: |
| 12 | + from .libcachesim_python import Request |
33 | 13 |
|
34 | | - # Properties |
35 | | - @property |
36 | | - def cache_size(self) -> int: ... |
37 | 14 |
|
38 | | - @property |
39 | | - def cache_name(self) -> str: ... |
| 15 | +@runtime_checkable |
| 16 | +class ReaderProtocol(Protocol): |
| 17 | + """Protocol for trace readers |
40 | 18 |
|
| 19 | + This protocol ensures that different reader implementations |
| 20 | + (SyntheticReader, TraceReader) can be used interchangeably. |
| 21 | + """ |
41 | 22 |
|
42 | | -class ReaderProtocol(Protocol): |
43 | 23 | def get_num_of_req(self) -> int: ... |
44 | | - |
45 | 24 | def read_one_req(self, req: Request) -> Request: ... |
46 | | - |
47 | 25 | def reset(self) -> None: ... |
48 | | - |
49 | 26 | def close(self) -> None: ... |
50 | | - |
51 | | - def clone(self) -> ReaderProtocol: ... |
52 | | - |
| 27 | + def clone(self) -> "ReaderProtocol": ... |
53 | 28 | def read_first_req(self, req: Request) -> Request: ... |
54 | | - |
55 | 29 | def read_last_req(self, req: Request) -> Request: ... |
56 | | - |
57 | 30 | def skip_n_req(self, n: int) -> int: ... |
58 | | - |
59 | 31 | def read_one_req_above(self, req: Request) -> Request: ... |
60 | | - |
61 | 32 | def go_back_one_req(self) -> None: ... |
62 | | - |
63 | 33 | def set_read_pos(self, pos: float) -> None: ... |
64 | | - |
65 | 34 | def get_read_pos(self) -> float: ... |
66 | | - |
67 | | - |
68 | | -class AnalyzerProtocol(Protocol): |
69 | | - def run(self) -> None: ... |
70 | | - |
71 | | - def cleanup(self) -> None: ... |
0 commit comments