Skip to content

Commit 280c71a

Browse files
committed
Format cpp and py
1 parent 06a3dfa commit 280c71a

File tree

7 files changed

+218
-736
lines changed

7 files changed

+218
-736
lines changed

.clang-format

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
ColumnLimit: 80
5+
AccessModifierOffset: -1
6+
AlignAfterOpenBracket: Align
7+
AlignConsecutiveMacros: false
8+
AlignConsecutiveAssignments: false
9+
AlignConsecutiveDeclarations: false
10+
AlignEscapedNewlines: Left
11+
AlignOperands: true
12+
AlignTrailingComments: true
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllConstructorInitializersOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortBlocksOnASingleLine: Never
17+
AllowShortCaseLabelsOnASingleLine: false
18+
AllowShortFunctionsOnASingleLine: All
19+
AllowShortLambdasOnASingleLine: All
20+
AllowShortIfStatementsOnASingleLine: WithoutElse
21+
AllowShortLoopsOnASingleLine: true
22+
AlwaysBreakAfterDefinitionReturnType: None
23+
AlwaysBreakAfterReturnType: None
24+
AlwaysBreakBeforeMultilineStrings: true
25+
AlwaysBreakTemplateDeclarations: Yes
26+
BinPackArguments: true
27+
BinPackParameters: true
28+
BraceWrapping:
29+
AfterCaseLabel: false
30+
AfterClass: false
31+
AfterControlStatement: false
32+
AfterEnum: false
33+
AfterFunction: false
34+
AfterNamespace: false
35+
AfterObjCDeclaration: false
36+
AfterStruct: false
37+
AfterUnion: false
38+
AfterExternBlock: false
39+
BeforeCatch: false
40+
BeforeElse: false
41+
IndentBraces: false
42+
SplitEmptyFunction: true
43+
SplitEmptyRecord: true
44+
SplitEmptyNamespace: true
45+
BreakBeforeBinaryOperators: None
46+
BreakBeforeBraces: Attach
47+
BreakBeforeInheritanceComma: false
48+
BreakInheritanceList: BeforeColon
49+
BreakBeforeTernaryOperators: true
50+
BreakConstructorInitializersBeforeComma: false
51+
BreakConstructorInitializers: BeforeColon
52+
BreakAfterJavaFieldAnnotations: false
53+
BreakStringLiterals: true
54+
CommentPragmas: '^ IWYU pragma:'
55+
CompactNamespaces: false
56+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
57+
ConstructorInitializerIndentWidth: 4
58+
ContinuationIndentWidth: 4
59+
Cpp11BracedListStyle: true
60+
DeriveLineEnding: true
61+
DerivePointerAlignment: true
62+
DisableFormat: false
63+
ExperimentalAutoDetectBinPacking: false
64+
FixNamespaceComments: true
65+
ForEachMacros:
66+
- foreach
67+
- Q_FOREACH
68+
- BOOST_FOREACH
69+
IncludeBlocks: Regroup
70+
IncludeCategories:
71+
- Regex: '^<ext/.*\.h>'
72+
Priority: 2
73+
SortPriority: 0
74+
- Regex: '^<.*\.h>'
75+
Priority: 1
76+
SortPriority: 0
77+
- Regex: '^<.*'
78+
Priority: 2
79+
SortPriority: 0
80+
- Regex: '.*'
81+
Priority: 3
82+
SortPriority: 0
83+
IncludeIsMainRegex: '([-_](test|unittest))?$'
84+
IncludeIsMainSourceRegex: ''
85+
IndentCaseLabels: true
86+
IndentGotoLabels: true
87+
IndentPPDirectives: None
88+
IndentWidth: 2
89+
IndentWrappedFunctionNames: false
90+
JavaScriptQuotes: Leave
91+
JavaScriptWrapImports: true
92+
KeepEmptyLinesAtTheStartOfBlocks: false
93+
MacroBlockBegin: ''
94+
MacroBlockEnd: ''
95+
MaxEmptyLinesToKeep: 1
96+
NamespaceIndentation: None
97+
ObjCBinPackProtocolList: Never
98+
ObjCBlockIndentWidth: 2
99+
ObjCSpaceAfterProperty: false
100+
ObjCSpaceBeforeProtocolList: true
101+
PenaltyBreakAssignment: 2
102+
PenaltyBreakBeforeFirstCallParameter: 1
103+
PenaltyBreakComment: 300
104+
PenaltyBreakFirstLessLess: 120
105+
PenaltyBreakString: 1000
106+
PenaltyBreakTemplateDeclaration: 10
107+
PenaltyExcessCharacter: 1000000
108+
PenaltyReturnTypeOnItsOwnLine: 200
109+
PointerAlignment: Left
110+
RawStringFormats:
111+
- Language: Cpp
112+
Delimiters:
113+
- cc
114+
- CC
115+
- cpp
116+
- Cpp
117+
- CPP
118+
- 'c++'
119+
- 'C++'
120+
CanonicalDelimiter: ''
121+
BasedOnStyle: google
122+
- Language: TextProto
123+
Delimiters:
124+
- pb
125+
- PB
126+
- proto
127+
- PROTO
128+
EnclosingFunctions:
129+
- EqualsProto
130+
- EquivToProto
131+
- PARSE_PARTIAL_TEXT_PROTO
132+
- PARSE_TEST_PROTO
133+
- PARSE_TEXT_PROTO
134+
- ParseTextOrDie
135+
- ParseTextProtoOrDie
136+
CanonicalDelimiter: ''
137+
BasedOnStyle: google
138+
ReflowComments: true
139+
SortIncludes: true
140+
SortUsingDeclarations: true
141+
SpaceAfterCStyleCast: false
142+
SpaceAfterLogicalNot: false
143+
SpaceAfterTemplateKeyword: true
144+
SpaceBeforeAssignmentOperators: true
145+
SpaceBeforeCpp11BracedList: false
146+
SpaceBeforeCtorInitializerColon: true
147+
SpaceBeforeInheritanceColon: true
148+
SpaceBeforeParens: ControlStatements
149+
SpaceBeforeRangeBasedForLoopColon: true
150+
SpaceInEmptyBlock: false
151+
SpaceInEmptyParentheses: false
152+
SpacesBeforeTrailingComments: 2
153+
SpacesInAngles: false
154+
SpacesInConditionalStatement: false
155+
SpacesInContainerLiterals: true
156+
SpacesInCStyleCastParentheses: false
157+
SpacesInParentheses: false
158+
SpacesInSquareBrackets: false
159+
SpaceBeforeSquareBrackets: false
160+
Standard: Auto
161+
StatementMacros:
162+
- Q_UNUSED
163+
- QT_REQUIRE_VERSION
164+
TabWidth: 8
165+
UseCRLF: false
166+
UseTab: Never
167+
...

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,5 @@ sftp-config.json
231231
# Custom files
232232
CMakeFiles/*
233233
*.pyc
234-
!scripts/smart_build.py
234+
!scripts/smart_build.py
235+
uv.lock

libcachesim/synthetic_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ def set_read_pos(self, pos: float) -> None:
181181
def get_read_pos(self) -> float:
182182
"""Get current read position"""
183183
return float(self.current_pos)
184-
184+
185185
def get_working_set_size(self) -> Tuple[int, int]:
186186
"""Calculate working set size"""
187187
wss_obj, wss_byte = 0, 0
188188
if self.current_pos > 0:
189-
unique_ids = np.unique(self.obj_ids[:self.current_pos])
189+
unique_ids = np.unique(self.obj_ids[: self.current_pos])
190190
wss_obj = len(unique_ids)
191191
wss_byte = wss_obj * self.obj_size
192192
return wss_obj, wss_byte

libcachesim/trace_reader.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
from urllib.parse import urlparse
77

88
from .protocols import ReaderProtocol
9-
from .libcachesim_python import TraceType, SamplerType, Request, ReaderInitParam, Reader, Sampler, ReadDirection, cal_working_set_size
9+
from .libcachesim_python import (
10+
TraceType,
11+
SamplerType,
12+
Request,
13+
ReaderInitParam,
14+
Reader,
15+
Sampler,
16+
ReadDirection,
17+
cal_working_set_size,
18+
)
1019
from ._s3_cache import get_data_loader
1120

1221
logger = logging.getLogger(__name__)

src/export_cache.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace libcachesim {
2828

2929
namespace py = pybind11;
3030

31-
const cache_obj_t* LHD_HIT_MARKER = reinterpret_cast<cache_obj_t *>(0x1);
31+
const cache_obj_t* LHD_HIT_MARKER = reinterpret_cast<cache_obj_t*>(0x1);
3232

3333
// Custom deleters for smart pointers
3434
struct CacheDeleter {
@@ -258,7 +258,7 @@ auto make_cache_wrapper(const std::string& fn_name) {
258258
cache_t* ptr = InitFn(cc_params, params_cstr);
259259
return std::unique_ptr<cache_t, CacheDeleter>(ptr);
260260
},
261-
"cc_params"_a, "cache_specific_params"_a = "");
261+
"cc_params"_a, "cache_specific_params"_a = "");
262262
};
263263
}
264264

@@ -281,18 +281,21 @@ void export_cache(py::module& m) {
281281
"req"_a)
282282
.def(
283283
"find",
284-
[](cache_t& self, const request_t& req, const bool update_cache) -> py::object {
284+
[](cache_t& self, const request_t& req,
285+
const bool update_cache) -> py::object {
285286
cache_obj_t* obj = self.find(&self, &req, update_cache);
286287
// Return None if obj is null (not found)
287288
if (obj == nullptr) {
288-
return py::none();
289+
return py::none();
289290
}
290291
// NOTE(haocheng): For LHD only, return a dummy object for hit
291292
if (obj == LHD_HIT_MARKER) {
292-
cache_obj_t* dummy_obj = static_cast<cache_obj_t*>(calloc(1, sizeof(cache_obj_t)));
293-
dummy_obj->obj_id = req.obj_id;
294-
dummy_obj->obj_size = req.obj_size;
295-
return py::cast(std::unique_ptr<cache_obj_t, CacheObjectDeleter>(dummy_obj));
293+
cache_obj_t* dummy_obj =
294+
static_cast<cache_obj_t*>(calloc(1, sizeof(cache_obj_t)));
295+
dummy_obj->obj_id = req.obj_id;
296+
dummy_obj->obj_size = req.obj_size;
297+
return py::cast(
298+
std::unique_ptr<cache_obj_t, CacheObjectDeleter>(dummy_obj));
296299
}
297300
return py::cast(obj, py::return_value_policy::reference);
298301
},
@@ -303,23 +306,25 @@ void export_cache(py::module& m) {
303306
return self.can_insert(&self, &req);
304307
},
305308
"req"_a)
306-
.def(
307-
"insert",
308-
[](cache_t& self, const request_t& req) -> std::optional<cache_obj_t*> {
309-
cache_obj_t* inserted = self.insert(&self, &req);
310-
if (inserted == nullptr) {
311-
return std::nullopt;
312-
}
313-
return inserted;
314-
},
315-
"req"_a,
316-
py::return_value_policy::reference // optional still respected
317-
)
318-
309+
.def(
310+
"insert",
311+
[](cache_t& self,
312+
const request_t& req) -> std::optional<cache_obj_t*> {
313+
cache_obj_t* inserted = self.insert(&self, &req);
314+
if (inserted == nullptr) {
315+
return std::nullopt;
316+
}
317+
return inserted;
318+
},
319+
"req"_a,
320+
py::return_value_policy::reference // optional still respected
321+
)
322+
319323
.def(
320324
"need_eviction",
321325
[](cache_t& self, const request_t& req) {
322-
return self.get_occupied_byte(&self) + req.obj_size > self.cache_size;
326+
return self.get_occupied_byte(&self) + req.obj_size >
327+
self.cache_size;
323328
},
324329
"req"_a)
325330
.def(
@@ -370,7 +375,8 @@ void export_cache(py::module& m) {
370375
params->default_ttl = default_ttl;
371376
params->hashpower = hashpower;
372377
params->consider_obj_metadata = consider_obj_metadata;
373-
return std::unique_ptr<common_cache_params_t, CommonCacheParamsDeleter>(params);
378+
return std::unique_ptr<common_cache_params_t,
379+
CommonCacheParamsDeleter>(params);
374380
}),
375381
"cache_size"_a, "default_ttl"_a = 86400 * 300, "hashpower"_a = 24,
376382
"consider_obj_metadata"_a = false)

src/export_reader.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ struct SamplerDeleter {
6161
}
6262
};
6363

64-
6564
void export_reader(py::module& m) {
6665
/* Helper function(s) */
67-
m.def("cal_working_set_size", [](reader_t& reader) {
68-
int64_t wss_obj = 0, wss_byte = 0;
69-
cal_working_set_size(&reader, &wss_obj, &wss_byte);
70-
return std::make_tuple(wss_obj, wss_byte);
71-
}, "reader"_a);
66+
m.def(
67+
"cal_working_set_size",
68+
[](reader_t& reader) {
69+
int64_t wss_obj = 0, wss_byte = 0;
70+
cal_working_set_size(&reader, &wss_obj, &wss_byte);
71+
return std::make_tuple(wss_obj, wss_byte);
72+
},
73+
"reader"_a);
7274

7375
// Sampler type enumeration
7476
py::enum_<sampler_type>(m, "SamplerType")

0 commit comments

Comments
 (0)