generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a6bea5
commit ddee4a1
Showing
422 changed files
with
1,098 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#ifndef TIFALIBS_IO_FASTIN | ||
#define TIFALIBS_IO_FASTIN | ||
|
||
#include "../util/traits.hpp" | ||
#ifdef __linux__ | ||
#include <sys/mman.h> | ||
#include <sys/stat.h> | ||
#endif | ||
|
||
namespace tifa_libs { | ||
|
||
//! UB if EOF occured during reading | ||
class fastin { | ||
CEXP static u32 BUF = 0x200005; | ||
FILE *f_ = nullptr; | ||
#ifdef __linux__ | ||
char *bg, *ed, *p; | ||
struct stat Fl; | ||
|
||
template <bool ignore_space = true> | ||
void read_str(strn &n) NE { | ||
char *l = p, *r; | ||
if CEXP (ignore_space) { | ||
while (!isgraph(*l++)); | ||
r = l--; | ||
while (isgraph(*r++)); | ||
} else { | ||
while (!isprint(*l++)); | ||
r = l--; | ||
while (isprint(*r++)); | ||
} | ||
n.assign(l, p = r); | ||
} | ||
|
||
public: | ||
fastin(FILE *f = stdin) NE { assert(f), rebind(f); } | ||
~fastin() NE { rebind(); } | ||
void rebind(FILE *f = nullptr) NE { | ||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" | ||
if (!f_) munmap(bg, Fl.st_size + 1); | ||
#pragma GCC diagnostic warning "-Wmaybe-uninitialized" | ||
if (!f) return; | ||
auto fd = fileno(f_ = f); | ||
fstat(fd, &Fl); | ||
p = (bg = (char *)mmap(nullptr, Fl.st_size + 4, PROT_READ, MAP_PRIVATE, fd, 0)); | ||
ed = bg + Fl.st_size; | ||
madvise(bg, Fl.st_size + 4, MADV_SEQUENTIAL); | ||
} | ||
bool iseof() NE { return p == ed; } | ||
#else | ||
char buf[BUF], *ed, *p; | ||
|
||
template <bool ignore_space> | ||
void read_str(strn &n) NE { | ||
n.clear(), n.reserve(23); | ||
if CEXP (ignore_space) { | ||
n.push_back(skip_cntrls().get()); | ||
while (isgraph(get())) n.push_back(peek()); | ||
} else { | ||
n.push_back(skip_cntrl().get()); | ||
while (isprint(get())) n.push_back(peek()); | ||
} | ||
} | ||
|
||
public: | ||
fastin(FILE *f = stdin) NE { rebind(f); } | ||
void rebind(FILE *f) NE { f_ = f, p = ed = buf; } | ||
bool iseof() NE { | ||
if (p == ed) [[unlikely]] | ||
ed = (p = buf) + fread(buf, 1, BUF, f_); | ||
return p == ed; | ||
} | ||
#endif | ||
char peek() NE { | ||
if (iseof()) [[unlikely]] | ||
return EOF; | ||
return *p; | ||
} | ||
char get_unchk() NE { return *p++; } | ||
char get() NE { | ||
if (iseof()) [[unlikely]] | ||
return EOF; | ||
return get_unchk(); | ||
} | ||
#define SKIP(name, pred) \ | ||
fastin &skip_##name() NE { \ | ||
if (pred(peek())) get_unchk(); \ | ||
return *this; \ | ||
} | ||
SKIP(cntrl, iscntrl) | ||
SKIP(cntrls, !isgraph) | ||
SKIP(ndigit, !isdigit) | ||
#undef SKIP | ||
template <class T> | ||
requires(std::integral<T> && !char_c<T>) | ||
fastin &operator>>(T &n) NE { | ||
if CEXP (std::same_as<T, bool>) n = skip_ndigit().get() != '0'; | ||
else { | ||
n = 0; | ||
bool is_neg = false; | ||
if CEXP (std::signed_integral<T>) | ||
while (!isdigit(peek())) is_neg |= peek() == '-', get_unchk(); | ||
else skip_ndigit(); | ||
while (isdigit(peek())) (n *= 10) += peek() & 15, get_unchk(); | ||
if CEXP (sint_c<T>) | ||
if (is_neg) n = -n; | ||
} | ||
return *this; | ||
} | ||
fastin &operator>>(std::floating_point auto &n) NE { | ||
static strn s; | ||
(*this >> s), std::from_chars(s.begin().base(), s.end().base(), n); | ||
return *this; | ||
} | ||
//! ignore cntrl and space | ||
fastin &operator>>(char_c auto &n) NE { return (n = skip_cntrls().get()), *this; } | ||
fastin &operator>>(strn &n) NE { return read_str<true>(n), *this; } | ||
fastin &getline(strn &n) NE { return read_str<false>(n), *this; } | ||
//! NOT ignore cntrl and space | ||
fastin &strict_read(char_c auto &n) NE { return (n = get()), *this; } | ||
fastin &operator>>(fastin &(*func)(fastin &)) NE { return func(*this); } | ||
}; | ||
inline fastin fin; | ||
inline fastin &ws(fastin &f) NE { return f.skip_cntrls(); } | ||
|
||
} // namespace tifa_libs | ||
|
||
#endif |
Oops, something went wrong.