Skip to content

Commit 61ab9a7

Browse files
author
ignat
committed
Add FormatValue for TPiecewiseLinearFunction
commit_hash:19d66bcbea30c7678ee476930a8fa6b7f78bb22a
1 parent c7cbc6d commit 61ab9a7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

yt/yt/library/numeric/piecewise_linear_function-inl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,25 @@ bool operator==(const TPiecewiseLinearFunction<TValue>& lhs, const TPiecewiseLin
11301130
return lhs.Segments() == rhs.Segments();
11311131
}
11321132

1133+
template <class TValue>
1134+
void FormatValue(TStringBuilderBase* builder, const TPiecewiseLinearFunction<TValue>& func, TStringBuf spec)
1135+
{
1136+
builder->AppendChar('[');
1137+
const auto& segments = func.Segments();
1138+
if (!segments.empty()) {
1139+
FormatValue(builder, segments[0].LeftBound(), spec);
1140+
builder->AppendString(": ");
1141+
FormatValue(builder, segments[0].LeftValue(), spec);
1142+
for (size_t index = 1; index < segments.size(); index++) {
1143+
builder->AppendString(", ");
1144+
FormatValue(builder, segments[0].RightBound(), spec);
1145+
builder->AppendString(": ");
1146+
FormatValue(builder, segments[0].RightValue(), spec);
1147+
}
1148+
}
1149+
builder->AppendChar(']');
1150+
}
1151+
11331152
////////////////////////////////////////////////////////////////////////////////
11341153

11351154
} // namespace NYT

yt/yt/library/numeric/piecewise_linear_function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <library/cpp/testing/gtest/friend.h>
77

8+
#include <library/cpp/yt/string/format.h>
9+
810
#include <util/system/yassert.h>
911
#include <util/generic/algorithm.h>
1012
#include <util/generic/yexception.h>
@@ -434,6 +436,9 @@ class TPiecewiseLinearFunction
434436
template <class TValue>
435437
bool operator==(const TPiecewiseLinearFunction<TValue>& lhs, const TPiecewiseLinearFunction<TValue>& rhs);
436438

439+
template <class TValue>
440+
void FormatValue(TStringBuilderBase* builder, const TPiecewiseLinearFunction<TValue>& func, TStringBuf spec);
441+
437442
////////////////////////////////////////////////////////////////////////////////
438443

439444
} // namespace NYT

0 commit comments

Comments
 (0)