Skip to content

Commit

Permalink
libstd: Allow strings to be passed into crc hash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 7, 2024
1 parent a1ce3bf commit 5832e56
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/source/pl/lib/std/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
namespace pl::lib::libstd::hash {

template<size_t Size>
static u128 crc(const auto &params) {
auto pattern = params[0].toPattern();
static u128 crc(pl::core::Evaluator *ctx, const auto &params) {
if (!params[0].isPattern() && !params[0].isString())
core::err::E0012.throwError("Only patterns and strings are supported for CRC hash functions.");

auto bytes = params[0].toBytes();
auto init = params[1].toUnsigned();
auto poly = params[2].toUnsigned();
auto xorout = params[3].toUnsigned();
auto reflectIn = params[4].toUnsigned();
auto reflectOut = params[5].toUnsigned();

wolv::hash::Crc<Size> crc(poly, init, xorout, reflectIn, reflectOut);
crc.process(pattern->getBytes());
crc.process(bytes);

return u128(crc.getResult());
}
Expand Down

0 comments on commit 5832e56

Please sign in to comment.