aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2018-05-19 09:10:20 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2018-05-19 09:10:20 +0800
commit09a998993fbd41643ba552751a9a7fd235c25ded (patch)
tree1b1dcdc0262d75ac81c42c1934b25182d1233b2e
parentb5e34ca403427c2a9666410645d6985b983d2fa4 (diff)
downloadtangerine-mcl-09a998993fbd41643ba552751a9a7fd235c25ded.tar.gz
tangerine-mcl-09a998993fbd41643ba552751a9a7fd235c25ded.tar.zst
tangerine-mcl-09a998993fbd41643ba552751a9a7fd235c25ded.zip
remove fromStr16
-rw-r--r--sample/bench.cpp2
-rw-r--r--src/conversion.hpp26
-rw-r--r--test/fp_util_test.cpp9
3 files changed, 5 insertions, 32 deletions
diff --git a/sample/bench.cpp b/sample/bench.cpp
index 14997f8..4e43020 100644
--- a/sample/bench.cpp
+++ b/sample/bench.cpp
@@ -173,7 +173,7 @@ void benchFromStr16()
Fp x;
const size_t N = 64;
mcl::fp::Unit buf[N];
- CYBOZU_BENCH("fp:fromStr16", mcl::fp::fromStr16, buf, N, str.c_str(), str.size());
+ CYBOZU_BENCH("fp:hexToArray", mcl::fp::hexToArray, buf, N, str.c_str(), str.size());
mpz_class y;
CYBOZU_BENCH("gmp:setStr ", mcl::gmp::setStr, y, str, 16);
diff --git a/src/conversion.hpp b/src/conversion.hpp
index 8681048..3c5a036 100644
--- a/src/conversion.hpp
+++ b/src/conversion.hpp
@@ -205,32 +205,6 @@ size_t arrayToBin(char *buf, size_t bufSize, const T *x, size_t n, bool withPref
convert hex string to x[0..xn)
hex string = [0-9a-fA-F]+
*/
-template<class T>
-void fromStr16(T *x, size_t xn, const char *str, size_t strLen)
-{
- if (strLen == 0) throw cybozu::Exception("fp:fromStr16:strLen is zero");
- const size_t unitLen = sizeof(T) * 2;
- const size_t q = strLen / unitLen;
- const size_t r = strLen % unitLen;
- const size_t requireSize = q + (r ? 1 : 0);
- if (xn < requireSize) throw cybozu::Exception("fp:fromStr16:short size") << xn << requireSize;
- for (size_t i = 0; i < q; i++) {
- bool b;
- x[i] = cybozu::hextoi(&b, &str[r + (q - 1 - i) * unitLen], unitLen);
- if (!b) throw cybozu::Exception("fp:fromStr16:bad char") << cybozu::exception::makeString(str, strLen);
- }
- if (r) {
- bool b;
- x[q] = cybozu::hextoi(&b, str, r);
- if (!b) throw cybozu::Exception("fp:fromStr16:bad char") << cybozu::exception::makeString(str, strLen);
- }
- for (size_t i = requireSize; i < xn; i++) x[i] = 0;
-}
-
-/*
- convert hex string to x[0..xn)
- hex string = [0-9a-fA-F]+
-*/
template<class UT>
inline size_t hexToArray(UT *x, size_t maxN, const char *buf, size_t bufSize)
{
diff --git a/test/fp_util_test.cpp b/test/fp_util_test.cpp
index 72e6c7d..c516274 100644
--- a/test/fp_util_test.cpp
+++ b/test/fp_util_test.cpp
@@ -53,7 +53,7 @@ CYBOZU_TEST_AUTO(arrayToBin)
}
// CYBOZU_TEST_AUTO(verifyStr) // QQQ
-CYBOZU_TEST_AUTO(fromStr16)
+CYBOZU_TEST_AUTO(hexToArray)
{
const struct {
const char *str;
@@ -71,10 +71,9 @@ CYBOZU_TEST_AUTO(fromStr16)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
const size_t xN = 4;
uint64_t x[xN];
- mcl::fp::fromStr16(x, xN, tbl[i].str, strlen(tbl[i].str));
- for (size_t j = 0; j < xN; j++) {
- CYBOZU_TEST_EQUAL(x[j], tbl[i].x[j]);
- }
+ size_t n = mcl::fp::hexToArray(x, xN, tbl[i].str, strlen(tbl[i].str));
+ CYBOZU_TEST_ASSERT(n > 0);
+ CYBOZU_TEST_EQUAL_ARRAY(x, tbl[i].x, n);
}
}