aboutsummaryrefslogtreecommitdiffstats
path: root/util/draft
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/draft
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/draft')
-rw-r--r--util/draft/date.cpp36
-rw-r--r--util/draft/date.h46
-rw-r--r--util/draft/date_ut.cpp2
-rw-r--r--util/draft/datetime.cpp156
-rw-r--r--util/draft/datetime.h128
-rw-r--r--util/draft/datetime_ut.cpp26
-rw-r--r--util/draft/enum.cpp2
-rw-r--r--util/draft/enum.h26
-rw-r--r--util/draft/holder_vector.cpp2
-rw-r--r--util/draft/holder_vector.h32
-rw-r--r--util/draft/ip.cpp2
-rw-r--r--util/draft/ip.h18
-rw-r--r--util/draft/matrix.cpp2
-rw-r--r--util/draft/matrix.h52
-rw-r--r--util/draft/memory.cpp2
-rw-r--r--util/draft/memory.h30
-rw-r--r--util/draft/memory_ut.cpp76
-rw-r--r--util/draft/ut/ya.make2
-rw-r--r--util/draft/ya.make14
19 files changed, 327 insertions, 327 deletions
diff --git a/util/draft/date.cpp b/util/draft/date.cpp
index ba2424bda2..a290c46050 100644
--- a/util/draft/date.cpp
+++ b/util/draft/date.cpp
@@ -1,10 +1,10 @@
-#include "date.h"
-
-#include <util/string/cast.h>
+#include "date.h"
+
+#include <util/string/cast.h>
#include <util/generic/yexception.h>
#include <util/datetime/base.h>
-time_t GetDateStart(time_t ts) {
+time_t GetDateStart(time_t ts) {
tm dateTm;
memset(&dateTm, 0, sizeof(tm));
localtime_r(&ts, &dateTm);
@@ -20,16 +20,16 @@ time_t GetDateStart(time_t ts) {
static time_t ParseDate(const char* date, const char* format) {
tm dateTm;
memset(&dateTm, 0, sizeof(tm));
- if (!strptime(date, format, &dateTm)) {
+ if (!strptime(date, format, &dateTm)) {
ythrow yexception() << "Invalid date string and format: " << date << ", " << format;
- }
+ }
return mktime(&dateTm);
}
static time_t ParseDate(const char* dateStr) {
- if (strlen(dateStr) != 8) {
+ if (strlen(dateStr) != 8) {
ythrow yexception() << "Invalid date string: " << dateStr;
- }
+ }
return ParseDate(dateStr, "%Y%m%d");
}
@@ -59,17 +59,17 @@ TDate::TDate(const TString& date, const TString& format)
{
}
-TDate::TDate(unsigned year, unsigned month, unsigned monthDay) {
+TDate::TDate(unsigned year, unsigned month, unsigned monthDay) {
tm dateTm;
Zero(dateTm);
- dateTm.tm_year = year - 1900;
- dateTm.tm_mon = month - 1;
- dateTm.tm_mday = monthDay;
+ dateTm.tm_year = year - 1900;
+ dateTm.tm_mon = month - 1;
+ dateTm.tm_mday = monthDay;
dateTm.tm_isdst = -1;
Timestamp = mktime(&dateTm);
- if (Timestamp == (time_t)-1) {
+ if (Timestamp == (time_t)-1) {
ythrow yexception() << "Invalid TDate args:(" << year << ',' << month << ',' << monthDay << ')';
- }
+ }
}
time_t TDate::GetStartUTC() const {
@@ -88,25 +88,25 @@ TString TDate::ToStroka(const char* format) const {
return Strftime(format, &dateTm);
}
-unsigned TDate::GetWeekDay() const {
+unsigned TDate::GetWeekDay() const {
tm dateTm;
localtime_r(&Timestamp, &dateTm);
return (unsigned)dateTm.tm_wday;
}
-unsigned TDate::GetYear() const {
+unsigned TDate::GetYear() const {
tm dateTm;
localtime_r(&Timestamp, &dateTm);
return ((unsigned)dateTm.tm_year) + 1900;
}
-unsigned TDate::GetMonth() const {
+unsigned TDate::GetMonth() const {
tm dateTm;
localtime_r(&Timestamp, &dateTm);
return ((unsigned)dateTm.tm_mon) + 1;
}
-unsigned TDate::GetMonthDay() const {
+unsigned TDate::GetMonthDay() const {
tm dateTm;
localtime_r(&Timestamp, &dateTm);
return (unsigned)dateTm.tm_mday;
diff --git a/util/draft/date.h b/util/draft/date.h
index 4130269b0b..e3eb616fe5 100644
--- a/util/draft/date.h
+++ b/util/draft/date.h
@@ -5,8 +5,8 @@
#include <util/generic/string.h>
#include <util/datetime/constants.h>
-#include <ctime>
-
+#include <ctime>
+
// XXX: uses system calls for trivial things. may be very slow therefore.
time_t GetDateStart(time_t ts);
@@ -23,7 +23,7 @@ public:
}
// XXX: wrong. Should be replace with two methods: TodayGmt() and TodayLocal()
- static TDate Today() {
+ static TDate Today() {
return TDate(time(nullptr));
}
@@ -34,7 +34,7 @@ public:
explicit TDate(time_t t);
- time_t GetStart() const {
+ time_t GetStart() const {
return Timestamp;
}
@@ -42,46 +42,46 @@ public:
TString ToStroka(const char* format = "%Y%m%d") const;
- TDate& operator++() {
+ TDate& operator++() {
Timestamp = GetDateStart(Timestamp + 3 * (SECONDS_IN_DAY / 2));
return *this;
}
- TDate& operator--() {
+ TDate& operator--() {
Timestamp = GetDateStart(Timestamp - SECONDS_IN_DAY / 2);
return *this;
}
- TDate& operator+=(unsigned days) {
+ TDate& operator+=(unsigned days) {
Timestamp = GetDateStart(Timestamp + days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2);
return *this;
}
- TDate& operator-=(unsigned days) {
+ TDate& operator-=(unsigned days) {
Timestamp = GetDateStart(Timestamp - days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2);
return *this;
}
- TDate operator+(unsigned days) const {
+ TDate operator+(unsigned days) const {
return TDate(Timestamp + days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2);
}
- TDate operator-(unsigned days) const {
+ TDate operator-(unsigned days) const {
return TDate(Timestamp - days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2);
}
unsigned GetWeekDay() const; // days since Sunday
unsigned GetYear() const;
- unsigned GetMonth() const; // from 01
+ unsigned GetMonth() const; // from 01
unsigned GetMonthDay() const; // from 01
- friend bool operator<(const TDate& left, const TDate& right);
- friend bool operator>(const TDate& left, const TDate& right);
- friend bool operator<=(const TDate& left, const TDate& right);
- friend bool operator>=(const TDate& left, const TDate& right);
- friend bool operator==(const TDate& left, const TDate& right);
- friend int operator-(const TDate& left, const TDate& right);
+ friend bool operator<(const TDate& left, const TDate& right);
+ friend bool operator>(const TDate& left, const TDate& right);
+ friend bool operator<=(const TDate& left, const TDate& right);
+ friend bool operator>=(const TDate& left, const TDate& right);
+ friend bool operator==(const TDate& left, const TDate& right);
+ friend int operator-(const TDate& left, const TDate& right);
friend IInputStream& operator>>(IInputStream& left, TDate& right);
friend IOutputStream& operator<<(IOutputStream& left, const TDate& right);
@@ -89,27 +89,27 @@ public:
Y_DECLARE_PODTYPE(TDate);
-inline bool operator<(const TDate& left, const TDate& right) {
+inline bool operator<(const TDate& left, const TDate& right) {
return left.Timestamp < right.Timestamp;
}
-inline bool operator>(const TDate& left, const TDate& right) {
+inline bool operator>(const TDate& left, const TDate& right) {
return left.Timestamp > right.Timestamp;
}
-inline bool operator<=(const TDate& left, const TDate& right) {
+inline bool operator<=(const TDate& left, const TDate& right) {
return left.Timestamp <= right.Timestamp;
}
-inline bool operator>=(const TDate& left, const TDate& right) {
+inline bool operator>=(const TDate& left, const TDate& right) {
return left.Timestamp >= right.Timestamp;
}
-inline bool operator==(const TDate& left, const TDate& right) {
+inline bool operator==(const TDate& left, const TDate& right) {
return left.Timestamp == right.Timestamp;
}
-inline int operator-(const TDate& left, const TDate& right) {
+inline int operator-(const TDate& left, const TDate& right) {
if (left < right) {
return -(right - left);
}
diff --git a/util/draft/date_ut.cpp b/util/draft/date_ut.cpp
index 85426b6ed6..8c33a6c1cf 100644
--- a/util/draft/date_ut.cpp
+++ b/util/draft/date_ut.cpp
@@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TDateTest) {
UNIT_ASSERT_EQUAL(d.GetStartUTC(), 1297728000);
}
{
- TDate d(2005, 6, 3);
+ TDate d(2005, 6, 3);
UNIT_ASSERT_EQUAL(d.GetYear(), 2005);
UNIT_ASSERT_EQUAL(d.GetMonth(), 6);
UNIT_ASSERT_EQUAL(d.GetMonthDay(), 3);
diff --git a/util/draft/datetime.cpp b/util/draft/datetime.cpp
index 2cde0152ad..5cbe7d8847 100644
--- a/util/draft/datetime.cpp
+++ b/util/draft/datetime.cpp
@@ -13,8 +13,8 @@
namespace NDatetime {
const ui32 MonthDays[2][12] = {
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, //nleap
- {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} //leap
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, //nleap
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} //leap
};
const ui32 MonthDaysNewYear[2][13] = {
@@ -60,11 +60,11 @@ namespace NDatetime {
default:
break;
}
-#endif
+#endif
IsDst = tt.tm_isdst;
- }
- };
-
+ }
+ };
+
TSimpleTM TSimpleTM::CurrentUTC() {
return New((time_t)TInstant::MicroSeconds(InterpolatedMicroSeconds()).Seconds());
}
@@ -80,30 +80,30 @@ namespace NDatetime {
#endif
return New(tmSys);
- }
+ }
TSimpleTM TSimpleTM::NewLocal(time_t t) {
TTimeData d(t);
return New(t, d.GMTOff, d.IsDst);
- }
+ }
- TSimpleTM TSimpleTM::New(const struct tm& t) {
- TSimpleTM res;
+ TSimpleTM TSimpleTM::New(const struct tm& t) {
+ TSimpleTM res;
res.IsDst = t.tm_isdst;
- res.Sec = t.tm_sec;
- res.Min = t.tm_min;
- res.Hour = t.tm_hour;
- res.WDay = t.tm_wday;
- res.Mon = t.tm_mon;
- res.MDay = t.tm_mday;
- res.Year = t.tm_year;
- res.YDay = t.tm_yday;
+ res.Sec = t.tm_sec;
+ res.Min = t.tm_min;
+ res.Hour = t.tm_hour;
+ res.WDay = t.tm_wday;
+ res.Mon = t.tm_mon;
+ res.MDay = t.tm_mday;
+ res.Year = t.tm_year;
+ res.YDay = t.tm_yday;
res.IsLeap = LeapYearAD(res.Year + 1900);
#ifndef _win_
- res.GMTOff = t.tm_gmtoff;
+ res.GMTOff = t.tm_gmtoff;
#endif
- return res;
- }
+ return res;
+ }
TSimpleTM& TSimpleTM::SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour, ui32 min, ui32 sec, i32 isdst) {
mday = ::Max<ui32>(mday, 1);
@@ -123,70 +123,70 @@ namespace NDatetime {
}
TSimpleTM& TSimpleTM::RegenerateFields() {
- return *this = New(AsTimeT(), GMTOff, IsDst);
+ return *this = New(AsTimeT(), GMTOff, IsDst);
}
- TSimpleTM& TSimpleTM::Add(EField f, i32 amount) {
- if (!amount) {
- return *this;
- }
+ TSimpleTM& TSimpleTM::Add(EField f, i32 amount) {
+ if (!amount) {
+ return *this;
+ }
- switch (f) {
- default:
- return *this;
- case F_DAY:
- amount *= 24;
+ switch (f) {
+ default:
+ return *this;
+ case F_DAY:
+ amount *= 24;
[[fallthrough]];
- case F_HOUR:
- amount *= 60;
+ case F_HOUR:
+ amount *= 60;
[[fallthrough]];
- case F_MIN:
- amount *= 60;
+ case F_MIN:
+ amount *= 60;
[[fallthrough]];
case F_SEC: {
- return *this = New(AsTimeT() + amount, GMTOff, IsDst);
+ return *this = New(AsTimeT() + amount, GMTOff, IsDst);
}
- case F_YEAR: {
- i32 y = amount + (i32)Year;
- y = ::Min<i32>(Max<i32>(y, 0), 255 /*max year*/);
+ case F_YEAR: {
+ i32 y = amount + (i32)Year;
+ y = ::Min<i32>(Max<i32>(y, 0), 255 /*max year*/);
- // YDay may correspond to different MDay if it's March or greater and the years have different leap status
- if (Mon > 1) {
+ // YDay may correspond to different MDay if it's March or greater and the years have different leap status
+ if (Mon > 1) {
YDay += (i32)LeapYearAD(RealYear()) - (i32)LeapYearAD(RealYear());
- }
+ }
- Year = y;
+ Year = y;
IsLeap = LeapYearAD(RealYear());
return RegenerateFields();
- }
- case F_MON: {
- i32 m = amount + Mon;
- i32 y = (m < 0 ? (-12 + m) : m) / 12;
- m = m - y * 12;
+ }
+ case F_MON: {
+ i32 m = amount + Mon;
+ i32 y = (m < 0 ? (-12 + m) : m) / 12;
+ m = m - y * 12;
if (y) {
- Add(F_YEAR, y);
+ Add(F_YEAR, y);
}
- if (m >= 0 && m < 12) {
- MDay = ::Min<ui32>(MonthDays[IsLeap][m], MDay);
+ if (m >= 0 && m < 12) {
+ MDay = ::Min<ui32>(MonthDays[IsLeap][m], MDay);
Mon = m;
- }
-
+ }
+
return RegenerateFields();
- }
+ }
}
}
-
+
TString TSimpleTM::ToString(const char* fmt) const {
- struct tm t = *this;
+ struct tm t = *this;
return Strftime(fmt, &t);
}
time_t TSimpleTM::AsTimeT() const {
struct tm t = AsStructTmLocal();
return TimeGM(&t) - GMTOff - IsDst * 3600;
- }
+ }
struct tm TSimpleTM::AsStructTmUTC() const {
struct tm res;
@@ -196,42 +196,42 @@ namespace NDatetime {
}
struct tm TSimpleTM::AsStructTmLocal() const {
- struct tm t;
- Zero(t);
- t.tm_isdst = IsDst;
- t.tm_sec = Sec;
- t.tm_min = Min;
- t.tm_hour = Hour;
- t.tm_wday = WDay;
- t.tm_mon = Mon;
- t.tm_mday = MDay;
- t.tm_year = Year;
- t.tm_yday = YDay;
+ struct tm t;
+ Zero(t);
+ t.tm_isdst = IsDst;
+ t.tm_sec = Sec;
+ t.tm_min = Min;
+ t.tm_hour = Hour;
+ t.tm_wday = WDay;
+ t.tm_mon = Mon;
+ t.tm_mday = MDay;
+ t.tm_year = Year;
+ t.tm_yday = YDay;
#ifndef _win_
- t.tm_gmtoff = GMTOff;
+ t.tm_gmtoff = GMTOff;
#endif
- return t;
- }
+ return t;
+ }
}
-template <>
+template <>
void In<TMonth>(IInputStream& in, TMonth& t) {
char buf[4];
LoadPodArray(&in, buf, 4);
- t.Year = FromString<ui16>(buf, 4);
+ t.Year = FromString<ui16>(buf, 4);
LoadPodArray(&in, buf, 2);
- t.Month = ui8(FromString<ui16>(buf, 2)) - 1;
+ t.Month = ui8(FromString<ui16>(buf, 2)) - 1;
}
-template <>
+template <>
void Out<TMonth>(IOutputStream& o, const TMonth& t) {
o << t.Year << Sprintf("%.2hu", (ui16)(t.Month + 1));
}
-template <>
-TMonth FromStringImpl<TMonth, char>(const char* s, size_t len) {
+template <>
+TMonth FromStringImpl<TMonth, char>(const char* s, size_t len) {
TMonth res;
- TMemoryInput in(s, len);
+ TMemoryInput in(s, len);
in >> res;
return res;
}
diff --git a/util/draft/datetime.h b/util/draft/datetime.h
index b72b8d7c55..8a387ea6f1 100644
--- a/util/draft/datetime.h
+++ b/util/draft/datetime.h
@@ -3,42 +3,42 @@
#include <util/generic/algorithm.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>
-#include <util/generic/ymath.h>
-#include <util/datetime/base.h>
+#include <util/generic/ymath.h>
+#include <util/datetime/base.h>
+
+#include <cstdlib>
-#include <cstdlib>
-
#include <time.h>
namespace NDatetime {
- extern const ui32 MonthDays[2][12]; // !leapYear; !!leapYear
+ extern const ui32 MonthDays[2][12]; // !leapYear; !!leapYear
extern const ui32 MonthDaysNewYear[2][13]; // !leapYear; !!leapYear
- inline ui32 YearDaysAD(ui32 year) {
- year = Max<ui32>(year, 1) - 1; //1 AD comes straight after 1 BC, no 0 AD
- return year * 365 + year / 4 - year / 100 + year / 400;
- }
+ inline ui32 YearDaysAD(ui32 year) {
+ year = Max<ui32>(year, 1) - 1; //1 AD comes straight after 1 BC, no 0 AD
+ return year * 365 + year / 4 - year / 100 + year / 400;
+ }
- inline bool LeapYearAD(ui32 year) {
+ inline bool LeapYearAD(ui32 year) {
return (!(year % 4) && (year % 100)) || !(year % 400);
- }
+ }
- inline ui32 YDayFromMonthAndDay(ui32 month /*0 - based*/, ui32 mday /*1 - based*/, bool isleap) {
- return MonthDaysNewYear[isleap][Min(month, (ui32)11u)] + mday - 1;
- }
+ inline ui32 YDayFromMonthAndDay(ui32 month /*0 - based*/, ui32 mday /*1 - based*/, bool isleap) {
+ return MonthDaysNewYear[isleap][Min(month, (ui32)11u)] + mday - 1;
+ }
void YDayToMonthAndDay(ui32 yday /*0 - based*/, bool isleap, ui32* month /*0 - based*/, ui32* mday /*1 - based*/);
- struct TSimpleTM {
- enum EField {
- F_NONE = 0,
- F_SEC,
- F_MIN,
- F_HOUR,
- F_DAY,
- F_MON,
- F_YEAR
- };
+ struct TSimpleTM {
+ enum EField {
+ F_NONE = 0,
+ F_SEC,
+ F_MIN,
+ F_HOUR,
+ F_DAY,
+ F_MON,
+ F_YEAR
+ };
i32 GMTOff = 0; // -43200 - 50400 seconds
ui16 Year = 0; // from 1900
@@ -56,24 +56,24 @@ namespace NDatetime {
static TSimpleTM New(time_t t = 0, i32 gmtoff = 0, i8 isdst = 0);
static TSimpleTM NewLocal(time_t = 0);
- static TSimpleTM New(const struct tm&);
+ static TSimpleTM New(const struct tm&);
static TSimpleTM CurrentUTC();
TSimpleTM() = default;
- TSimpleTM(ui32 year, ui32 mon, ui32 day, ui32 h = 0, ui32 m = 0, ui32 s = 0) {
- Zero(*this);
- SetRealDate(year, mon, day, h, m, s);
- }
+ TSimpleTM(ui32 year, ui32 mon, ui32 day, ui32 h = 0, ui32 m = 0, ui32 s = 0) {
+ Zero(*this);
+ SetRealDate(year, mon, day, h, m, s);
+ }
- // keeps the object consistent
- TSimpleTM& Add(EField f, i32 amount = 1);
+ // keeps the object consistent
+ TSimpleTM& Add(EField f, i32 amount = 1);
TString ToString(const char* fmt = "%a, %d %b %Y %H:%M:%S %z") const;
TSimpleTM& ToUTC() {
- return *this = New(AsTimeT());
+ return *this = New(AsTimeT());
}
bool IsUTC() const {
@@ -94,43 +94,43 @@ namespace NDatetime {
return AsStructTmLocal();
}
- ui32 RealYear() const {
- return ui32(Year + 1900);
- }
+ ui32 RealYear() const {
+ return ui32(Year + 1900);
+ }
- ui32 RealMonth() const {
- return ui32(Mon + 1);
- }
+ ui32 RealMonth() const {
+ return ui32(Mon + 1);
+ }
TSimpleTM& SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour = -1, ui32 min = -1, ui32 sec = -1, i32 isdst = 0);
// regenerates all fields from Year, MDay, Hour, Min, Sec, IsDst, GMTOffset
TSimpleTM& RegenerateFields();
- friend bool operator==(const TSimpleTM& a, const TSimpleTM& b) {
+ friend bool operator==(const TSimpleTM& a, const TSimpleTM& b) {
return a.AsTimeT() == b.AsTimeT();
- }
+ }
- friend bool operator==(const TSimpleTM& s, const struct tm& t) {
- return s == New(t);
- }
+ friend bool operator==(const TSimpleTM& s, const struct tm& t) {
+ return s == New(t);
+ }
- friend bool operator==(const struct tm& t, const TSimpleTM& s) {
- return s == t;
- }
+ friend bool operator==(const struct tm& t, const TSimpleTM& s) {
+ return s == t;
+ }
- friend bool operator!=(const TSimpleTM& a, const TSimpleTM& b) {
- return !(a == b);
- }
+ friend bool operator!=(const TSimpleTM& a, const TSimpleTM& b) {
+ return !(a == b);
+ }
- friend bool operator!=(const TSimpleTM& s, const struct tm& t) {
- return !(s == t);
- }
+ friend bool operator!=(const TSimpleTM& s, const struct tm& t) {
+ return !(s == t);
+ }
- friend bool operator!=(const struct tm& t, const TSimpleTM& s) {
- return s != t;
- }
- };
+ friend bool operator!=(const struct tm& t, const TSimpleTM& s) {
+ return s != t;
+ }
+ };
}
inline TString date2str(const time_t date) {
@@ -150,28 +150,28 @@ inline time_t str2date(const TString& dateStr) {
}
// checks whether time2 > time1 and close enough to it
-inline bool AreTimesSeqAndClose(time_t time1, time_t time2, time_t closeInterval = 10) {
+inline bool AreTimesSeqAndClose(time_t time1, time_t time2, time_t closeInterval = 10) {
return (time2 - time1) <= closeInterval;
}
// checks whether time2 and time1 are close enough
-inline bool AreTimesClose(time_t time1, time_t time2, time_t closeInterval = 10) {
- return std::abs(time2 - time1) <= closeInterval;
+inline bool AreTimesClose(time_t time1, time_t time2, time_t closeInterval = 10) {
+ return std::abs(time2 - time1) <= closeInterval;
}
////////////////////////////////
-struct TMonth {
+struct TMonth {
ui16 Year;
- ui8 Month;
+ ui8 Month;
TMonth(ui16 year = 0, ui8 month = 0)
: Year(year)
, Month(month)
- {
- }
+ {
+ }
- TMonth operator-(ui16 n) {
+ TMonth operator-(ui16 n) {
if (n <= Month) {
return TMonth(Year, Month - (ui8)n);
} else {
diff --git a/util/draft/datetime_ut.cpp b/util/draft/datetime_ut.cpp
index 7106a1aa09..a5e065ef6e 100644
--- a/util/draft/datetime_ut.cpp
+++ b/util/draft/datetime_ut.cpp
@@ -1,16 +1,16 @@
-#include "datetime.h"
-
+#include "datetime.h"
+
#include <library/cpp/testing/unittest/registar.h>
-#include <util/string/builder.h>
-
+#include <util/string/builder.h>
+
Y_UNIT_TEST_SUITE(TSimpleTMTest) {
TString PrintMarker(const TString& test, int line) {
- return TStringBuilder() << "test " << test << " at line " << line;
+ return TStringBuilder() << "test " << test << " at line " << line;
}
TString JoinMarker(const TString& marker, time_t t) {
- return TStringBuilder() << marker << " (tstamp=" << t << ")";
+ return TStringBuilder() << marker << " (tstamp=" << t << ")";
}
TString PrintMarker(const TString& test, int line, time_t t) {
@@ -80,7 +80,7 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
}
Y_UNIT_TEST(SimpleTMTest) {
- using namespace NDatetime;
+ using namespace NDatetime;
tzset();
@@ -90,11 +90,11 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
UNIT_ASSERT((ui32)TSimpleTM::New(0).IsUTC());
time_t t = time(nullptr);
- {
+ {
struct tm tmt;
Zero(tmt);
gmtime_r(&t, &tmt);
- UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(t).AsTimeT(), ToString(t)); // time_t -> gmt tm -> time_t
+ UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(t).AsTimeT(), ToString(t)); // time_t -> gmt tm -> time_t
UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(tmt).AsTimeT(), ToString(t)); // gmt tm -> time_t
AssertStructTmEqual(PrintMarker("UTC:time_t", __LINE__, t),
tmt, TSimpleTM::New(t));
@@ -102,7 +102,7 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
tmt, TSimpleTM::New(tmt));
UNIT_ASSERT(TSimpleTM::New(t).IsUTC());
UNIT_ASSERT(TSimpleTM::New(tmt).IsUTC());
- }
+ }
{
struct tm tmt;
@@ -118,7 +118,7 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
AssertStructTmEqual(PrintMarker("local:tm:RegenerateFields", __LINE__, t),
tmt, TSimpleTM::New(tmt).RegenerateFields());
AssertStructTmEqual(PrintMarker("local:time_t:SetRealDate", __LINE__, t),
- tmt, TSimpleTM::NewLocal(t).SetRealDate(tmt.tm_year + 1900, tmt.tm_mon + 1, tmt.tm_mday, tmt.tm_hour, tmt.tm_min, tmt.tm_sec, tmt.tm_isdst));
+ tmt, TSimpleTM::NewLocal(t).SetRealDate(tmt.tm_year + 1900, tmt.tm_mon + 1, tmt.tm_mday, tmt.tm_hour, tmt.tm_min, tmt.tm_sec, tmt.tm_isdst));
}
{
@@ -148,9 +148,9 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
AssertSimpleTM(PrintMarker("UTC:AddYear", __LINE__),
tt, 1320469567, 2011, 11, 5, 5, 6, 7);
- for (ui32 i = 0; i < 365; ++i) {
+ for (ui32 i = 0; i < 365; ++i) {
tt.Add(TSimpleTM::F_DAY);
- }
+ }
AssertSimpleTM(PrintMarker("UTC:365*AddDay", __LINE__),
tt, 1352005567, 2012, 11, 4, 5, 6, 7);
diff --git a/util/draft/enum.cpp b/util/draft/enum.cpp
index 495a36d54d..40c79fb679 100644
--- a/util/draft/enum.cpp
+++ b/util/draft/enum.cpp
@@ -1 +1 @@
-#include "enum.h"
+#include "enum.h"
diff --git a/util/draft/enum.h b/util/draft/enum.h
index 4ad75dac3f..18002b7df2 100644
--- a/util/draft/enum.h
+++ b/util/draft/enum.h
@@ -8,7 +8,7 @@
#include <util/string/split.h>
#include <utility>
-class TEnumNotFoundException: public yexception {
+class TEnumNotFoundException: public yexception {
};
#define EnumFromString(key, entries) EnumFromStringImpl(key, entries, Y_ARRAY_SIZE(entries))
@@ -19,7 +19,7 @@ class TEnumNotFoundException: public yexception {
#define EnumToStringWithSize(key, entries, size) EnumToStringImpl(key, entries, size)
#define PrintEnumItems(entries) PrintEnumItemsImpl(entries, Y_ARRAY_SIZE(entries))
-template <class K1, class K2, class V>
+template <class K1, class K2, class V>
const V* FindEnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t arraySize) {
for (size_t i = 0; i < arraySize; i++)
if (entries[i].first == key)
@@ -28,7 +28,7 @@ const V* FindEnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t
}
// special version for const char*
-template <class V>
+template <class V>
const V* FindEnumFromStringImpl(const char* key, const std::pair<const char*, V>* entries, size_t arraySize) {
for (size_t i = 0; i < arraySize; i++)
if (entries[i].first && key && !strcmp(entries[i].first, key))
@@ -36,7 +36,7 @@ const V* FindEnumFromStringImpl(const char* key, const std::pair<const char*, V>
return nullptr;
}
-template <class K, class V>
+template <class K, class V>
TString PrintEnumItemsImpl(const std::pair<K, V>* entries, size_t arraySize) {
TString result;
TStringOutput out(result);
@@ -46,25 +46,25 @@ TString PrintEnumItemsImpl(const std::pair<K, V>* entries, size_t arraySize) {
}
// special version for const char*
-template <class V>
+template <class V>
TString PrintEnumItemsImpl(const std::pair<const char*, V>* entries, size_t arraySize) {
TString result;
TStringOutput out(result);
for (size_t i = 0; i < arraySize; i++)
- out << (i ? ", " : "") << "'" << (entries[i].first ? entries[i].first : "<null>") << "'";
+ out << (i ? ", " : "") << "'" << (entries[i].first ? entries[i].first : "<null>") << "'";
return result;
}
-template <class K1, class K2, class V>
+template <class K1, class K2, class V>
const V* EnumFromStringImpl(K1 key, const std::pair<K2, V>* entries, size_t arraySize) {
const V* res = FindEnumFromStringImpl(key, entries, arraySize);
if (res)
return res;
- ythrow TEnumNotFoundException() << "Key '" << key << "' not found in enum. Valid options are: " << PrintEnumItemsImpl(entries, arraySize) << ". ";
+ ythrow TEnumNotFoundException() << "Key '" << key << "' not found in enum. Valid options are: " << PrintEnumItemsImpl(entries, arraySize) << ". ";
}
-template <class K, class V>
+template <class K, class V>
const K* EnumToStringImpl(V value, const std::pair<K, V>* entries, size_t arraySize) {
for (size_t i = 0; i < arraySize; i++)
if (entries[i].second == value)
@@ -90,9 +90,9 @@ inline void SetEnumFlagsForEmptySpec(B& flags, bool allIfEmpty) {
}
// all set by default
-template <class E, size_t N, size_t B>
-inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TStringBuf optSpec,
- std::bitset<B>& flags, bool allIfEmpty = true) {
+template <class E, size_t N, size_t B>
+inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TStringBuf optSpec,
+ std::bitset<B>& flags, bool allIfEmpty = true) {
if (optSpec.empty()) {
SetEnumFlagsForEmptySpec(flags, allIfEmpty);
} else {
@@ -107,7 +107,7 @@ inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TString
template <class E, size_t B>
inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf optSpec,
std::bitset<B>& flags, const size_t size,
- bool allIfEmpty = true) {
+ bool allIfEmpty = true) {
if (optSpec.empty()) {
SetEnumFlagsForEmptySpec(flags, allIfEmpty);
} else {
diff --git a/util/draft/holder_vector.cpp b/util/draft/holder_vector.cpp
index c66f45c3ec..9994c2a2b5 100644
--- a/util/draft/holder_vector.cpp
+++ b/util/draft/holder_vector.cpp
@@ -1 +1 @@
-#include "holder_vector.h"
+#include "holder_vector.h"
diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h
index 3095371dfa..1c62055bd9 100644
--- a/util/draft/holder_vector.h
+++ b/util/draft/holder_vector.h
@@ -2,16 +2,16 @@
#include <util/generic/ptr.h>
#include <util/generic/vector.h>
-#include <util/generic/noncopyable.h>
+#include <util/generic/noncopyable.h>
-template <class T, class D = TDelete>
+template <class T, class D = TDelete>
class THolderVector: public TVector<T*>, public TNonCopyable {
using TBase = TVector<T*>;
-
+
public:
explicit THolderVector(size_t n = 0)
- : TBase(n)
- {
+ : TBase(n)
+ {
}
~THolderVector() {
@@ -34,7 +34,7 @@ public:
void PushBack(T* t) {
try {
TBase::push_back(t);
- } catch (...) {
+ } catch (...) {
if (t)
D::Destroy(t);
throw;
@@ -85,18 +85,18 @@ public:
using TBase::operator[];
using TBase::operator bool;
using TBase::at;
- using TBase::back;
- using TBase::begin;
+ using TBase::back;
+ using TBase::begin;
using TBase::capacity;
using TBase::empty;
- using TBase::end;
+ using TBase::end;
using TBase::front;
using TBase::reserve;
- using TBase::size;
-
- using typename TBase::const_iterator;
- using typename TBase::const_reverse_iterator;
- using typename TBase::iterator;
- using typename TBase::reverse_iterator;
- using typename TBase::value_type;
+ using TBase::size;
+
+ using typename TBase::const_iterator;
+ using typename TBase::const_reverse_iterator;
+ using typename TBase::iterator;
+ using typename TBase::reverse_iterator;
+ using typename TBase::value_type;
};
diff --git a/util/draft/ip.cpp b/util/draft/ip.cpp
index 798ac4c118..a43bcdadcf 100644
--- a/util/draft/ip.cpp
+++ b/util/draft/ip.cpp
@@ -1 +1 @@
-#include "ip.h"
+#include "ip.h"
diff --git a/util/draft/ip.h b/util/draft/ip.h
index 3b5e26d77b..eb947cd2cd 100644
--- a/util/draft/ip.h
+++ b/util/draft/ip.h
@@ -9,22 +9,22 @@
#include <util/generic/variant.h>
#ifdef _unix_
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <arpa/inet.h>
#endif // _unix_
#include <string.h>
#ifndef INET6_ADDRSTRLEN
- #define INET6_ADDRSTRLEN 46
+ #define INET6_ADDRSTRLEN 46
#endif
// Network (big-endian) byte order
using TIp4 = TIpHost;
// Network (big-endian) byte order
-struct TIp6 {
+struct TIp6 {
char Data[16];
bool operator==(const TIp6& rhs) const {
@@ -56,7 +56,7 @@ static inline TIp6 Ip6FromString(const char* ipStr) {
TIp6 res;
if (inet_pton(AF_INET6, ipStr, &res.Data) == 0) {
- ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv6 address";
+ ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv6 address";
}
return res;
@@ -103,7 +103,7 @@ static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) {
return Ip6FromString(ipStr);
}
}
- ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv4 or ipv6 address";
+ ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ipv4 or ipv6 address";
}
static inline TString Ip4Or6ToString(const TIp4Or6& ip) {
@@ -115,8 +115,8 @@ static inline TString Ip4Or6ToString(const TIp4Or6& ip) {
}
// for TIp4 or TIp6, not TIp4Or6
-template <class TIp>
-struct TIpCompare {
+template <class TIp>
+struct TIpCompare {
bool Less(const TIp& l, const TIp& r) const {
return memcmp(&l, &r, sizeof(TIp)) < 0;
}
diff --git a/util/draft/matrix.cpp b/util/draft/matrix.cpp
index 2b93f5bd9d..24a274b810 100644
--- a/util/draft/matrix.cpp
+++ b/util/draft/matrix.cpp
@@ -1 +1 @@
-#include "matrix.h"
+#include "matrix.h"
diff --git a/util/draft/matrix.h b/util/draft/matrix.h
index 71d1537ded..154d00b35e 100644
--- a/util/draft/matrix.h
+++ b/util/draft/matrix.h
@@ -5,42 +5,42 @@
#include <util/system/defaults.h>
#include <string.h>
-template <typename T>
-class TMatrix: TNonCopyable {
- // Constructor/Destructor
+template <typename T>
+class TMatrix: TNonCopyable {
+ // Constructor/Destructor
public:
TMatrix()
: Buf(nullptr)
, Arr(nullptr)
- , M(0)
- , N(0)
- , BufSize(0)
- {
- }
+ , M(0)
+ , N(0)
+ , BufSize(0)
+ {
+ }
TMatrix(size_t m, size_t n)
- : Buf(new T[m * n])
- , Arr(Buf)
- , M(m)
- , N(n)
- , BufSize(m * n)
- {
- }
+ : Buf(new T[m * n])
+ , Arr(Buf)
+ , M(m)
+ , N(n)
+ , BufSize(m * n)
+ {
+ }
TMatrix(size_t m, size_t n, T* buf)
: Buf(nullptr)
- , Arr(buf)
- , M(m)
- , N(n)
- , BufSize(m * n)
- {
- }
+ , Arr(buf)
+ , M(m)
+ , N(n)
+ , BufSize(m * n)
+ {
+ }
~TMatrix() {
delete[] Buf;
}
- // Properties/Methods
+ // Properties/Methods
public:
void Clear() {
M = N = 0;
@@ -51,12 +51,12 @@ public:
size_t newSize = m * n;
if (newSize > BufSize) {
T* newBuf = new T[newSize];
- delete[] Buf;
+ delete[] Buf;
Arr = Buf = newBuf;
BufSize = newSize;
}
- M = m;
- N = n;
+ M = m;
+ N = n;
}
size_t Width() const {
@@ -96,7 +96,7 @@ public:
}
void Fill(T value) {
- for (T *p = Arr, *end = Arr + M * N; p < end; ++p)
+ for (T *p = Arr, *end = Arr + M * N; p < end; ++p)
*p = value;
}
diff --git a/util/draft/memory.cpp b/util/draft/memory.cpp
index 57937cb7d4..b31569d449 100644
--- a/util/draft/memory.cpp
+++ b/util/draft/memory.cpp
@@ -1 +1 @@
-#include "memory.h"
+#include "memory.h"
diff --git a/util/draft/memory.h b/util/draft/memory.h
index 512c7cfcef..0a9722bb36 100644
--- a/util/draft/memory.h
+++ b/util/draft/memory.h
@@ -1,30 +1,30 @@
#pragma once
-#include <util/system/defaults.h>
-
+#include <util/system/defaults.h>
+
#include <algorithm>
#include <functional>
#include <utility>
-template <class T>
-inline bool IsZero(const T* begin, const T* end) {
+template <class T>
+inline bool IsZero(const T* begin, const T* end) {
return std::find_if(begin, end, [](const T& other) { return other != T(0); }) == end;
}
-template <size_t Size>
-inline bool IsZero(const char* p) {
- size_t sizeInUI64 = Size / 8;
- const char* pEndUi64 = p + sizeInUI64 * 8;
+template <size_t Size>
+inline bool IsZero(const char* p) {
+ size_t sizeInUI64 = Size / 8;
+ const char* pEndUi64 = p + sizeInUI64 * 8;
if (sizeInUI64 && !IsZero<ui64>((const ui64*)p, (const ui64*)pEndUi64))
return false;
return IsZero(pEndUi64, p + Size);
}
-#define IS_ZERO_INTSZ(INT) \
- template <> \
- inline bool IsZero<sizeof(INT)>(const char* p) { \
- return (*(INT*)p) == INT(0); \
- }
+#define IS_ZERO_INTSZ(INT) \
+ template <> \
+ inline bool IsZero<sizeof(INT)>(const char* p) { \
+ return (*(INT*)p) == INT(0); \
+ }
IS_ZERO_INTSZ(ui8)
IS_ZERO_INTSZ(ui16)
@@ -34,7 +34,7 @@ IS_ZERO_INTSZ(ui64)
#undef IS_ZERO_INTSZ
// If you want to use this to check all fields in a struct make sure it's w/o holes or #pragma pack(1)
-template <class T>
-bool IsZero(const T& t) {
+template <class T>
+bool IsZero(const T& t) {
return IsZero<sizeof(T)>((const char*)&t);
}
diff --git a/util/draft/memory_ut.cpp b/util/draft/memory_ut.cpp
index 6e235702d7..76bee30549 100644
--- a/util/draft/memory_ut.cpp
+++ b/util/draft/memory_ut.cpp
@@ -1,5 +1,5 @@
-#include "memory.h"
-
+#include "memory.h"
+
#include <library/cpp/testing/unittest/registar.h>
#pragma pack(1)
@@ -25,45 +25,45 @@ struct Y_PACKED TSampleStruct3 {
Y_UNIT_TEST_SUITE(TUtilDraftMemoryTest) {
Y_UNIT_TEST(IsZeroTest) {
- ui8 a1 = 0;
- UNIT_ASSERT(IsZero(a1));
- a1 = 0xF0;
- UNIT_ASSERT(!IsZero(a1));
+ ui8 a1 = 0;
+ UNIT_ASSERT(IsZero(a1));
+ a1 = 0xF0;
+ UNIT_ASSERT(!IsZero(a1));
- i32 a2 = -1;
- UNIT_ASSERT(!IsZero(a2));
- a2 = 0;
- UNIT_ASSERT(IsZero(a2));
+ i32 a2 = -1;
+ UNIT_ASSERT(!IsZero(a2));
+ a2 = 0;
+ UNIT_ASSERT(IsZero(a2));
- double a3 = 0.0;
- UNIT_ASSERT(IsZero(a3));
- a3 = 1.e-13;
- UNIT_ASSERT(!IsZero(a3));
+ double a3 = 0.0;
+ UNIT_ASSERT(IsZero(a3));
+ a3 = 1.e-13;
+ UNIT_ASSERT(!IsZero(a3));
- TSampleStruct1 ss1;
- ss1.A = 0;
- ss1.B = 0;
- UNIT_ASSERT(IsZero(ss1));
- ss1.A = 0;
- ss1.B = 12;
- UNIT_ASSERT(!IsZero(ss1));
+ TSampleStruct1 ss1;
+ ss1.A = 0;
+ ss1.B = 0;
+ UNIT_ASSERT(IsZero(ss1));
+ ss1.A = 0;
+ ss1.B = 12;
+ UNIT_ASSERT(!IsZero(ss1));
- TSampleStruct2 ss2;
- ss2.A = 0;
- ss2.B = 100;
- ss2.C = 0;
- UNIT_ASSERT(!IsZero(ss2));
- ss2.B = 0;
- UNIT_ASSERT(IsZero(ss2));
+ TSampleStruct2 ss2;
+ ss2.A = 0;
+ ss2.B = 100;
+ ss2.C = 0;
+ UNIT_ASSERT(!IsZero(ss2));
+ ss2.B = 0;
+ UNIT_ASSERT(IsZero(ss2));
- TSampleStruct3 ss3;
- ss3.A = ss2;
- ss3.B = 0;
- UNIT_ASSERT(IsZero(ss3));
- ss3.B = 0x030;
- UNIT_ASSERT(!IsZero(ss3));
- ss3.B = 0;
- ss3.A.C = -789;
- UNIT_ASSERT(!IsZero(ss3));
- }
+ TSampleStruct3 ss3;
+ ss3.A = ss2;
+ ss3.B = 0;
+ UNIT_ASSERT(IsZero(ss3));
+ ss3.B = 0x030;
+ UNIT_ASSERT(!IsZero(ss3));
+ ss3.B = 0;
+ ss3.A.C = -789;
+ UNIT_ASSERT(!IsZero(ss3));
+ }
}
diff --git a/util/draft/ut/ya.make b/util/draft/ut/ya.make
index e62505f148..37ab9413c5 100644
--- a/util/draft/ut/ya.make
+++ b/util/draft/ut/ya.make
@@ -1,5 +1,5 @@
UNITTEST()
-
+
OWNER(g:util)
SUBSCRIBER(g:util-subscribers)
diff --git a/util/draft/ya.make b/util/draft/ya.make
index 036a9cbcc5..e00674b682 100644
--- a/util/draft/ya.make
+++ b/util/draft/ya.make
@@ -1,5 +1,5 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(g:util)
SUBSCRIBER(g:util-subscribers)
@@ -12,11 +12,11 @@ ENDIF()
SRCS(
date.cpp
datetime.cpp
- enum.cpp
- holder_vector.cpp
- ip.cpp
- matrix.cpp
- memory.cpp
+ enum.cpp
+ holder_vector.cpp
+ ip.cpp
+ matrix.cpp
+ memory.cpp
)
END()