diff options
author | melkov <melkov@yandex-team.ru> | 2022-02-10 16:48:13 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:13 +0300 |
commit | 438546c8737d5c1fdeb31157dcf999717d930eec (patch) | |
tree | d29d229abd2f9f889b9b7eb148d635059dc26acf /util | |
parent | 96647fad5355ff5ef45a00a6d85c097028584ab0 (diff) | |
download | ydb-438546c8737d5c1fdeb31157dcf999717d930eec.tar.gz |
Restoring authorship annotation for <melkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
56 files changed, 938 insertions, 938 deletions
diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp index 38ecc3ab96..8238cc66a2 100644 --- a/util/datetime/base.cpp +++ b/util/datetime/base.cpp @@ -287,9 +287,9 @@ TString DateToString(time_t when, long* sec) { TString YearToString(const struct tm& theTm) { Y_ENSURE(0 <= theTm.tm_year + 1900 && theTm.tm_year + 1900 <= 9999, "invalid year " + ToString(theTm.tm_year + 1900) + ", year should be in range [0, 9999]"); - char buf[16]; - sprintf(buf, "%04d", theTm.tm_year + 1900); - return buf; + char buf[16]; + sprintf(buf, "%04d", theTm.tm_year + 1900); + return buf; } TString YearToString(time_t when) { diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp index afc3f802eb..d1b7f399f5 100644 --- a/util/datetime/base_ut.cpp +++ b/util/datetime/base_ut.cpp @@ -186,7 +186,7 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) { << a.tm_mon << ", " << a.tm_year << ", " << a.tm_wday << ", " -#if !defined(_musl_) && !defined(_win_) +#if !defined(_musl_) && !defined(_win_) << a.tm_yday #endif << ")"; diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h index 7d38d5bdb3..c6559c8de2 100644 --- a/util/datetime/cputimer.h +++ b/util/datetime/cputimer.h @@ -34,25 +34,25 @@ public: class TProfileTimer { TDuration T; -public: +public: TProfileTimer() { - Reset(); - } + Reset(); + } TDuration Get() const { return TRusage::Get().Utime - T; - } + } TDuration Step() { TRusage r; r.Fill(); TDuration d = r.Utime - T; T = r.Utime; - return d; - } + return d; + } void Reset() { T = TRusage::Get().Utime; - } -}; - + } +}; + /// Return cached processor cycle count per second. Method takes 1 second at first invocation. /// Note, on older systems cycle rate may change during program lifetime, /// so returned value may be incorrect. Modern Intel and AMD processors keep constant TSC rate. @@ -115,7 +115,7 @@ private: time_t Begin; ui64 BeginCycles; -public: +public: TTimeLogger(const TString& message, bool verbose = true); ~TTimeLogger(); diff --git a/util/datetime/strptime.cpp b/util/datetime/strptime.cpp index f0d4ec333e..2e999879a1 100644 --- a/util/datetime/strptime.cpp +++ b/util/datetime/strptime.cpp @@ -1,83 +1,83 @@ -// ATTN! this is port of FreeBSD LIBC code to Win32 - just for convenience. -// Locale is ignored!!! - -/* - * Powerdog Industries kindly requests feedback from anyone modifying - * this function: - * +// ATTN! this is port of FreeBSD LIBC code to Win32 - just for convenience. +// Locale is ignored!!! + +/* + * Powerdog Industries kindly requests feedback from anyone modifying + * this function: + * * Date: Thu, 05 Jun 1997 23:17:17 -0400 - * From: Kevin Ruddy <kevin.ruddy@powerdog.com> - * To: James FitzGibbon <james@nexis.net> - * Subject: Re: Use of your strptime(3) code (fwd) + * From: Kevin Ruddy <kevin.ruddy@powerdog.com> + * To: James FitzGibbon <james@nexis.net> + * Subject: Re: Use of your strptime(3) code (fwd) * - * The reason for the "no mod" clause was so that modifications would + * The reason for the "no mod" clause was so that modifications would * come back and we could integrate them and reissue so that a wider * audience could use it (thereby spreading the wealth). This has - * made it possible to get strptime to work on many operating systems. - * I'm not sure why that's "plain unacceptable" to the FreeBSD team. + * made it possible to get strptime to work on many operating systems. + * I'm not sure why that's "plain unacceptable" to the FreeBSD team. * - * Anyway, you can change it to "with or without modification" as + * Anyway, you can change it to "with or without modification" as * you see fit. Enjoy. * - * Kevin Ruddy - * Powerdog Industries, Inc. - */ -/* - * Copyright (c) 1994 Powerdog Industries. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgement: - * This product includes software developed by Powerdog Industries. - * 4. The name of Powerdog Industries may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + * Kevin Ruddy + * Powerdog Industries, Inc. + */ +/* + * Copyright (c) 1994 Powerdog Industries. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgement: + * This product includes software developed by Powerdog Industries. + * 4. The name of Powerdog Industries may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include <util/system/compat.h> #include "systime.h" -#ifdef _win32_ +#ifdef _win32_ #ifndef lint #ifndef NOID -static char copyright[] = +static char copyright[] = "@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved."; static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27"; #endif /* !defined NOID */ #endif /* not lint */ //__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $"); - + //#include "namespace.h" #include <time.h> #include <ctype.h> #include <errno.h> #include <stdlib.h> #include <string.h> -//#include <pthread.h> -//#include "un-namespace.h" -//#include "libc_private.h" - -// ******************* #include "timelocal.h" ********************* -struct lc_time_T { +//#include <pthread.h> +//#include "un-namespace.h" +//#include "libc_private.h" + +// ******************* #include "timelocal.h" ********************* +struct lc_time_T { const char* mon[12]; const char* month[12]; const char* wday[7]; @@ -91,14 +91,14 @@ struct lc_time_T { const char* alt_month[12]; const char* md_order; const char* ampm_fmt; -}; - -// ******************* timelocal.c ****************** -/*- - * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> - * Copyright (c) 1997 FreeBSD Inc. - * All rights reserved. -*/ +}; + +// ******************* timelocal.c ****************** +/*- + * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> + * Copyright (c) 1997 FreeBSD Inc. + * All rights reserved. +*/ static const struct lc_time_T _C_time_locale = { {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}, @@ -108,85 +108,85 @@ static const struct lc_time_T _C_time_locale = { "Thu", "Fri", "Sat"}, {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}, - + /* X_fmt */ "%H:%M:%S", - + /* - * x_fmt - * Since the C language standard calls for - * "date, using locale's date format," anything goes. - * Using just numbers (as here) makes Quakers happier; - * it's also compatible with SVR4. - */ + * x_fmt + * Since the C language standard calls for + * "date, using locale's date format," anything goes. + * Using just numbers (as here) makes Quakers happier; + * it's also compatible with SVR4. + */ "%m/%d/%y", - + /* - * c_fmt - */ + * c_fmt + */ "%a %b %e %H:%M:%S %Y", - + /* am */ "AM", - + /* pm */ "PM", - + /* date_fmt */ "%a %b %e %H:%M:%S %Z %Y", - + /* alt_month - * Standalone months forms for %OB - */ + * Standalone months forms for %OB + */ { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}, - + /* md_order - * Month / day order in dates - */ + * Month / day order in dates + */ "md", - + /* ampm_fmt - * To determine 12-hour clock format time (empty, if N/A) - */ + * To determine 12-hour clock format time (empty, if N/A) + */ "%I:%M:%S %p"}; - + struct lc_time_T* -__get_current_time_locale(void) -{ +__get_current_time_locale(void) +{ return /*(_time_using_locale - ? &_time_locale + ? &_time_locale :*/ (struct lc_time_T*)&_C_time_locale /*)*/; -} - -// ******************* strptime.c ******************* +} + +// ******************* strptime.c ******************* static char* _strptime(const char*, const char*, struct tm*, int*); - + #define asizeof(a) (sizeof(a) / sizeof((a)[0])) - + #if defined(_MSC_VER) && (_MSC_VER >= 1900) #define tzname _tzname #endif static char* _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) -{ +{ char c; const char* ptr; int i; size_t len = 0; int Ealternative, Oalternative; struct lc_time_T* tptr = __get_current_time_locale(); - + ptr = fmt; while (*ptr != 0) { if (*buf == 0) break; - + c = *ptr++; - + if (c != '%') { if (isspace((unsigned char)c)) while (*buf != 0 && isspace((unsigned char)*buf)) @@ -195,7 +195,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) return 0; continue; } - + Ealternative = 0; Oalternative = 0; label: @@ -206,17 +206,17 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) if (*buf++ != '%') return 0; break; - + case '+': buf = _strptime(buf, tptr->date_fmt, tm, GMTp); if (buf == 0) return 0; break; - + case 'C': if (!isdigit((unsigned char)*buf)) return 0; - + /* XXX This will break for 3-digit centuries. */ len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { @@ -226,74 +226,74 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i < 19) return 0; - + tm->tm_year = i * 100 - 1900; break; - + case 'c': buf = _strptime(buf, tptr->c_fmt, tm, GMTp); if (buf == 0) return 0; break; - + case 'D': buf = _strptime(buf, "%m/%d/%y", tm, GMTp); if (buf == 0) return 0; break; - + case 'E': if (Ealternative || Oalternative) break; ++Ealternative; goto label; - + case 'O': if (Ealternative || Oalternative) break; ++Oalternative; goto label; - + case 'F': buf = _strptime(buf, "%Y-%m-%d", tm, GMTp); if (buf == 0) return 0; break; - + case 'R': buf = _strptime(buf, "%H:%M", tm, GMTp); if (buf == 0) return 0; break; - + case 'r': buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp); if (buf == 0) return 0; break; - + case 'T': buf = _strptime(buf, "%H:%M:%S", tm, GMTp); if (buf == 0) return 0; break; - + case 'X': buf = _strptime(buf, tptr->X_fmt, tm, GMTp); if (buf == 0) return 0; break; - + case 'x': buf = _strptime(buf, tptr->x_fmt, tm, GMTp); if (buf == 0) return 0; break; - + case 'j': if (!isdigit((unsigned char)*buf)) return 0; - + len = 3; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -305,22 +305,22 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) tm->tm_yday = i - 1; break; - + case 'M': case 'S': if (*buf == 0 || isspace((unsigned char)*buf)) break; - + if (!isdigit((unsigned char)*buf)) return 0; - + len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; i += *buf - '0'; --len; } - + if (c == 'M') { if (i > 59) return 0; @@ -350,7 +350,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) */ if (!isdigit((unsigned char)*buf)) return 0; - + len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -362,14 +362,14 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) return 0; } else if (i > 12) return 0; - + tm->tm_hour = i; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 'p': /* * XXX This is bogus if parsed before hour-related @@ -411,11 +411,11 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i == asizeof(tptr->weekday)) return 0; - + tm->tm_wday = i; buf += len; break; - + case 'U': case 'W': /* @@ -426,7 +426,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) */ if (!isdigit((unsigned char)*buf)) return 0; - + len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -435,27 +435,27 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i > 53) return 0; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 'w': if (!isdigit((unsigned char)*buf)) return 0; - + i = *buf - '0'; if (i > 6) return 0; - + tm->tm_wday = i; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 'd': case 'e': /* @@ -468,7 +468,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) */ if (!isdigit((unsigned char)*buf)) return 0; - + len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -477,14 +477,14 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i > 31) return 0; - + tm->tm_mday = i; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 'B': case 'b': case 'h': @@ -510,15 +510,15 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i == asizeof(tptr->month)) return 0; - + tm->tm_mon = i; buf += len; break; - + case 'm': if (!isdigit((unsigned char)*buf)) return 0; - + len = 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -527,20 +527,20 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } if (i < 1 || i > 12) return 0; - + tm->tm_mon = i - 1; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 's': { char* cp; int sverrno; long n; time_t t; - + sverrno = errno; errno = 0; n = strtol(buf, &cp, 10); @@ -553,15 +553,15 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) GmTimeR(&t, tm); *GMTp = 1; } break; - + case 'Y': case 'y': if (*buf == 0 || isspace((unsigned char)*buf)) break; - + if (!isdigit((unsigned char)*buf)) return 0; - + len = (c == 'Y') ? 4 : 2; for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { i *= 10; @@ -574,18 +574,18 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) i += 100; if (i < 0) return 0; - + tm->tm_year = i; - + if (*buf != 0 && isspace((unsigned char)*buf)) while (*ptr != 0 && !isspace((unsigned char)*ptr)) ++ptr; break; - + case 'Z': { const char* cp; char* zonestr; - + for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) { /*empty*/ } if (cp - buf) { @@ -608,20 +608,20 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp) } } return (char*)buf; -} - +} + char* strptime(const char* buf, const char* fmt, struct tm* tm) -{ +{ char* ret; int gmt; - + gmt = 0; ret = _strptime(buf, fmt, tm, &gmt); if (ret && gmt) { time_t t = timegm(tm); localtime_r(&t, tm); } - + return (ret); -} -#endif //_win32_ +} +#endif //_win32_ diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp index 6ee7e8fc6e..1f3b1f5d29 100644 --- a/util/datetime/systime.cpp +++ b/util/datetime/systime.cpp @@ -6,7 +6,7 @@ #ifdef _win_ void FileTimeToTimeval(const FILETIME* ft, timeval* tv) { - const i64 NANOINTERVAL = LL(116444736000000000); // Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 + const i64 NANOINTERVAL = LL(116444736000000000); // Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 union { ui64 ft_scalar; FILETIME ft_struct; @@ -38,14 +38,14 @@ tm* gmtime_r(const time_t* clock, tm* result) { } char* ctime_r(const time_t* clock, char* buf) { - char* res = ctime(clock); - if (res) { - memcpy(buf, res, 26); - return buf; - } - return 0; -} - + char* res = ctime(clock); + if (res) { + memcpy(buf, res, 26); + return buf; + } + return 0; +} + #endif /* _win_ */ #define YEAR0 1900 diff --git a/util/datetime/systime.h b/util/datetime/systime.h index 491d36e802..937518b2ac 100644 --- a/util/datetime/systime.h +++ b/util/datetime/systime.h @@ -24,7 +24,7 @@ int gettimeofday(struct timeval* tp, void*); tm* localtime_r(const time_t* clock, tm* result); tm* gmtime_r(const time_t* clock, tm* result); char* ctime_r(const time_t* clock, char* buf); - + inline time_t timegm(struct tm* t) { return TimeGM(t); } diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..67525acb45 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -23,7 +23,7 @@ extern "C" int mkstemps(char* path, int slen); char* mkdtemp(char* path); -#else +#else #ifdef _sun_ #include <alloca.h> @@ -55,7 +55,7 @@ void MakePathIfNotExist(const char* path, int mode = 0777); void SlashFolderLocal(TString& folder); bool correctpath(TString& filename); bool resolvepath(TString& folder, const TString& home); - + char GetDirectorySeparator(); const char* GetDirectorySeparatorS(); diff --git a/util/generic/bitmap.h b/util/generic/bitmap.h index f77d182460..1c9c2c41b1 100644 --- a/util/generic/bitmap.h +++ b/util/generic/bitmap.h @@ -1,5 +1,5 @@ #pragma once - + #include "fwd.h" #include "ptr.h" #include "bitops.h" diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..ed183431bd 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -2,7 +2,7 @@ #include "fwd.h" #include "mapfindptr.h" - + #include <util/memory/alloc.h> #include <util/system/type_name.h> #include <util/system/yassert.h> @@ -28,7 +28,7 @@ struct TSelect1st { } }; -template <class Value> +template <class Value> struct __yhashtable_node { /** If the first bit is not set, then this is a pointer to the next node in * the list of nodes for the current bucket. Otherwise this is a pointer of @@ -42,37 +42,37 @@ struct __yhashtable_node { Value val; __yhashtable_node& operator=(const __yhashtable_node&) = delete; -}; - -template <class Value, class Key, class HashFcn, - class ExtractKey, class EqualKey, class Alloc> +}; + +template <class Value, class Key, class HashFcn, + class ExtractKey, class EqualKey, class Alloc> class THashTable; - + template <class Key, class T, class HashFcn, class EqualKey, typename size_type_f> class sthash; -template <class Value> +template <class Value> struct __yhashtable_iterator; - -template <class Value> + +template <class Value> struct __yhashtable_const_iterator; - -template <class Value> + +template <class Value> struct __yhashtable_iterator { using iterator = __yhashtable_iterator<Value>; using const_iterator = __yhashtable_const_iterator<Value>; using node = __yhashtable_node<Value>; - + using iterator_category = std::forward_iterator_tag; using value_type = Value; using difference_type = ptrdiff_t; using size_type = size_t; using reference = Value&; using pointer = Value*; - + node* cur; - + explicit __yhashtable_iterator(node* n) : cur(n) { @@ -99,23 +99,23 @@ struct __yhashtable_iterator { Y_FORCE_INLINE explicit operator bool() const noexcept { return cur != nullptr; } -}; - -template <class Value> +}; + +template <class Value> struct __yhashtable_const_iterator { using iterator = __yhashtable_iterator<Value>; using const_iterator = __yhashtable_const_iterator<Value>; using node = __yhashtable_node<Value>; - + using iterator_category = std::forward_iterator_tag; using value_type = Value; using difference_type = ptrdiff_t; using size_type = size_t; using reference = const Value&; using pointer = const Value*; - + const node* cur; - + explicit __yhashtable_const_iterator(const node* n) : cur(n) { @@ -146,8 +146,8 @@ struct __yhashtable_const_iterator { Y_FORCE_INLINE explicit operator bool() const noexcept { return cur != nullptr; } -}; - +}; + /** * This class saves some space in allocator-based containers for the most common * use case of empty allocators. This is achieved thanks to the application of @@ -447,7 +447,7 @@ struct _yhashtable_traits { }; extern const void* const _yhashtable_empty_data[]; - + template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey, class Alloc> class THashTable: private _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>::base_type { using traits_type = _yhashtable_traits<Value, Key, HashFcn, ExtractKey, EqualKey, Alloc>; @@ -457,7 +457,7 @@ class THashTable: private _yhashtable_traits<Value, Key, HashFcn, ExtractKey, Eq using buckets_type = _yhashtable_buckets<node*, nodep_allocator_type>; using TBucketDivisor = ::NPrivate::THashDivisor; -public: +public: using key_type = Key; using value_type = Value; using hasher = HashFcn; @@ -465,14 +465,14 @@ public: using key_extract = ExtractKey; using allocator_type = Alloc; using node_allocator_type = typename traits_type::node_allocator_type; - + using size_type = size_t; using difference_type = ptrdiff_t; using pointer = value_type*; using const_pointer = const value_type*; using reference = value_type&; using const_reference = const value_type&; - + node_allocator_type& GetNodeAllocator() { return this->_get_alloc(); } @@ -485,13 +485,13 @@ public: hasher hash_function() const { return this->_get_hash_fun(); } - -private: + +private: template <class KeyL, class KeyR> bool equals(const KeyL& l, const KeyR& r) const { return this->_get_key_eq()(l, r); } - + /* This method is templated to postpone instantiation of key extraction functor. */ template <class ValueL> auto get_key(const ValueL& value) const -> decltype(ExtractKey()(value)) { @@ -509,16 +509,16 @@ private: buckets_type buckets; size_type num_elements; - -public: + +public: using iterator = __yhashtable_iterator<Value>; using const_iterator = __yhashtable_const_iterator<Value>; using insert_ctx = node**; - + friend struct __yhashtable_iterator<Value>; friend struct __yhashtable_const_iterator<Value>; - -public: + +public: THashTable() : base_type(HashFcn(), ExtractKey(), EqualKey(), node_allocator_type()) , buckets(nodep_allocator_type()) @@ -534,7 +534,7 @@ public: { initialize_buckets(buckets, n); } - + THashTable(size_type n, const HashFcn& hf, const EqualKey& eql) : base_type(hf, ExtractKey(), eql, node_allocator_type()) , buckets(nodep_allocator_type()) @@ -542,7 +542,7 @@ public: { initialize_buckets(buckets, n); } - + template <class TAllocParam> THashTable(size_type n, const HashFcn& hf, const EqualKey& eql, TAllocParam* allocParam) : base_type(hf, ExtractKey(), eql, allocParam) @@ -551,7 +551,7 @@ public: { initialize_buckets(buckets, n); } - + THashTable(const THashTable& ht) : base_type(ht._get_hash_fun(), ht._get_key_extract(), ht._get_key_eq(), ht._get_alloc()) , buckets(ht.buckets.get_allocator()) @@ -572,8 +572,8 @@ public: { initialize_buckets(buckets, 0); this->swap(ht); - } - + } + THashTable& operator=(const THashTable& ht) { if (&ht != this) { basic_clear(); @@ -609,12 +609,12 @@ public: return *this; } - + ~THashTable() { basic_clear(); deinitialize_buckets(buckets); } - + size_type size() const noexcept { return num_elements; } @@ -625,24 +625,24 @@ public: Y_PURE_FUNCTION bool empty() const noexcept { return size() == 0; } - + void swap(THashTable& ht) { base_type::swap(ht); buckets.swap(ht.buckets); DoSwap(num_elements, ht.num_elements); } - + iterator begin() { for (size_type n = 0; n < buckets.size(); ++n) /*y*/ if (buckets[n]) return iterator(buckets[n]); /*y*/ return end(); } - + iterator end() { return iterator(nullptr); } /*y*/ - + const_iterator begin() const { for (size_type n = 0; n < buckets.size(); ++n) /*y*/ if (buckets[n]) @@ -654,11 +654,11 @@ public: return const_iterator(nullptr); } /*y*/ -public: +public: size_type bucket_count() const { return buckets.size(); } /*y*/ - + size_type bucket_size(size_type bucket) const { size_type result = 0; if (const node* cur = buckets[bucket]) @@ -666,19 +666,19 @@ public: result += 1; return result; } - + template <class OtherValue> std::pair<iterator, bool> insert_unique(const OtherValue& obj) { reserve(num_elements + 1); return insert_unique_noresize(obj); } - + template <class OtherValue> iterator insert_equal(const OtherValue& obj) { reserve(num_elements + 1); return emplace_equal_noresize(obj); } - + template <typename... Args> iterator emplace_equal(Args&&... args) { reserve(num_elements + 1); @@ -702,7 +702,7 @@ public: ++num_elements; return iterator(tmp); } - + template <typename... Args> std::pair<iterator, bool> emplace_unique(Args&&... args) { reserve(num_elements + 1); @@ -717,29 +717,29 @@ public: template <typename... Args> iterator emplace_equal_noresize(Args&&... args); - + template <class InputIterator> void insert_unique(InputIterator f, InputIterator l) { insert_unique(f, l, typename std::iterator_traits<InputIterator>::iterator_category()); } - + template <class InputIterator> void insert_equal(InputIterator f, InputIterator l) { insert_equal(f, l, typename std::iterator_traits<InputIterator>::iterator_category()); } - + template <class InputIterator> void insert_unique(InputIterator f, InputIterator l, std::input_iterator_tag) { for (; f != l; ++f) insert_unique(*f); } - + template <class InputIterator> void insert_equal(InputIterator f, InputIterator l, std::input_iterator_tag) { for (; f != l; ++f) insert_equal(*f); } - + template <class ForwardIterator> void insert_unique(ForwardIterator f, ForwardIterator l, std::forward_iterator_tag) { difference_type n = std::distance(f, l); @@ -748,7 +748,7 @@ public: for (; n > 0; --n, ++f) insert_unique_noresize(*f); } - + template <class ForwardIterator> void insert_equal(ForwardIterator f, ForwardIterator l, std::forward_iterator_tag) { difference_type n = std::distance(f, l); @@ -757,10 +757,10 @@ public: for (; n > 0; --n, ++f) emplace_equal_noresize(*f); } - + template <class OtherValue> reference find_or_insert(const OtherValue& v); - + template <class OtherKey> iterator find(const OtherKey& key) { size_type n = bkt_num_key(key); @@ -784,25 +784,25 @@ public: } return const_iterator(first); /*y*/ } - + template <class OtherKey> iterator find_i(const OtherKey& key, insert_ctx& ins); - + template <class OtherKey> size_type count(const OtherKey& key) const { const size_type n = bkt_num_key(key); size_type result = 0; - + if (const node* cur = buckets[n]) for (; !((uintptr_t)cur & 1); cur = cur->next) if (equals(get_key(cur->val), key)) ++result; return result; } - + template <class OtherKey> std::pair<iterator, iterator> equal_range(const OtherKey& key); - + template <class OtherKey> std::pair<const_iterator, const_iterator> equal_range(const OtherKey& key) const; @@ -815,13 +815,13 @@ public: // void (instead of iterator) is intended, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2023.pdf void erase(const iterator& it); void erase(iterator first, iterator last); - + void erase(const const_iterator& it); void erase(const_iterator first, const_iterator last); - + bool reserve(size_type num_elements_hint); void basic_clear(); - + /** * Clears the hashtable without deallocating the nodes. * @@ -840,10 +840,10 @@ public: // implemented in save_stl.h template <class KeySaver> int save_for_st(IOutputStream* stream, KeySaver& ks, sthash<int, int, THash<int>, TEqualTo<int>, typename KeySaver::TSizeType>* stHash = nullptr) const; - + void clear(size_type downsize) { basic_clear(); - + if (downsize < buckets.size()) { const TBucketDivisor newSize = HashBucketCountExt(downsize); if (newSize() < buckets.size()) { @@ -875,9 +875,9 @@ public: void clear() { if (num_elements) clear((num_elements * 2 + buckets.size()) / 3); - } - -private: + } + +private: static void initialize_buckets(buckets_type& buckets, size_type sizeHint) { if (sizeHint == 0) { buckets.initialize_static(reinterpret_cast<node**>(const_cast<void**>(_yhashtable_empty_data)) + 1, TBucketDivisor::One()); @@ -888,7 +888,7 @@ private: initialize_buckets_dynamic(buckets, size); } } - + static void initialize_buckets_dynamic(buckets_type& buckets, TBucketDivisor size) { buckets.initialize_dynamic(size); memset(buckets.data(), 0, size() * sizeof(*buckets.data())); @@ -911,24 +911,24 @@ private: size_type bkt_num_key(const OtherKey& key) const { return bkt_num_key(key, buckets.ExtSize()); } - + template <class OtherValue> size_type bkt_num(const OtherValue& obj) const { return bkt_num_key(get_key(obj)); } - + template <class OtherKey> size_type bkt_num_key(const OtherKey& key, TBucketDivisor n) const { const size_type bucket = n.Remainder(this->_get_hash_fun()(key)); Y_ASSERT((0 <= bucket) && (bucket < n())); return bucket; } - + template <class OtherValue> size_type bkt_num(const OtherValue& obj, TBucketDivisor n) const { return bkt_num_key(get_key(obj), n); } - + template <typename... Args> node* new_node(Args&&... val) { node* n = get_node(); @@ -947,56 +947,56 @@ private: //n->next = (node*) 0xDeadBeeful; put_node(n); } - + void erase_bucket(const size_type n, node* first, node* last); void erase_bucket(const size_type n, node* last); - + void copy_from_dynamic(const THashTable& ht); -}; - -template <class V> +}; + +template <class V> __yhashtable_iterator<V>& __yhashtable_iterator<V>::operator++() { Y_ASSERT(cur); - cur = cur->next; + cur = cur->next; if ((uintptr_t)cur & 1) { node** bucket = (node**)((uintptr_t)cur & ~1); while (*bucket == nullptr) ++bucket; Y_ASSERT(*bucket != nullptr); cur = (node*)((uintptr_t)*bucket & ~1); - } - return *this; -} - -template <class V> + } + return *this; +} + +template <class V> inline __yhashtable_iterator<V> __yhashtable_iterator<V>::operator++(int) { iterator tmp = *this; ++*this; return tmp; -} - -template <class V> +} + +template <class V> __yhashtable_const_iterator<V>& __yhashtable_const_iterator<V>::operator++() { Y_ASSERT(cur); - cur = cur->next; + cur = cur->next; if ((uintptr_t)cur & 1) { node** bucket = (node**)((uintptr_t)cur & ~1); while (*bucket == nullptr) ++bucket; Y_ASSERT(*bucket != nullptr); cur = (node*)((uintptr_t)*bucket & ~1); - } - return *this; -} - -template <class V> + } + return *this; +} + +template <class V> inline __yhashtable_const_iterator<V> __yhashtable_const_iterator<V>::operator++(int) { const_iterator tmp = *this; ++*this; return tmp; -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <typename... Args> std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::emplace_unique_noresize(Args&&... args) { auto deleter = [&](node* tmp) { delete_node(tmp); }; @@ -1023,20 +1023,20 @@ template <class OtherValue> std::pair<typename THashTable<V, K, HF, Ex, Eq, A>::iterator, bool> THashTable<V, K, HF, Ex, Eq, A>::insert_unique_noresize(const OtherValue& obj) { const size_type n = bkt_num(obj); node* first = buckets[n]; - + if (first) /*y*/ for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/ if (equals(get_key(cur->val), get_key(obj))) return std::pair<iterator, bool>(iterator(cur), false); /*y*/ - + node* tmp = new_node(obj); tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/ buckets[n] = tmp; ++num_elements; return std::pair<iterator, bool>(iterator(tmp), true); /*y*/ -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <typename... Args> __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize(Args&&... args) { auto deleter = [&](node* tmp) { delete_node(tmp); }; @@ -1044,7 +1044,7 @@ __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize std::unique_ptr<node, decltype(deleter)> guard(tmp, deleter); const size_type n = bkt_num(tmp->val); node* first = buckets[n]; - + if (first) /*y*/ for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/ if (equals(get_key(cur->val), get_key(tmp->val))) { @@ -1054,55 +1054,55 @@ __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::emplace_equal_noresize ++num_elements; return iterator(tmp); /*y*/ } - + guard.release(); tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/ buckets[n] = tmp; ++num_elements; return iterator(tmp); /*y*/ -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherValue> typename THashTable<V, K, HF, Ex, Eq, A>::reference THashTable<V, K, HF, Ex, Eq, A>::find_or_insert(const OtherValue& v) { reserve(num_elements + 1); - + size_type n = bkt_num_key(get_key(v)); node* first = buckets[n]; - + if (first) /*y*/ for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/ if (equals(get_key(cur->val), get_key(v))) return cur->val; - + node* tmp = new_node(v); tmp->next = first ? first : (node*)((uintptr_t)&buckets[n + 1] | 1); /*y*/ buckets[n] = tmp; ++num_elements; return tmp->val; -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> __yhashtable_iterator<V> THashTable<V, K, HF, Ex, Eq, A>::find_i(const OtherKey& key, insert_ctx& ins) { size_type n = bkt_num_key(key); ins = &buckets[n]; node* first = buckets[n]; - + if (first) /*y*/ for (node* cur = first; !((uintptr_t)cur & 1); cur = cur->next) /*y*/ if (equals(get_key(cur->val), key)) return iterator(cur); /*y*/ return end(); -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> std::pair<__yhashtable_iterator<V>, __yhashtable_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) { using pii = std::pair<iterator, iterator>; const size_type n = bkt_num_key(key); node* first = buckets[n]; - + if (first) /*y*/ for (; !((uintptr_t)first & 1); first = first->next) { /*y*/ if (equals(get_key(first->val), key)) { @@ -1117,15 +1117,15 @@ std::pair<__yhashtable_iterator<V>, __yhashtable_iterator<V>> THashTable<V, K, H } } return pii(end(), end()); -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> std::pair<__yhashtable_const_iterator<V>, __yhashtable_const_iterator<V>> THashTable<V, K, HF, Ex, Eq, A>::equal_range(const OtherKey& key) const { using pii = std::pair<const_iterator, const_iterator>; const size_type n = bkt_num_key(key); const node* first = buckets[n]; - + if (first) /*y*/ for (; !((uintptr_t)first & 1); first = first->next) { /*y*/ if (equals(get_key(first->val), key)) { @@ -1141,15 +1141,15 @@ std::pair<__yhashtable_const_iterator<V>, __yhashtable_const_iterator<V>> THashT } } return pii(end(), end()); -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase(const OtherKey& key) { const size_type n = bkt_num_key(key); node* first = buckets[n]; size_type erased = 0; - + if (first) { node* cur = first; node* next = cur->next; @@ -1171,11 +1171,11 @@ typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, --num_elements; delete_node(first); } - } + } return erased; -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> template <class OtherKey> typename THashTable<V, K, HF, Ex, Eq, A>::size_type THashTable<V, K, HF, Ex, Eq, A>::erase_one(const OtherKey& key) { const size_type n = bkt_num_key(key); @@ -1210,7 +1210,7 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase(const iterator& it) { if (node* const p = it.cur) { const size_type n = bkt_num(p->val); node* cur = buckets[n]; - + if (cur == p) { buckets[n] = ((uintptr_t)cur->next & 1) ? nullptr : cur->next; /*y*/ delete_node(cur); @@ -1228,15 +1228,15 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase(const iterator& it) { next = cur->next; } } - } - } -} - -template <class V, class K, class HF, class Ex, class Eq, class A> + } + } +} + +template <class V, class K, class HF, class Ex, class Eq, class A> void THashTable<V, K, HF, Ex, Eq, A>::erase(iterator first, iterator last) { size_type f_bucket = first.cur ? bkt_num(first.cur->val) : buckets.size(); /*y*/ size_type l_bucket = last.cur ? bkt_num(last.cur->val) : buckets.size(); /*y*/ - + if (first.cur == last.cur) return; else if (f_bucket == l_bucket) @@ -1248,20 +1248,20 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase(iterator first, iterator last) { if (l_bucket != buckets.size()) /*y*/ erase_bucket(l_bucket, last.cur); } -} - -template <class V, class K, class HF, class Ex, class Eq, class A> -inline void +} + +template <class V, class K, class HF, class Ex, class Eq, class A> +inline void THashTable<V, K, HF, Ex, Eq, A>::erase(const_iterator first, const_iterator last) { erase(iterator(const_cast<node*>(first.cur)), iterator(const_cast<node*>(last.cur))); -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> inline void THashTable<V, K, HF, Ex, Eq, A>::erase(const const_iterator& it) { erase(iterator(const_cast<node*>(it.cur))); -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { const size_type old_n = buckets.size(); /*y*/ if (num_elements_hint + 1 > old_n) { @@ -1304,13 +1304,13 @@ bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { throw; } #endif /* __STL_USE_EXCEPTIONS */ - } - } + } + } return false; -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* first, node* last) { node* cur = buckets[n]; if (cur == first) @@ -1325,10 +1325,10 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* firs next = ((uintptr_t)cur->next & 1) ? nullptr : cur->next; /*y*/ --num_elements; } - } -} - -template <class V, class K, class HF, class Ex, class Eq, class A> + } +} + +template <class V, class K, class HF, class Ex, class Eq, class A> void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* last) { node* cur = buckets[n]; while (cur != last) { @@ -1338,9 +1338,9 @@ void THashTable<V, K, HF, Ex, Eq, A>::erase_bucket(const size_type n, node* last buckets[n] = cur; --num_elements; } -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> void THashTable<V, K, HF, Ex, Eq, A>::basic_clear() { if (!num_elements) { return; @@ -1360,9 +1360,9 @@ void THashTable<V, K, HF, Ex, Eq, A>::basic_clear() { } } num_elements = 0; -} - -template <class V, class K, class HF, class Ex, class Eq, class A> +} + +template <class V, class K, class HF, class Ex, class Eq, class A> void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { Y_ASSERT(buckets.size() == ht.buckets.size() && !ht.empty()); @@ -1373,23 +1373,23 @@ void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { if (const node* cur = ht.buckets[i]) { node* copy = new_node(cur->val); buckets[i] = copy; - + for (node* next = cur->next; !((uintptr_t)next & 1); cur = next, next = cur->next) { copy->next = new_node(next->val); copy = copy->next; } copy->next = (node*)((uintptr_t)&buckets[i + 1] | 1); /*y*/ } - } + } num_elements = ht.num_elements; #ifdef __STL_USE_EXCEPTIONS } catch (...) { basic_clear(); throw; - } + } #endif /* __STL_USE_EXCEPTIONS */ -} - +} + namespace NPrivate { template <class Key> inline TString MapKeyToString(const Key&) { @@ -1423,11 +1423,11 @@ namespace NPrivate { template <class Key, class T, class HashFcn, class EqualKey, class Alloc> class THashMap: public TMapOps<THashMap<Key, T, HashFcn, EqualKey, Alloc>> { -private: +private: using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; ht rep; - -public: + +public: using key_type = typename ht::key_type; using value_type = typename ht::value_type; using hasher = typename ht::hasher; @@ -1435,26 +1435,26 @@ public: using allocator_type = typename ht::allocator_type; using node_allocator_type = typename ht::node_allocator_type; using mapped_type = T; - + using size_type = typename ht::size_type; using difference_type = typename ht::difference_type; using pointer = typename ht::pointer; using const_pointer = typename ht::const_pointer; using reference = typename ht::reference; using const_reference = typename ht::const_reference; - + using iterator = typename ht::iterator; using const_iterator = typename ht::const_iterator; using insert_ctx = typename ht::insert_ctx; - + hasher hash_function() const { return rep.hash_function(); } key_equal key_eq() const { return rep.key_eq(); } - -public: + +public: THashMap() : rep(0, hasher(), key_equal()) { @@ -1507,7 +1507,7 @@ public: { rep.insert_unique(f, l); } - + THashMap(const std::initializer_list<std::pair<Key, T>>& list) : rep(list.size(), hasher(), key_equal()) { @@ -1520,7 +1520,7 @@ public: // because its implementation is backed by THashTable. // See hash_ut.cpp -public: +public: size_type size() const noexcept { return rep.size(); } @@ -1540,7 +1540,7 @@ public: void swap(THashMap& hs) { rep.swap(hs.rep); } - + iterator begin() { return rep.begin(); } @@ -1559,8 +1559,8 @@ public: const_iterator cend() const { return rep.end(); } - -public: + +public: template <class InputIterator> void insert(InputIterator f, InputIterator l) { rep.insert_unique(f, l); @@ -1588,7 +1588,7 @@ public: iterator insert_direct(const TheObj& obj, const insert_ctx& ins) { return rep.insert_direct(obj, ins); } - + template <typename... Args> iterator emplace_direct(const insert_ctx& ins, Args&&... args) { return rep.emplace_direct(ins, std::forward<Args>(args)...); @@ -1646,7 +1646,7 @@ public: return rep.emplace_direct(ctx, std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple())->second; } - + template <class TheKey> const T& at(const TheKey& key) const { using namespace ::NPrivate; @@ -1680,7 +1680,7 @@ public: std::pair<iterator, iterator> equal_range(const TKey& key) { return rep.equal_range(key); } - + template <class TKey> std::pair<const_iterator, const_iterator> equal_range(const TKey& key) const { return rep.equal_range(key); @@ -1690,7 +1690,7 @@ public: size_type erase(const TKey& key) { return rep.erase_one(key); } - + void erase(iterator it) { rep.erase(it); } @@ -1715,8 +1715,8 @@ public: int save_for_st(IOutputStream* stream, KeySaver& ks, sthash<int, int, THash<int>, TEqualTo<int>, typename KeySaver::TSizeType>* stHash = nullptr) const { return rep.template save_for_st<KeySaver>(stream, ks, stHash); } - -public: + +public: void reserve(size_type hint) { rep.reserve(hint); } @@ -1732,9 +1732,9 @@ public: const node_allocator_type& GetNodeAllocator() const { return rep.GetNodeAllocator(); } -}; - -template <class Key, class T, class HashFcn, class EqualKey, class Alloc> +}; + +template <class Key, class T, class HashFcn, class EqualKey, class Alloc> inline bool operator==(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { if (hm1.size() != hm2.size()) { return false; @@ -1746,8 +1746,8 @@ inline bool operator==(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, co } } return true; -} - +} + template <class Key, class T, class HashFcn, class EqualKey, class Alloc> inline bool operator!=(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm2) { return !(hm1 == hm2); @@ -1755,37 +1755,37 @@ inline bool operator!=(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& hm1, co template <class Key, class T, class HashFcn, class EqualKey, class Alloc> class THashMultiMap { -private: +private: using ht = THashTable<std::pair<const Key, T>, Key, HashFcn, TSelect1st, EqualKey, Alloc>; ht rep; - -public: + +public: using key_type = typename ht::key_type; using value_type = typename ht::value_type; using hasher = typename ht::hasher; using key_equal = typename ht::key_equal; using mapped_type = T; using allocator_type = typename ht::allocator_type; - + using size_type = typename ht::size_type; using difference_type = typename ht::difference_type; using pointer = typename ht::pointer; using const_pointer = typename ht::const_pointer; using reference = typename ht::reference; using const_reference = typename ht::const_reference; - + using iterator = typename ht::iterator; using const_iterator = typename ht::const_iterator; using insert_ctx = typename ht::insert_ctx; - + hasher hash_function() const { return rep.hash_function(); } key_equal key_eq() const { return rep.key_eq(); } - -public: + +public: THashMultiMap() : rep(0, hasher(), key_equal()) { @@ -1807,7 +1807,7 @@ public: : rep(n, hf, eql) { } - + template <class InputIterator> THashMultiMap(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) @@ -1832,7 +1832,7 @@ public: { rep.insert_equal(f, l); } - + THashMultiMap(std::initializer_list<std::pair<Key, T>> list) : rep(list.size(), hasher(), key_equal()) { @@ -1845,7 +1845,7 @@ public: // because its implementation is backed by THashTable. // See hash_ut.cpp -public: +public: size_type size() const { return rep.size(); } @@ -1865,7 +1865,7 @@ public: void swap(THashMultiMap& hs) { rep.swap(hs.rep); } - + iterator begin() { return rep.begin(); } @@ -1884,8 +1884,8 @@ public: const_iterator cend() const { return rep.end(); } - -public: + +public: template <class InputIterator> void insert(InputIterator f, InputIterator l) { rep.insert_equal(f, l); @@ -1903,7 +1903,7 @@ public: iterator insert_noresize(const value_type& obj) { return rep.emplace_equal_noresize(obj); } - + template <typename... Args> iterator emplace_noresize(Args&&... args) { return rep.emplace_equal_noresize(std::forward<Args>(args)...); @@ -1923,12 +1923,12 @@ public: const_iterator find(const TKey& key) const { return rep.find(key); } - + template <class TKey> iterator find(const TKey& key) { return rep.find(key); } - + template <class TheKey> iterator find(const TheKey& key, insert_ctx& ins) { return rep.find_i(key, ins); @@ -1953,7 +1953,7 @@ public: std::pair<const_iterator, const_iterator> equal_range(const TKey& key) const { return rep.equal_range(key); } - + size_type erase(const key_type& key) { return rep.erase(key); } @@ -1975,14 +1975,14 @@ public: void release_nodes() { rep.release_nodes(); } - + // if (stHash != NULL) bucket_count() must be equal to stHash->bucket_count() template <class KeySaver> int save_for_st(IOutputStream* stream, KeySaver& ks, sthash<int, int, THash<int>, TEqualTo<int>, typename KeySaver::TSizeType>* stHash = nullptr) const { return rep.template save_for_st<KeySaver>(stream, ks, stHash); } -public: +public: void reserve(size_type hint) { rep.reserve(hint); } @@ -1992,9 +1992,9 @@ public: size_type bucket_size(size_type n) const { return rep.bucket_size(n); } -}; - -template <class Key, class T, class HF, class EqKey, class Alloc> +}; + +template <class Key, class T, class HF, class EqKey, class Alloc> inline bool operator==(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { // NOTE: copy-pasted from // contrib/libs/cxxsupp/libcxx/include/unordered_map @@ -2015,8 +2015,8 @@ inline bool operator==(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const it = eq1.second; } return true; -} - +} + template <class Key, class T, class HF, class EqKey, class Alloc> inline bool operator!=(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { return !(hm1 == hm2); diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b..bb27ee90d6 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -6,43 +6,43 @@ #include <initializer_list> #include <utility> -#undef value_type - +#undef value_type + template <class Value, class HashFcn, class EqualKey, class Alloc> class THashSet { -private: +private: using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; ht rep; - + using mutable_iterator = typename ht::iterator; -public: +public: using key_type = typename ht::key_type; using value_type = typename ht::value_type; using hasher = typename ht::hasher; using key_equal = typename ht::key_equal; using allocator_type = typename ht::allocator_type; using node_allocator_type = typename ht::node_allocator_type; - + using size_type = typename ht::size_type; using difference_type = typename ht::difference_type; using pointer = typename ht::const_pointer; using const_pointer = typename ht::const_pointer; using reference = typename ht::const_reference; using const_reference = typename ht::const_reference; - + using iterator = typename ht::const_iterator; using const_iterator = typename ht::const_iterator; using insert_ctx = typename ht::insert_ctx; - + hasher hash_function() const { return rep.hash_function(); } key_equal key_eq() const { return rep.key_eq(); } - -public: + +public: THashSet() { } template <class TT> @@ -62,7 +62,7 @@ public: : rep(n, hf, eql) { } - + THashSet(std::initializer_list<value_type> list) : rep(list.size(), hasher(), key_equal()) { @@ -110,12 +110,12 @@ public: { rep.insert_unique(f, l); } - + // THashSet has implicit copy/move constructors and copy-/move-assignment operators // because its implementation is backed by THashTable. // See hash_ut.cpp -public: +public: size_type size() const { return rep.size(); } @@ -132,7 +132,7 @@ public: void swap(THashSet& hs) { rep.swap(hs.rep); } - + iterator begin() const { return rep.begin(); } @@ -145,8 +145,8 @@ public: iterator cend() const { return rep.end(); } - -public: + +public: void insert(std::initializer_list<value_type> ilist) { insert(ilist.begin(), ilist.end()); } @@ -159,7 +159,7 @@ public: std::pair<iterator, bool> insert(const value_type& obj) { std::pair<mutable_iterator, bool> p = rep.insert_unique(obj); return std::pair<iterator, bool>(p.first, p.second); - } + } template <typename... Args> std::pair<iterator, bool> emplace(Args&&... args) { std::pair<mutable_iterator, bool> p = rep.emplace_unique(std::forward<Args>(args)...); @@ -189,7 +189,7 @@ public: iterator emplace_direct(const insert_ctx& ins, Args&&... args) { return rep.emplace_direct(ins, std::forward<Args>(args)...); } - + template <class TheKey> const_iterator find(const TheKey& key) const { return rep.find(key); @@ -212,12 +212,12 @@ public: size_type count(const TKey& key) const { return rep.count(key); } - + template <class TKey> std::pair<iterator, iterator> equal_range(const TKey& key) const { return rep.equal_range(key); } - + size_type erase(const key_type& key) { return rep.erase(key); } @@ -239,13 +239,13 @@ public: void release_nodes() { rep.release_nodes(); } - + template <class KeySaver> int save_for_st(IOutputStream* stream, KeySaver& ks) const { return rep.template save_for_st<KeySaver>(stream, ks); } - -public: + +public: void reserve(size_type hint) { rep.reserve(hint); } @@ -258,9 +258,9 @@ public: node_allocator_type& GetNodeAllocator() { return rep.GetNodeAllocator(); } -}; - -template <class Value, class HashFcn, class EqualKey, class Alloc> +}; + +template <class Value, class HashFcn, class EqualKey, class Alloc> inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { if (hs1.size() != hs2.size()) { return false; @@ -271,8 +271,8 @@ inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, con } } return true; -} - +} + template <class Value, class HashFcn, class EqualKey, class Alloc> inline bool operator!=(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, const THashSet<Value, HashFcn, EqualKey, Alloc>& hs2) { return !(hs1 == hs2); @@ -280,36 +280,36 @@ inline bool operator!=(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, con template <class Value, class HashFcn, class EqualKey, class Alloc> class THashMultiSet { -private: +private: using ht = THashTable<Value, Value, HashFcn, ::TIdentity, EqualKey, Alloc>; ht rep; - -public: + +public: using key_type = typename ht::key_type; using value_type = typename ht::value_type; using hasher = typename ht::hasher; using key_equal = typename ht::key_equal; using allocator_type = typename ht::allocator_type; using node_allocator_type = typename ht::node_allocator_type; - + using size_type = typename ht::size_type; using difference_type = typename ht::difference_type; using pointer = typename ht::const_pointer; using const_pointer = typename ht::const_pointer; using reference = typename ht::const_reference; using const_reference = typename ht::const_reference; - + using iterator = typename ht::const_iterator; using const_iterator = typename ht::const_iterator; - + hasher hash_function() const { return rep.hash_function(); } key_equal key_eq() const { return rep.key_eq(); } - -public: + +public: THashMultiSet() : rep(0, hasher(), key_equal()) { @@ -326,7 +326,7 @@ public: : rep(n, hf, eql) { } - + template <class InputIterator> THashMultiSet(InputIterator f, InputIterator l) : rep(0, hasher(), key_equal()) @@ -353,7 +353,7 @@ public: { rep.insert_equal(f, l); } - + THashMultiSet(std::initializer_list<value_type> list) : rep(list.size(), hasher(), key_equal()) { @@ -364,7 +364,7 @@ public: // because its implementation is backed by THashTable. // See hash_ut.cpp -public: +public: size_type size() const { return rep.size(); } @@ -381,7 +381,7 @@ public: void swap(THashMultiSet& hs) { rep.swap(hs.rep); } - + iterator begin() const { return rep.begin(); } @@ -394,8 +394,8 @@ public: iterator cend() const { return rep.end(); } - -public: + +public: iterator insert(const value_type& obj) { return rep.insert_equal(obj); } @@ -410,22 +410,22 @@ public: iterator insert_noresize(const value_type& obj) { return rep.insert_equal_noresize(obj); } - + template <class TKey> iterator find(const TKey& key) const { return rep.find(key); } - + template <class TKey> size_type count(const TKey& key) const { return rep.count(key); } - + template <class TKey> std::pair<iterator, iterator> equal_range(const TKey& key) const { return rep.equal_range(key); } - + size_type erase(const key_type& key) { return rep.erase(key); } @@ -447,8 +447,8 @@ public: void release_nodes() { rep.release_nodes(); } - -public: + +public: void reserve(size_type hint) { rep.reserve(hint); } @@ -461,9 +461,9 @@ public: node_allocator_type& GetNodeAllocator() { return rep.GetNodeAllocator(); } -}; - -template <class Val, class HashFcn, class EqualKey, class Alloc> +}; + +template <class Val, class HashFcn, class EqualKey, class Alloc> inline bool operator==(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { if (hs1.size() != hs2.size()) { return false; @@ -480,7 +480,7 @@ inline bool operator==(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, } } return true; -} +} template <class Val, class HashFcn, class EqualKey, class Alloc> inline bool operator!=(const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs1, const THashMultiSet<Val, HashFcn, EqualKey, Alloc>& hs2) { diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..9bf1a3b9b6 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -346,13 +346,13 @@ void THashTest::TestHMMap1() { hmap.insert(HMapType::value_type(23, 0)); UNIT_ASSERT(hmap.count(12325) == 2); - - UNIT_ASSERT(hmap.bucket_count() > 3000); - for (size_t n = 0; n < 10; n++) { - hmap.clear(); - hmap.insert(HMapType::value_type(1, 2)); - } - UNIT_ASSERT(hmap.bucket_count() < 30); + + UNIT_ASSERT(hmap.bucket_count() > 3000); + for (size_t n = 0; n < 10; n++) { + hmap.clear(); + hmap.insert(HMapType::value_type(1, 2)); + } + UNIT_ASSERT(hmap.bucket_count() < 30); } void THashTest::TestHMMapHas() { diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..119f4eb832 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -326,7 +326,7 @@ public: return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); } - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> bool operator==(const TStringBase<TDerived2, TChar, TTraits2>& s2) const noexcept { return equal(*this, s2); } @@ -344,7 +344,7 @@ public: return equal(pc, s); } - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> friend bool operator!=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return !(s1 == s2); } @@ -362,7 +362,7 @@ public: } #endif - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> friend bool operator<(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) < 0; } @@ -379,7 +379,7 @@ public: return compare(pc, s) < 0; } - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> friend bool operator<=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) <= 0; } @@ -396,7 +396,7 @@ public: return compare(pc, s) <= 0; } - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> friend bool operator>(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) > 0; } @@ -413,7 +413,7 @@ public: return compare(pc, s) > 0; } - template <typename TDerived2, typename TTraits2> + template <typename TDerived2, typename TTraits2> friend bool operator>=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept { return compare(s1, s2) >= 0; } @@ -573,11 +573,11 @@ public: return TDerived(Ptr(), Len()); } - // ~~~ Partial copy ~~~~ + // ~~~ Partial copy ~~~~ TDerived substr(size_t pos, size_t n = npos) const Y_WARN_UNUSED_RESULT { - return TDerived(*This(), pos, n); - } - + return TDerived(*This(), pos, n); + } + private: using GenericFinder = const TCharType* (*)(const TCharType*, size_t, const TCharType*, size_t); diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 70b9360d58..03d1a3397c 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -20,7 +20,7 @@ private: public: using char_type = TCharType; // TODO: DROP using traits_type = TTraits; - + //Resolving some ambiguity between TStringBase and std::basic_string_view //for typenames using typename TStringView::const_iterator; @@ -116,7 +116,7 @@ public: { } - template <typename D, typename T> + template <typename D, typename T> inline TBasicStringBuf(const TStringBase<D, TCharType, T>& str) noexcept : TStringView(str.data(), str.size()) { @@ -147,10 +147,10 @@ public: inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos, size_t n) noexcept : TBasicStringBuf(src) - { + { Skip(pos).Trunc(n); - } - + } + inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos) noexcept : TBasicStringBuf(src, pos, TBase::npos) { diff --git a/util/generic/strfcpy.cpp b/util/generic/strfcpy.cpp index 19b4da493e..d9dd21eb8e 100644 --- a/util/generic/strfcpy.cpp +++ b/util/generic/strfcpy.cpp @@ -1,13 +1,13 @@ /* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ -/* +/* * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> - * - * + * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR @@ -15,23 +15,23 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - + */ + /* * Modified version is * Copyright (c) Alexey Galakhov */ -#include "strfcpy.h" - -/* +#include "strfcpy.h" + +/* * Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). - */ + */ void strfcpy(char* dst, const char* src, size_t dsize) { size_t nleft = dsize; - + /* Copy as many bytes as will fit. */ if (nleft != 0) { while (--nleft != 0) { @@ -40,11 +40,11 @@ void strfcpy(char* dst, const char* src, size_t dsize) } } } - + /* Not enough room in dst, add NUL */ if (nleft == 0) { if (dsize != 0) { *dst = '\0'; /* NUL-terminate dst */ } } -} +} diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..688687593e 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -794,16 +794,16 @@ public: void TestOperatorsCI() { TStringType s(Data.ABCD()); - UNIT_ASSERT(s > Data.abc0123456xyz()); - UNIT_ASSERT(s == Data.abcd()); - + UNIT_ASSERT(s > Data.abc0123456xyz()); + UNIT_ASSERT(s == Data.abcd()); + using TCIStringBuf = TBasicStringBuf<char_type, traits_type>; UNIT_ASSERT(s > TCIStringBuf(Data.abc0123456xyz())); UNIT_ASSERT(TCIStringBuf(Data.abc0123456xyz()) < s); UNIT_ASSERT(s == TCIStringBuf(Data.abcd())); - } - + } + void TestMulOperators() { { TStringType s(Data._0()); diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..304a1b4e33 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -101,14 +101,14 @@ template <class T> static inline void DoSwap(T& l, T& r) noexcept(noexcept(NSwapCheck::TSwapSelector<T>::Swap(l, r))) { NSwapCheck::TSwapSelector<T>::Swap(l, r); } - -template <bool b> -struct TNullTmpl { + +template <bool b> +struct TNullTmpl { template <class T> - operator T() const { - return (T)0; - } -}; + operator T() const { + return (T)0; + } +}; using TNull = TNullTmpl<0>; diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h index a40aa408f5..fa7effb433 100644 --- a/util/memory/segmented_string_pool.h +++ b/util/memory/segmented_string_pool.h @@ -1,11 +1,11 @@ #pragma once - + #include <util/system/align.h> #include <util/system/yassert.h> #include <util/system/defaults.h> #include <util/generic/noncopyable.h> #include <util/generic/vector.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <memory> #include <cstdio> @@ -18,7 +18,7 @@ template <class T, class Alloc = std::allocator<T>> class segmented_pool: TNonCopyable { protected: Alloc seg_allocator; - struct seg_inf { + struct seg_inf { T* data; // allocated chunk size_t _size; // size of allocated chunk in sizeof(T)-units size_t freepos; // offset to free chunk's memory in bytes @@ -34,7 +34,7 @@ protected: , freepos(0) { } - }; + }; using seg_container = TVector<seg_inf>; using seg_iterator = typename seg_container::iterator; using seg_const_iterator = typename seg_container::const_iterator; @@ -72,7 +72,7 @@ public: } ~segmented_pool() { clear(); - } + } /* src - array of objects, len - count of elements in array */ T* append(const T* src, size_t len) { check_capacity(len); @@ -82,12 +82,12 @@ public: memcpy(rv, src, last_ins_size); curseg->freepos += last_ins_size, last_free -= len; return (T*)rv; - } + } T* append() { T* obj = get_raw(); new (obj) T(); return obj; - } + } T* get_raw() { // append(0, 1) check_capacity(1); ui8* rv = (ui8*)curseg->data + curseg->freepos; @@ -114,38 +114,38 @@ public: return segs.size() * segment_size * sizeof(T); } void restart() { - if (curseg != segs.end()) - ++curseg; - for (seg_iterator i = segs.begin(); i != curseg; ++i) + if (curseg != segs.end()) + ++curseg; + for (seg_iterator i = segs.begin(); i != curseg; ++i) i->freepos = 0; curseg = segs.begin(); last_free = 0; last_ins_size = 0; } - void clear() { + void clear() { for (seg_iterator i = segs.begin(); i != segs.end(); ++i) seg_allocator.deallocate(i->data, i->_size); - segs.clear(); - curseg = segs.begin(); - last_free = 0; - last_ins_size = 0; - } - void undo_last_append() { + segs.clear(); + curseg = segs.begin(); + last_free = 0; + last_ins_size = 0; + } + void undo_last_append() { Y_ASSERT(curseg != segs.end()); // do not use before append() if (last_ins_size) { Y_ASSERT(last_ins_size <= curseg->freepos); curseg->freepos -= last_ins_size; last_free += last_ins_size / sizeof(T); - last_ins_size = 0; - } - } + last_ins_size = 0; + } + } void alloc_first_seg() { Y_ASSERT(capacity() == 0); check_capacity(segment_size); Y_ASSERT(capacity() == segment_size * sizeof(T)); } -}; - +}; + class segmented_string_pool: public segmented_pool<char> { private: using _Base = segmented_pool<char>; @@ -166,14 +166,14 @@ public: } char* append(const char* src, size_t len) { char* rv = _Base::append(nullptr, len + 1); - if (src) - memcpy(rv, src, len); - rv[len] = 0; - return rv; - } + if (src) + memcpy(rv, src, len); + rv[len] = 0; + return rv; + } char* Append(const TStringBuf s) { return append(s.data(), s.size()); - } + } void align_4() { size_t t = (curseg->freepos + 3) & ~3; last_free -= t - curseg->freepos; @@ -184,11 +184,11 @@ public: } }; -template <typename T, typename C> +template <typename T, typename C> inline T* pool_push(segmented_pool<C>& pool, const T* v) { static_assert(sizeof(C) == 1, "only char type supported"); - size_t len = SizeOf(v); + size_t len = SizeOf(v); C* buf = pool.append(nullptr, AlignUp(len)); - memcpy(buf, v, len); - return (T*)buf; -} + memcpy(buf, v, len); + return (T*)buf; +} diff --git a/util/memory/segpool_alloc.h b/util/memory/segpool_alloc.h index 1a83b7a543..e8d39b64fa 100644 --- a/util/memory/segpool_alloc.h +++ b/util/memory/segpool_alloc.h @@ -1,35 +1,35 @@ #pragma once - + #include "segmented_string_pool.h" - -/** - This is a partially implemented allocator class that uses segmented_pool - as its allocatior base. - In fact, segpool_alloc can only allocate, it can't deallocate. Therefore, - it should be used with add-only containers that are just clear()'ed in the - end of their life cycle. - - External segmented_pool object must be cleared explicitly after all - containers use it in their allocator are cleared. - Single segmented_pool object may be used for several containers. - - Use segpool_alloc_vt as allocator template parameter for container. - Example: + +/** + This is a partially implemented allocator class that uses segmented_pool + as its allocatior base. + In fact, segpool_alloc can only allocate, it can't deallocate. Therefore, + it should be used with add-only containers that are just clear()'ed in the + end of their life cycle. + + External segmented_pool object must be cleared explicitly after all + containers use it in their allocator are cleared. + Single segmented_pool object may be used for several containers. + + Use segpool_alloc_vt as allocator template parameter for container. + Example: using TSomething = THashMap<A, B, hash<A>, TEqualTo<A>, segpool_alloc_vt>; - ... - TSomething something; - something.GetNodeAllocator().pool = &alloc_pool; - - Some containers may provide no way to access their allocator. In that case, - if you want to use them with segpool_alloc_vt, you should first either - hack them, or fix segpool_alloc so that it would create ref-counted - segmented_pool object on it's own - + ... + TSomething something; + something.GetNodeAllocator().pool = &alloc_pool; + + Some containers may provide no way to access their allocator. In that case, + if you want to use them with segpool_alloc_vt, you should first either + hack them, or fix segpool_alloc so that it would create ref-counted + segmented_pool object on it's own + ! Only tested with THashMap -*/ - -template <class _Tp> -struct segpool_alloc { +*/ + +template <class _Tp> +struct segpool_alloc { using pool_type = segmented_pool<char>; pool_type* pool; using pointer = _Tp*; @@ -39,62 +39,62 @@ struct segpool_alloc { using size_type = size_t; using difference_type = ptrdiff_t; using value_type = _Tp; -#ifndef NDEBUG - ui64 pool_count, malloc_count, pool_free_count, malloc_free_count; -#endif +#ifndef NDEBUG + ui64 pool_count, malloc_count, pool_free_count, malloc_free_count; +#endif segpool_alloc() : pool(nullptr) { Y_IF_DEBUG(pool_count = malloc_count = pool_free_count = malloc_free_count = 0); - } + } segpool_alloc(pool_type* p) : pool(p) { Y_IF_DEBUG(pool_count = malloc_count = pool_free_count = malloc_free_count = 0); } - segpool_alloc(const segpool_alloc& a) + segpool_alloc(const segpool_alloc& a) : pool(a.pool) { Y_IF_DEBUG(pool_count = malloc_count = pool_free_count = malloc_free_count = 0); - } - template <class _Tp1> - segpool_alloc(const segpool_alloc<_Tp1>& a) + } + template <class _Tp1> + segpool_alloc(const segpool_alloc<_Tp1>& a) : pool(a.pool) { Y_IF_DEBUG(pool_count = malloc_count = pool_free_count = malloc_free_count = 0); } _Tp* allocate(size_t __n) { - if (!pool) { - _Tp* data = (_Tp*)malloc(__n * sizeof(_Tp)); + if (!pool) { + _Tp* data = (_Tp*)malloc(__n * sizeof(_Tp)); Y_IF_DEBUG(if (data) malloc_count++); - return data; - } + return data; + } _Tp* data = (_Tp*)pool->append(nullptr, __n * sizeof(_Tp)); Y_IF_DEBUG(pool_count++); - return data; - } - void deallocate(pointer __p, size_t /*__n*/) { - if (!pool) { + return data; + } + void deallocate(pointer __p, size_t /*__n*/) { + if (!pool) { Y_IF_DEBUG(malloc_free_count++); - free(__p); + free(__p); } else { Y_IF_DEBUG(pool_free_count++); ; } - } - ~segpool_alloc() { + } + ~segpool_alloc() { //assert(pool_count == pool_free_count && malloc_count == malloc_free_count); <- uncomment when swap() problem is solved //printf("in ~segpool_alloc: size = %u, pool_count = %" PRId64 ", malloc_count = %" PRId64 ", pool_free_count = %" PRId64 ", malloc_free_count = %" PRId64 "\n", - // sizeof(_Tp), pool_count, malloc_count, pool_free_count, malloc_free_count); + // sizeof(_Tp), pool_count, malloc_count, pool_free_count, malloc_free_count); //fflush(stdout); - } + } template <class _Tp1> struct rebind { using other = segpool_alloc<_Tp1>; - }; - size_type max_size() const { - return size_type(-1) / sizeof(_Tp); - } + }; + size_type max_size() const { + return size_type(-1) / sizeof(_Tp); + } void construct(pointer __p, const _Tp& __val) { new (__p) _Tp(__val); } @@ -102,17 +102,17 @@ struct segpool_alloc { (void)__p; /* Make MSVC happy. */ __p->~_Tp(); } -}; +}; -template <class _Tp> +template <class _Tp> inline bool operator==(const segpool_alloc<_Tp>& a1, const segpool_alloc<_Tp>& a2) { return a1.pool == a2.pool; -} - -template <class _Tp> +} + +template <class _Tp> inline bool operator!=(const segpool_alloc<_Tp>& a1, const segpool_alloc<_Tp>& a2) { return a1.pool != a2.pool; -} - +} + // Any type since it is supposed to be rebound anyway. using segpool_alloc_vt = segpool_alloc<int>; diff --git a/util/str_stl.h b/util/str_stl.h index f1e137181d..97f0816c0d 100644 --- a/util/str_stl.h +++ b/util/str_stl.h @@ -25,7 +25,7 @@ namespace std { } bool operator()(const char* x, const TStringBuf y) const { return strlen(x) == y.size() && memcmp(x, y.data(), y.size()) == 0; - } + } using is_transparent = void; }; } @@ -65,17 +65,17 @@ template <typename T> struct hash<const T*> { inline size_t operator()(const T* t) const noexcept { return NumericHash(t); - } -}; - + } +}; + template <class T> struct hash<T*>: public ::hash<const T*> { }; template <> struct hash<const char*>: ::NHashPrivate::TStringHash<char> { -}; - +}; + template <> struct THash<TStringBuf>: ::NHashPrivate::TStringHash<char> { }; @@ -154,7 +154,7 @@ namespace NHashPrivate { public: template <class T> - inline size_t operator()(const T& pair) const { + inline size_t operator()(const T& pair) const { return CombineHashes(FirstHash(pair.first), SecondHash(pair.second)); } }; @@ -167,7 +167,7 @@ namespace NHashPrivate { template <class TFirst, class TSecond> struct TPairHash<TFirst, TSecond, true> { template <class T> - inline size_t operator()(const T& pair) const { + inline size_t operator()(const T& pair) const { // maps have TFirst = const TFoo, which would make for an undefined specialization using TFirstClean = std::remove_cv_t<TFirst>; using TSecondClean = std::remove_cv_t<TSecond>; @@ -184,12 +184,12 @@ template <class T> struct TEqualTo: public std::equal_to<T> { }; -template <> +template <> struct TEqualTo<TString>: public TEqualTo<TStringBuf> { using is_transparent = void; -}; - -template <> +}; + +template <> struct TEqualTo<TUtf16String>: public TEqualTo<TWtringBuf> { using is_transparent = void; }; @@ -200,14 +200,14 @@ struct TEqualTo<TUtf32String>: public TEqualTo<TUtf32StringBuf> { }; template <class TFirst, class TSecond> -struct TEqualTo<std::pair<TFirst, TSecond>> { +struct TEqualTo<std::pair<TFirst, TSecond>> { template <class TOther> - inline bool operator()(const std::pair<TFirst, TSecond>& a, const TOther& b) const { - return TEqualTo<TFirst>()(a.first, b.first) && TEqualTo<TSecond>()(a.second, b.second); - } - using is_transparent = void; -}; - + inline bool operator()(const std::pair<TFirst, TSecond>& a, const TOther& b) const { + return TEqualTo<TFirst>()(a.first, b.first) && TEqualTo<TSecond>()(a.second, b.second); + } + using is_transparent = void; +}; + template <class T> struct TCIEqualTo { }; @@ -240,8 +240,8 @@ struct TLess: public std::less<T> { template <> struct TLess<TString>: public TLess<TStringBuf> { using is_transparent = void; -}; - +}; + template <> struct TLess<TUtf16String>: public TLess<TWtringBuf> { using is_transparent = void; diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp index 01d09db232..29f7858ecf 100644 --- a/util/stream/direct_io_ut.cpp +++ b/util/stream/direct_io_ut.cpp @@ -8,8 +8,8 @@ #include "direct_io.h" Y_UNIT_TEST_SUITE(TDirectIOTests) { - // Decrease numBufToWrite further if tests continue to time out - static void Y_NO_INLINE Test(EOpenMode mode, size_t numBufToWrite) { + // Decrease numBufToWrite further if tests continue to time out + static void Y_NO_INLINE Test(EOpenMode mode, size_t numBufToWrite) { const char TEMPLATE[] = "qwertyuiopQWERTYUIOPasdfghjklASD"; const auto TEMPLATE_SIZE = Y_ARRAY_SIZE(TEMPLATE) - 1; static_assert(TEMPLATE_SIZE > 0, "must be greater than zero"); @@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) { auto&& directIOBuffer = TDirectIOBufferedFile{fileName, RdWr | CreateAlways | mode}; { auto&& output = TRandomAccessFileOutput{directIOBuffer}; - for (size_t i = 0; i < numBufToWrite; ++i) { + for (size_t i = 0; i < numBufToWrite; ++i) { output.Write(buffer.Data(), BUFFER_SIZE); } } @@ -54,18 +54,18 @@ Y_UNIT_TEST_SUITE(TDirectIOTests) { } } - UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE); + UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE); } Y_UNIT_TEST(ReadWriteTest) { - Test(0, 100 * 32); + Test(0, 100 * 32); } Y_UNIT_TEST(ReadWriteDirectTest) { - Test(Direct, 100 * 4); + Test(Direct, 100 * 4); } Y_UNIT_TEST(ReadWriteDirectSeqTest) { - Test(Direct | Seq, 100 * 4); + Test(Direct | Seq, 100 * 4); } } diff --git a/util/stream/input_ut.cpp b/util/stream/input_ut.cpp index 4a93f5458e..20469cf551 100644 --- a/util/stream/input_ut.cpp +++ b/util/stream/input_ut.cpp @@ -6,10 +6,10 @@ #include <util/system/file.h> #include <util/system/yassert.h> -#ifdef _win_ +#ifdef _win_ #include <io.h> -#endif - +#endif + class TMockStdIn { public: TMockStdIn() @@ -28,7 +28,7 @@ public: tempFile.Seek(0, sSet); TFileHandle tempFh(tempFile.GetHandle()); - tempFh.Duplicate2Posix(0); + tempFh.Duplicate2Posix(0); tempFh.Release(); func(); diff --git a/util/string/escape.h b/util/string/escape.h index b01be65b0e..ac52685f31 100644 --- a/util/string/escape.h +++ b/util/string/escape.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/string.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> template <class TChar> TBasicString<TChar>& EscapeCImpl(const TChar* str, size_t len, TBasicString<TChar>&); @@ -26,9 +26,9 @@ static inline TBasicString<TChar> EscapeC(const TChar* str, size_t len) { template <typename TChar> static inline TBasicString<TChar> EscapeC(const TBasicStringBuf<TChar>& str) { return EscapeC(str.data(), str.size()); -} - -template <typename TChar> +} + +template <typename TChar> static inline TBasicString<TChar>& UnescapeC(const TChar* str, size_t len, TBasicString<TChar>& s) { return UnescapeCImpl(str, len, s); } diff --git a/util/string/split.cpp b/util/string/split.cpp index 7d26857cc7..e3fc1444f5 100644 --- a/util/string/split.cpp +++ b/util/string/split.cpp @@ -8,7 +8,7 @@ inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values) if (ptr && *ptr) { size_t epos = strcspn(ptr, delim); assert(epos); - values.push_back(TValue(ptr, epos)); + values.push_back(TValue(ptr, epos)); ptr += epos; } } @@ -17,8 +17,8 @@ inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values) size_t Split(const char* ptr, const char* delim, TVector<TString>& values) { return Split<TString>(ptr, delim, values); -} - +} + size_t Split(const TString& in, const TString& delim, TVector<TString>& res) { return Split(in.data(), delim.data(), res); } diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..50aa32210e 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -408,21 +408,21 @@ static inline void Split(char* buf, char ch, T* res) { } /// Split string into res vector. Res vector is cleared before split. -/// Old good slow split function. -/// Field delimter is any number of symbols specified in delim (no empty strings in res vector) +/// Old good slow split function. +/// Field delimter is any number of symbols specified in delim (no empty strings in res vector) /// @return number of elements created size_t Split(const char* in, const char* delim, TVector<TString>& res); size_t Split(const TString& in, const TString& delim, TVector<TString>& res); - -/// Old split reimplemented for TStringBuf using the new code -/// Note that delim can be constructed from char* automatically (it is not cheap though) + +/// Old split reimplemented for TStringBuf using the new code +/// Note that delim can be constructed from char* automatically (it is not cheap though) inline size_t Split(const TStringBuf s, const TSetDelimiter<const char>& delim, TVector<TStringBuf>& res) { - res.clear(); + res.clear(); TContainerConsumer<TVector<TStringBuf>> res1(&res); TSkipEmptyTokens<TContainerConsumer<TVector<TStringBuf>>> consumer(&res1); SplitString(s.data(), s.data() + s.size(), delim, consumer); - return res.size(); -} + return res.size(); +} template <class P, class D> void GetNext(TStringBuf& s, D delim, P& param) { diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..54c9b4c833 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -245,10 +245,10 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TVector<TString> test; Split(data, delim, test); Cmp(good, test); - + TVector<TStringBuf> test1; Split(data, delim.data(), test1); - Cmp(good, test1); + Cmp(good, test1); } Y_UNIT_TEST(ConvenientSplitTest) { diff --git a/util/string/util.cpp b/util/string/util.cpp index b14f20bf75..41dd7db624 100644 --- a/util/string/util.cpp +++ b/util/string/util.cpp @@ -10,44 +10,44 @@ int a2i(const TString& s) { return atoi(s.c_str()); } -//============================== span ===================================== - +//============================== span ===================================== + void str_spn::init(const char* charset, bool extended) { // chars_table_1 is necessary to avoid some unexpected // multi-threading issues - ui8 chars_table_1[256]; - memset(chars_table_1, 0, sizeof(chars_table_1)); - if (extended) { + ui8 chars_table_1[256]; + memset(chars_table_1, 0, sizeof(chars_table_1)); + if (extended) { for (const char* cs = charset; *cs; cs++) { - if (cs[1] == '-' && cs[2] != 0) { + if (cs[1] == '-' && cs[2] != 0) { for (int c = (ui8)*cs; c <= (ui8)cs[2]; c++) { - chars_table_1[c] = 1; + chars_table_1[c] = 1; } - cs += 2; - continue; - } - chars_table_1[(ui8)*cs] = 1; - } - } else { + cs += 2; + continue; + } + chars_table_1[(ui8)*cs] = 1; + } + } else { for (; *charset; charset++) { - chars_table_1[(ui8)*charset] = 1; + chars_table_1[(ui8)*charset] = 1; } - } - memcpy(chars_table, chars_table_1, 256); + } + memcpy(chars_table, chars_table_1, 256); chars_table_1[0] = 1; for (int n = 0; n < 256; n++) { c_chars_table[n] = !chars_table_1[n]; } -} - +} + Tr::Tr(const char* from, const char* to) { for (size_t n = 0; n < 256; n++) { - Map[n] = (char)n; + Map[n] = (char)n; } for (; *from && *to; from++, to++) { - Map[(ui8)*from] = *to; + Map[(ui8)*from] = *to; } -} +} size_t Tr::FindFirstChangePosition(const TString& str) const { for (auto it = str.begin(); it != str.end(); ++it) { diff --git a/util/string/util.h b/util/string/util.h index 0d77a5042b..0c41a3459e 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -53,24 +53,24 @@ inline void addIfAbsent(TString& s, char lastCh1, char lastCh2) { * * ------------------------------------------------------------------ */ -struct ui8_256 { +struct ui8_256 { // forward chars table - ui8 chars_table[256]; + ui8 chars_table[256]; // reverse (for c* functions) chars table ui8 c_chars_table[256]; -}; - +}; + class str_spn: public ui8_256 { public: explicit str_spn(const char* charset, bool extended = false) { - // exteneded: if true, treat charset string more like - // interior of brackets [ ], e.g. "a-z0-9" - init(charset, extended); - } - - /// Return first character in table, like strpbrk() - /// That is, skip all characters not in table - /// [DIFFERENCE FOR NOT_FOUND CASE: Returns end of string, not NULL] + // exteneded: if true, treat charset string more like + // interior of brackets [ ], e.g. "a-z0-9" + init(charset, extended); + } + + /// Return first character in table, like strpbrk() + /// That is, skip all characters not in table + /// [DIFFERENCE FOR NOT_FOUND CASE: Returns end of string, not NULL] const char* brk(const char* s) const { while (c_chars_table[(ui8)*s]) ++s; @@ -83,13 +83,13 @@ public: return s; } - /// Return first character not in table, like strpbrk() for inverted table. - /// That is, skip all characters in table + /// Return first character not in table, like strpbrk() for inverted table. + /// That is, skip all characters in table const char* cbrk(const char* s) const { while (chars_table[(ui8)*s]) ++s; - return s; - } + return s; + } const char* cbrk(const char* s, const char* e) const { while (s < e && chars_table[(ui8)*s]) @@ -97,7 +97,7 @@ public: return s; } - /// Offset of the first character not in table, like strspn(). + /// Offset of the first character not in table, like strspn(). size_t spn(const char* s) const { return cbrk(s) - s; } @@ -106,7 +106,7 @@ public: return cbrk(s, e) - s; } - /// Offset of the first character in table, like strcspn(). + /// Offset of the first character in table, like strcspn(). size_t cspn(const char* s) const { return brk(s) - s; } @@ -123,35 +123,35 @@ public: return const_cast<char*>(cbrk((const char*)s)); } - /// See strsep [BUT argument is *&, not **] + /// See strsep [BUT argument is *&, not **] char* sep(char*& s) const { - char sep_char; // unused; - return sep(s, sep_char); - } - - /// strsep + remember character that was destroyed + char sep_char; // unused; + return sep(s, sep_char); + } + + /// strsep + remember character that was destroyed char* sep(char*& s, char& sep_char) const { - if (!s) + if (!s) return nullptr; char* ret = s; char* next = brk(ret); - if (*next) { - sep_char = *next; - *next = 0; - s = next + 1; - } else { - sep_char = 0; + if (*next) { + sep_char = *next; + *next = 0; + s = next + 1; + } else { + sep_char = 0; s = nullptr; - } - return ret; - } - + } + return ret; + } + protected: void init(const char* charset, bool extended); str_spn() = default; -}; - -// an analogue of tr/$from/$to/ +}; + +// an analogue of tr/$from/$to/ class Tr { public: Tr(const char* from, const char* to); @@ -161,14 +161,14 @@ public: } void Do(char* s) const { - for (; *s; s++) + for (; *s; s++) *s = ConvertChar(*s); - } + } void Do(const char* src, char* dst) const { - for (; *src; src++) + for (; *src; src++) *dst++ = ConvertChar(*src); - *dst = 0; - } + *dst = 0; + } void Do(char* s, size_t l) const { for (size_t i = 0; i < l && s[i]; i++) s[i] = ConvertChar(s[i]); @@ -179,7 +179,7 @@ private: char Map[256]; size_t FindFirstChangePosition(const TString& str) const; -}; +}; // Removes all occurrences of given character from string template <typename TStringType> diff --git a/util/string/util_ut.cpp b/util/string/util_ut.cpp index 18a2d8e195..5c6e003132 100644 --- a/util/string/util_ut.cpp +++ b/util/string/util_ut.cpp @@ -10,8 +10,8 @@ class TStrUtilTest: public TTestBase { public: void TestSpn() { - str_spn rul("a-z", true); - char s[] = "!@#$ab%^&c+-"; + str_spn rul("a-z", true); + char s[] = "!@#$ab%^&c+-"; UNIT_ASSERT_EQUAL(rul.brk(s), s + 4); UNIT_ASSERT_EQUAL(rul.brk(s + 4), s + 4); UNIT_ASSERT_EQUAL(rul.brk(s + 10), s + 12); @@ -21,7 +21,7 @@ public: UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "%^&"), 0); UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "+-"), 0); UNIT_ASSERT_EQUAL(rul.sep(s1), nullptr); - } + } void TestRemoveAll() { static const struct T { diff --git a/util/system/align.h b/util/system/align.h index ea0bbc5b46..e5e8a217f8 100644 --- a/util/system/align.h +++ b/util/system/align.h @@ -21,9 +21,9 @@ template <class T> static inline T AlignUpSpace(T len, T align) noexcept { Y_ASSERT(IsPowerOf2(align)); // align should be power of 2 return ((T)0 - len) & (align - 1); // AlignUp(len, align) - len; -} - -template <class T> +} + +template <class T> static inline T* AlignUp(T* ptr, size_t align) noexcept { return (T*)AlignUp((uintptr_t)ptr, align); } diff --git a/util/system/atomic.h b/util/system/atomic.h index 80265babfd..676fa3fb91 100644 --- a/util/system/atomic.h +++ b/util/system/atomic.h @@ -1,5 +1,5 @@ #pragma once - + #include "defaults.h" using TAtomicBase = intptr_t; @@ -11,8 +11,8 @@ using TAtomic = volatile TAtomicBase; #include "atomic_win.h" #else #error unsupported platform -#endif - +#endif + #if !defined(ATOMIC_COMPILER_BARRIER) #define ATOMIC_COMPILER_BARRIER() #endif diff --git a/util/system/atomic_gcc.h b/util/system/atomic_gcc.h index ed8dc2bdc5..8838e3919c 100644 --- a/util/system/atomic_gcc.h +++ b/util/system/atomic_gcc.h @@ -1,5 +1,5 @@ #pragma once - + #define ATOMIC_COMPILER_BARRIER() __asm__ __volatile__("" \ : \ : \ @@ -61,7 +61,7 @@ static inline intptr_t AtomicSwap(TAtomic* p, intptr_t v) { __atomic_exchange(p, &v, &ret, __ATOMIC_SEQ_CST); return ret; } - + static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) { (void)a; // disable strange 'parameter set but not used' warning on gcc return __atomic_compare_exchange(a, &compare, &exchange, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); diff --git a/util/system/atomic_win.h b/util/system/atomic_win.h index 65c290e6cc..084c4c8859 100644 --- a/util/system/atomic_win.h +++ b/util/system/atomic_win.h @@ -1,5 +1,5 @@ #pragma once - + #include <intrin.h> #define USE_GENERIC_SETGET @@ -14,7 +14,7 @@ static inline intptr_t AtomicIncrement(TAtomic& a) { return _InterlockedIncrement((volatile long*)&a); -} +} static inline intptr_t AtomicGetAndIncrement(TAtomic& a) { return _InterlockedIncrement((volatile long*)&a) - 1; @@ -22,7 +22,7 @@ static inline intptr_t AtomicGetAndIncrement(TAtomic& a) { static inline intptr_t AtomicDecrement(TAtomic& a) { return _InterlockedDecrement((volatile long*)&a); -} +} static inline intptr_t AtomicGetAndDecrement(TAtomic& a) { return _InterlockedDecrement((volatile long*)&a) + 1; @@ -30,7 +30,7 @@ static inline intptr_t AtomicGetAndDecrement(TAtomic& a) { static inline intptr_t AtomicAdd(TAtomic& a, intptr_t b) { return _InterlockedExchangeAdd((volatile long*)&a, b) + b; -} +} static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) { return _InterlockedExchangeAdd((volatile long*)&a, b); @@ -39,7 +39,7 @@ static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) { static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) { return _InterlockedExchange((volatile long*)a, b); } - + static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) { return _InterlockedCompareExchange((volatile long*)a, exchange, compare) == compare; } diff --git a/util/system/compat.h b/util/system/compat.h index c53dbcca17..b85591b0d1 100644 --- a/util/system/compat.h +++ b/util/system/compat.h @@ -44,7 +44,7 @@ extern "C" { void vwarnx(const char* format, va_list ap); void vwarn(const char* format, va_list ap); void verrx(int status, const char* format, va_list ap); -#else +#else #include <err.h> #endif } diff --git a/util/system/err.cpp b/util/system/err.cpp index 5573ea1ee9..891d7c0cb6 100644 --- a/util/system/err.cpp +++ b/util/system/err.cpp @@ -4,20 +4,20 @@ #include "error.h" #include <util/generic/scope.h> - + #include <util/stream/printf.h> #include <util/stream/output.h> - + void vwarnx(const char* fmt, va_list args) { Cerr << GetProgramName() << ": "; - + if (fmt) { Printf(Cerr, fmt, args); } - + Cerr << '\n'; } - + void vwarn(const char* fmt, va_list args) { int curErrNo = errno; auto curErrText = LastSystemErrorText(); @@ -25,55 +25,55 @@ void vwarn(const char* fmt, va_list args) { Y_DEFER { errno = curErrNo; }; - + Cerr << GetProgramName() << ": "; - + if (fmt) { Printf(Cerr, fmt, args); Cerr << ": "; } Cerr << curErrText << '\n'; -} - +} + void warn(const char* fmt, ...) { va_list args; - + va_start(args, fmt); vwarn(fmt, args); va_end(args); -} - +} + void warnx(const char* fmt, ...) { va_list args; - + va_start(args, fmt); vwarnx(fmt, args); va_end(args); -} - +} + void verr(int status, const char* fmt, va_list args) { vwarn(fmt, args); exit(status); -} - +} + void err(int status, const char* fmt, ...) { va_list args; va_start(args, fmt); verr(status, fmt, args); va_end(args); -} - +} + void verrx(int status, const char* fmt, va_list args) { vwarnx(fmt, args); exit(status); -} - +} + void errx(int status, const char* fmt, ...) { va_list args; va_start(args, fmt); verrx(status, fmt, args); va_end(args); -} +} diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..ec7cc69272 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -49,7 +49,7 @@ #include <sys/sendfile.h> #define HAVE_POSIX_FADVISE 1 #define HAVE_SYNC_FILE_RANGE 1 -#elif defined(__FreeBSD__) && !defined(WITH_VALGRIND) +#elif defined(__FreeBSD__) && !defined(WITH_VALGRIND) #include <sys/param.h> #define HAVE_POSIX_FADVISE (__FreeBSD_version >= 900501) #define HAVE_SYNC_FILE_RANGE 0 @@ -565,38 +565,38 @@ FHANDLE TFileHandle::Duplicate() const noexcept { #endif } -int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept { - if (!IsOpen()) { - return -1; - } -#if defined(_win_) - FHANDLE dupHandle = Duplicate(); - if (dupHandle == INVALID_FHANDLE) { - _set_errno(EMFILE); - return -1; - } - int posixHandle = _open_osfhandle((intptr_t)dupHandle, 0); - if (posixHandle == -1) { - CloseHandle(dupHandle); - return -1; - } - if (dup2(posixHandle, dstHandle) == -1) { - dstHandle = -1; - } - _close(posixHandle); - return dstHandle; -#elif defined(_unix_) - while (dup2(Fd_, dstHandle) == -1) { - if (errno != EINTR) { - return -1; - } - } - return dstHandle; -#else +int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept { + if (!IsOpen()) { + return -1; + } +#if defined(_win_) + FHANDLE dupHandle = Duplicate(); + if (dupHandle == INVALID_FHANDLE) { + _set_errno(EMFILE); + return -1; + } + int posixHandle = _open_osfhandle((intptr_t)dupHandle, 0); + if (posixHandle == -1) { + CloseHandle(dupHandle); + return -1; + } + if (dup2(posixHandle, dstHandle) == -1) { + dstHandle = -1; + } + _close(posixHandle); + return dstHandle; +#elif defined(_unix_) + while (dup2(Fd_, dstHandle) == -1) { + if (errno != EINTR) { + return -1; + } + } + return dstHandle; +#else #error unsupported platform -#endif -} - +#endif +} + bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept { #if defined(_unix_) while (dup2(fh.Fd_, Fd_) == -1) { diff --git a/util/system/file.h b/util/system/file.h index 9502e159b6..caec596d9e 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -120,7 +120,7 @@ public: int Flock(int op) noexcept; FHANDLE Duplicate() const noexcept; - int Duplicate2Posix(int dstHandle) const noexcept; + int Duplicate2Posix(int dstHandle) const noexcept; //dup2 - like semantics, return true on success bool LinkTo(const TFileHandle& fh) const noexcept; diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..a0864cc980 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -60,7 +60,7 @@ namespace { return sysInfo.dwAllocationGranularity; #else return NSystemInfo::GetPageSize(); -#endif +#endif } const size_t GRANULARITY_; @@ -188,7 +188,7 @@ public: , Mode_(om) { CheckFile(); - + if (File_.GetLength() < Length_) { File_.Resize(Length_); } @@ -220,15 +220,15 @@ public: inline TMapResult Map(i64 offset, size_t size) { assert(File_.IsOpen()); - + if (offset > Length_) { ythrow yexception() << "Can't map something at offset " << offset << " of '" << DbgName_ << "' with length " << Length_; } - + if (offset + (i64)size > Length_) { ythrow yexception() << "Can't map " << (unsigned long)size << " bytes at offset " << offset << " of '" << DbgName_ << "' with length " << Length_; } - + TMapResult result; i64 base = DownToGranularity(offset); diff --git a/util/system/filemap.h b/util/system/filemap.h index 11be64bff4..014b46c41d 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -52,7 +52,7 @@ struct TMemoryMapCommon { oRdOnly = 1, oRdWr = 2, oCopyOnWr = 4, - + oAccessMask = 7, oNotGreedy = 8, oPrecharge = 16, @@ -77,12 +77,12 @@ public: TMemoryMap(FILE* f, EOpenMode om, TString dbgName = UnknownFileName()); TMemoryMap(const TFile& file, TString dbgName = UnknownFileName()); TMemoryMap(const TFile& file, EOpenMode om, TString dbgName = UnknownFileName()); - + ~TMemoryMap(); - + TMapResult Map(i64 offset, size_t size); bool Unmap(TMapResult region); - + void ResizeAndReset(i64 size); TMapResult ResizeAndRemap(i64 offset, size_t size); @@ -91,7 +91,7 @@ public: bool IsWritable() const noexcept; EOpenMode GetMode() const noexcept; TFile GetFile() const noexcept; - + void SetSequential(); void Evict(void* ptr, size_t len); void Evict(); @@ -100,7 +100,7 @@ public: * deprecated */ bool Unmap(void* ptr, size_t size); - + private: class TImpl; TSimpleIntrusivePtr<TImpl> Impl_; @@ -165,7 +165,7 @@ public: TFile GetFile() const noexcept { return Map_.GetFile(); } - + void Precharge(size_t pos = 0, size_t size = (size_t)-1) const; void SetSequential() { @@ -203,11 +203,11 @@ public: ~TFileMappedArray() { Ptr_ = nullptr; End_ = nullptr; - } + } void Init(const char* name) { DataHolder_.Reset(new TFileMap(name)); DoInit(name); - } + } void Init(const TFileMap& fileMap) { DataHolder_.Reset(new TFileMap(fileMap)); DoInit(fileMap.GetFile().GetName()); @@ -217,18 +217,18 @@ public: Ptr_ = nullptr; Size_ = 0; End_ = nullptr; - } + } void Precharge() { DataHolder_->Precharge(); } const T& operator[](size_t pos) const { Y_ASSERT(pos < size()); return Ptr_[pos]; - } + } /// for STL compatibility only, Size() usage is recommended - size_t size() const { + size_t size() const { return Size_; - } + } size_t Size() const { return Size_; } @@ -236,11 +236,11 @@ public: if (pos < Size_) return Ptr_[pos]; return Dummy(); - } + } void SetDummy(const T& n_Dummy) { Dummy_.Destroy(); Dummy_.Reset(new (DummyData()) T(n_Dummy)); - } + } inline char* DummyData() const noexcept { return AlignUp((char*)DummyData_); } @@ -285,8 +285,8 @@ private: Size_ = DataHolder_->Length() / sizeof(T); End_ = Ptr_ + Size_; } -}; - +}; + class TMappedAllocation: TMoveOnly { public: TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr); @@ -343,12 +343,12 @@ public: T* Create(size_t siz) { Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr); T* arr = (T*)Alloc((sizeof(T) * siz)); - if (!arr) + if (!arr) return nullptr; Y_ASSERT(MappedSize() == sizeof(T) * siz); for (size_t n = 0; n < siz; n++) new (&arr[n]) T(); - return arr; + return arr; } void Destroy() { T* arr = (T*)Ptr(); diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp index a410ccac06..52ecf3ed7f 100644 --- a/util/system/fs_win.cpp +++ b/util/system/fs_win.cpp @@ -6,7 +6,7 @@ #include <util/charset/wide.h> #include "file.h" -#include <winioctl.h> +#include <winioctl.h> namespace NFsPrivate { static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) { diff --git a/util/system/guard.h b/util/system/guard.h index efc091d5f8..fa8da37f27 100644 --- a/util/system/guard.h +++ b/util/system/guard.h @@ -1,5 +1,5 @@ #pragma once - + #include <util/generic/noncopyable.h> template <class T> diff --git a/util/system/mktemp.cpp b/util/system/mktemp.cpp index 505b7b4a4b..4b332255af 100644 --- a/util/system/mktemp.cpp +++ b/util/system/mktemp.cpp @@ -10,7 +10,7 @@ #ifdef _win32_ #include "winint.h" #include <io.h> -#else +#else #include <unistd.h> #include <stdlib.h> #endif diff --git a/util/system/mutex.h b/util/system/mutex.h index 032630d134..2187380e65 100644 --- a/util/system/mutex.h +++ b/util/system/mutex.h @@ -17,7 +17,7 @@ public: inline void Release() noexcept { } - + inline void lock() noexcept { Acquire(); } diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b1989b5c8c..4200491e2e 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -628,22 +628,22 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { #endif void ShellQuoteArg(TString& dst, TStringBuf argument) { - dst.append("\""); - TStringBuf l, r; + dst.append("\""); + TStringBuf l, r; while (argument.TrySplit('"', l, r)) { - dst.append(l); - dst.append("\\\""); + dst.append(l); + dst.append("\\\""); argument = r; - } + } dst.append(argument); - dst.append("\""); -} - + dst.append("\""); +} + void ShellQuoteArgSp(TString& dst, TStringBuf argument) { - dst.append(' '); + dst.append(' '); ShellQuoteArg(dst, argument); -} - +} + bool ArgNeedsQuotes(TStringBuf arg) noexcept { if (arg.empty()) { return true; diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 8730627fe5..d3d1488d3a 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -474,11 +474,11 @@ private: using TImplRef = TSimpleIntrusivePtr<TImpl>; TImplRef Impl; }; - -/// Appends to dst: quoted arg + +/// Appends to dst: quoted arg void ShellQuoteArg(TString& dst, TStringBuf arg); - -/// Appends to dst: space, quoted arg + +/// Appends to dst: space, quoted arg void ShellQuoteArgSp(TString& dst, TStringBuf arg); /// Returns true if arg should be quoted diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 9d849279d2..ffd7fd738d 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -62,14 +62,14 @@ private: Y_UNIT_TEST_SUITE(TShellQuoteTest) { Y_UNIT_TEST(TestQuoteArg) { TString cmd; - ShellQuoteArg(cmd, "/pr f/krev/prev.exe"); - ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\""); - ShellQuoteArgSp(cmd, "-DVal=W Space"); - ShellQuoteArgSp(cmd, "-DVal=Blah"); - UNIT_ASSERT_STRINGS_EQUAL(cmd, "\"/pr f/krev/prev.exe\" \"-DVal=\\\"W Quotes\\\"\" \"-DVal=W Space\" \"-DVal=Blah\""); - } -} - + ShellQuoteArg(cmd, "/pr f/krev/prev.exe"); + ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\""); + ShellQuoteArgSp(cmd, "-DVal=W Space"); + ShellQuoteArgSp(cmd, "-DVal=Blah"); + UNIT_ASSERT_STRINGS_EQUAL(cmd, "\"/pr f/krev/prev.exe\" \"-DVal=\\\"W Quotes\\\"\" \"-DVal=W Space\" \"-DVal=Blah\""); + } +} + Y_UNIT_TEST_SUITE(TShellCommandTest) { Y_UNIT_TEST(TestNoQuotes) { TShellCommandOptions options; diff --git a/util/system/spin_wait.h b/util/system/spin_wait.h index 91dd423e33..c13559bce6 100644 --- a/util/system/spin_wait.h +++ b/util/system/spin_wait.h @@ -1,5 +1,5 @@ #pragma once - + struct TSpinWait { TSpinWait() noexcept; diff --git a/util/system/spinlock.h b/util/system/spinlock.h index af2630890a..a560d83821 100644 --- a/util/system/spinlock.h +++ b/util/system/spinlock.h @@ -1,5 +1,5 @@ #pragma once - + #include "atomic.h" #include "spin_wait.h" diff --git a/util/system/thread.cpp b/util/system/thread.cpp index 6236746c2d..f1fe4a24b4 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -8,7 +8,7 @@ #include <util/generic/yexception.h> #include "yassert.h" #include <utility> - + #if defined(_glibc_) #if !__GLIBC_PREREQ(2, 30) #include <sys/syscall.h> @@ -82,7 +82,7 @@ namespace { #endif { } - + inline bool Running() const noexcept { return Handle != 0; } @@ -231,7 +231,7 @@ namespace { #undef PCHECK using TThreadBase = TPosixThread; -#endif +#endif template <class T> static inline typename T::TValueType* Impl(T& t, const char* op, bool check = true) { @@ -403,48 +403,48 @@ static void WindowsCurrentSetThreadName(DWORD dwThreadID, const char* threadName } #endif -#if defined(_win_) -namespace { - struct TWinThreadDescrAPI { - TWinThreadDescrAPI() +#if defined(_win_) +namespace { + struct TWinThreadDescrAPI { + TWinThreadDescrAPI() : Kernel32Dll("kernel32.dll") - , SetThreadDescription((TSetThreadDescription)Kernel32Dll.SymOptional("SetThreadDescription")) - , GetThreadDescription((TGetThreadDescription)Kernel32Dll.SymOptional("GetThreadDescription")) - { - } - - // This API is for Windows 10+ only: - // https://msdn.microsoft.com/en-us/library/windows/desktop/mt774972(v=vs.85).aspx - bool HasAPI() noexcept { - return SetThreadDescription && GetThreadDescription; - } - - // Should always succeed, unless something very strange is passed in `descr' - void SetDescr(const char* descr) { - auto hr = SetThreadDescription(GetCurrentThread(), (const WCHAR*)UTF8ToWide(descr).data()); - Y_VERIFY(SUCCEEDED(hr), "SetThreadDescription failed"); - } - - TString GetDescr() { - PWSTR wideName; - auto hr = GetThreadDescription(GetCurrentThread(), &wideName); - Y_VERIFY(SUCCEEDED(hr), "GetThreadDescription failed"); - Y_DEFER { - LocalFree(wideName); - }; - return WideToUTF8((const wchar16*)wideName); - } - + , SetThreadDescription((TSetThreadDescription)Kernel32Dll.SymOptional("SetThreadDescription")) + , GetThreadDescription((TGetThreadDescription)Kernel32Dll.SymOptional("GetThreadDescription")) + { + } + + // This API is for Windows 10+ only: + // https://msdn.microsoft.com/en-us/library/windows/desktop/mt774972(v=vs.85).aspx + bool HasAPI() noexcept { + return SetThreadDescription && GetThreadDescription; + } + + // Should always succeed, unless something very strange is passed in `descr' + void SetDescr(const char* descr) { + auto hr = SetThreadDescription(GetCurrentThread(), (const WCHAR*)UTF8ToWide(descr).data()); + Y_VERIFY(SUCCEEDED(hr), "SetThreadDescription failed"); + } + + TString GetDescr() { + PWSTR wideName; + auto hr = GetThreadDescription(GetCurrentThread(), &wideName); + Y_VERIFY(SUCCEEDED(hr), "GetThreadDescription failed"); + Y_DEFER { + LocalFree(wideName); + }; + return WideToUTF8((const wchar16*)wideName); + } + typedef HRESULT(__cdecl* TSetThreadDescription)(HANDLE hThread, PCWSTR lpThreadDescription); typedef HRESULT(__cdecl* TGetThreadDescription)(HANDLE hThread, PWSTR* ppszThreadDescription); - - TDynamicLibrary Kernel32Dll; - TSetThreadDescription SetThreadDescription; - TGetThreadDescription GetThreadDescription; - }; -} -#endif // _win_ - + + TDynamicLibrary Kernel32Dll; + TSetThreadDescription SetThreadDescription; + TGetThreadDescription GetThreadDescription; + }; +} +#endif // _win_ + void TThread::SetCurrentThreadName(const char* name) { (void)name; @@ -455,15 +455,15 @@ void TThread::SetCurrentThreadName(const char* name) { prctl(PR_SET_NAME, name, 0, 0, 0); #elif defined(_darwin_) pthread_setname_np(name); -#elif defined(_win_) - auto api = Singleton<TWinThreadDescrAPI>(); - if (api->HasAPI()) { - api->SetDescr(name); - } else { +#elif defined(_win_) + auto api = Singleton<TWinThreadDescrAPI>(); + if (api->HasAPI()) { + api->SetDescr(name); + } else { #if defined(_MSC_VER) - WindowsCurrentSetThreadName(DWORD(-1), name); + WindowsCurrentSetThreadName(DWORD(-1), name); #endif - } + } #else // no idea #endif // OS @@ -471,7 +471,7 @@ void TThread::SetCurrentThreadName(const char* name) { TString TThread::CurrentThreadName() { #if defined(_freebsd_) -// TODO: check pthread_get_name_np API availability +// TODO: check pthread_get_name_np API availability #elif defined(_linux_) // > The buffer should allow space for up to 16 bytes; the returned string will be // > null-terminated. @@ -487,12 +487,12 @@ TString TThread::CurrentThreadName() { memset(name, 0, sizeof(name)); Y_VERIFY(pthread_getname_np(thread, name, sizeof(name)) == 0, "pthread_getname_np failed: %s", strerror(errno)); return name; -#elif defined(_win_) - auto api = Singleton<TWinThreadDescrAPI>(); - if (api->HasAPI()) { - return api->GetDescr(); - } - return {}; +#elif defined(_win_) + auto api = Singleton<TWinThreadDescrAPI>(); + if (api->HasAPI()) { + return api->GetDescr(); + } + return {}; #else // no idea #endif // OS @@ -500,16 +500,16 @@ TString TThread::CurrentThreadName() { return {}; } -bool TThread::CanGetCurrentThreadName() { -#if defined(_linux_) || defined(_darwin_) - return true; -#elif defined(_win_) - return Singleton<TWinThreadDescrAPI>()->HasAPI(); -#else - return false; -#endif // OS -} - +bool TThread::CanGetCurrentThreadName() { +#if defined(_linux_) || defined(_darwin_) + return true; +#elif defined(_win_) + return Singleton<TWinThreadDescrAPI>()->HasAPI(); +#else + return false; +#endif // OS +} + TCurrentThreadLimits::TCurrentThreadLimits() noexcept : StackBegin(nullptr) , StackLength(0) diff --git a/util/system/thread.h b/util/system/thread.h index a6e8abdb5b..8ce6ab3016 100644 --- a/util/system/thread.h +++ b/util/system/thread.h @@ -1,5 +1,5 @@ #pragma once - + /// This code should not be used directly unless you really understand what you do. /// If you need threads, use thread pool functionality in <util/thread/factory.h> /// @see SystemThreadFactory() @@ -9,7 +9,7 @@ #include "defaults.h" #include "progname.h" - + bool SetHighestThreadPriority(); class TThread { @@ -71,7 +71,7 @@ public: return *this; } }; - + TThread(const TParams& params); TThread(TThreadProc threadProc, void* param); @@ -113,18 +113,18 @@ public: // NOTE: Content of `name` will be copied. // // NOTE: On Linux thread name is limited to 15 symbols which is probably the smallest one among - // all platforms. If you provide a name longer than 15 symbols it will be cut. So if you expect + // all platforms. If you provide a name longer than 15 symbols it will be cut. So if you expect // `CurrentThreadName` to return the same name as `name` make sure it's not longer than 15 // symbols. static void SetCurrentThreadName(const char* name); - // NOTE: Will return empty string where CanGetCurrentThreadName() returns false. + // NOTE: Will return empty string where CanGetCurrentThreadName() returns false. static TString CurrentThreadName(); - // NOTE: Depends on a platform version. - // Will return true for Darwin, Linux or fresh Windows 10. - static bool CanGetCurrentThreadName(); - + // NOTE: Depends on a platform version. + // Will return true for Darwin, Linux or fresh Windows 10. + static bool CanGetCurrentThreadName(); + private: struct TCallableBase { virtual ~TCallableBase() = default; @@ -155,7 +155,7 @@ private: private: class TImpl; THolder<TImpl> Impl_; -}; +}; class ISimpleThread: public TThread { public: diff --git a/util/system/thread.i b/util/system/thread.i index 8cba505473..ee18b5efee 100644 --- a/util/system/thread.i +++ b/util/system/thread.i @@ -23,7 +23,7 @@ #endif #include <util/digest/numeric.h> - + static inline size_t SystemCurrentThreadIdImpl() noexcept { #if defined(_unix_) return (size_t)pthread_self(); diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp index d820898fd5..8d0b023da0 100644 --- a/util/system/thread_ut.cpp +++ b/util/system/thread_ut.cpp @@ -66,11 +66,11 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { TThread::SetCurrentThreadName(setName.data()); const auto getName = TThread::CurrentThreadName(); - if (TThread::CanGetCurrentThreadName()) { - UNIT_ASSERT_VALUES_EQUAL(setName, getName); - } else { - UNIT_ASSERT_VALUES_EQUAL("", getName); - } + if (TThread::CanGetCurrentThreadName()) { + UNIT_ASSERT_VALUES_EQUAL(setName, getName); + } else { + UNIT_ASSERT_VALUES_EQUAL("", getName); + } return nullptr; } @@ -97,11 +97,11 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { thread.Join(); const auto getName = TThread::CurrentThreadName(); - if (TThread::CanGetCurrentThreadName()) { - UNIT_ASSERT_VALUES_EQUAL(setName, getName); - } else { - UNIT_ASSERT_VALUES_EQUAL("", getName); - } + if (TThread::CanGetCurrentThreadName()) { + UNIT_ASSERT_VALUES_EQUAL(setName, getName); + } else { + UNIT_ASSERT_VALUES_EQUAL("", getName); + } return nullptr; } diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp index 0377da4212..16efdbe353 100644 --- a/util/system/type_name.cpp +++ b/util/system/type_name.cpp @@ -1,7 +1,7 @@ #include "platform.h" #include "demangle_impl.h" -#ifdef __GNUC__ +#ifdef __GNUC__ #include <stdexcept> #include <cxxabi.h> #endif @@ -25,7 +25,7 @@ namespace { } // anonymous namespace const char* NPrivate::TCppDemangler::Demangle(const char* name) { -#ifndef __GNUC__ +#ifndef __GNUC__ return name; #else int status; diff --git a/util/system/unaligned_mem.h b/util/system/unaligned_mem.h index 4b84686f2f..4af20371f2 100644 --- a/util/system/unaligned_mem.h +++ b/util/system/unaligned_mem.h @@ -40,7 +40,7 @@ public: } inline T Cur() const noexcept { - Y_ASSERT(C_ < L_ || sizeof(T) < Align); + Y_ASSERT(C_ < L_ || sizeof(T) < Align); return ::ReadUnaligned<T>(C_); } diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp index 0f586648b7..816e9e8448 100644 --- a/util/system/yassert.cpp +++ b/util/system/yassert.cpp @@ -78,7 +78,7 @@ namespace NPrivate { } else { o << " " << function << "() failed" << Endl; } - Cerr << r << Flush; + Cerr << r << Flush; #ifndef WITH_VALGRIND PrintBackTrace(); #endif diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp index 05fad02e9b..506743da09 100644 --- a/util/thread/pool.cpp +++ b/util/thread/pool.cpp @@ -662,7 +662,7 @@ namespace { void IThreadPool::SafeAdd(IObjectInQueue* obj) { Y_ENSURE_EX(Add(obj), TThreadPoolException() << TStringBuf("can not add object to queue")); } - + void IThreadPool::SafeAddAndOwn(THolder<IObjectInQueue> obj) { Y_ENSURE_EX(AddAndOwn(std::move(obj)), TThreadPoolException() << TStringBuf("can not add to queue and own")); } diff --git a/util/thread/pool_ut.cpp b/util/thread/pool_ut.cpp index 893770d0c4..628db06fed 100644 --- a/util/thread/pool_ut.cpp +++ b/util/thread/pool_ut.cpp @@ -186,10 +186,10 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { name = TThread::CurrentThreadName(); }); pool.Stop(); - if (TThread::CanGetCurrentThreadName()) { - UNIT_ASSERT_EQUAL(name, expectedName); - UNIT_ASSERT_UNEQUAL(TThread::CurrentThreadName(), expectedName); - } + if (TThread::CanGetCurrentThreadName()) { + UNIT_ASSERT_EQUAL(name, expectedName); + UNIT_ASSERT_UNEQUAL(TThread::CurrentThreadName(), expectedName); + } } Y_UNIT_TEST(TestFixedThreadName) { @@ -225,9 +225,9 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { }); } pool.Stop(); - if (TThread::CanGetCurrentThreadName()) { - UNIT_ASSERT_EQUAL(names, expectedNames); - } + if (TThread::CanGetCurrentThreadName()) { + UNIT_ASSERT_EQUAL(names, expectedNames); + } } Y_UNIT_TEST(TestEnumeratedThreadName) { |