rename vector.hpp to array.hpp

dev
MITSUNARI Shigeo 7 years ago
parent e879a8389e
commit 5c3db4036b
  1. 2
      Makefile
  2. 8
      include/mcl/bn.hpp
  3. 4
      include/mcl/op.hpp
  4. 77
      include/mcl/vector.hpp
  5. 2
      include/mcl/vint.hpp
  6. 4
      test/array_test.cpp

@ -5,7 +5,7 @@ EXE_DIR=bin
SRC_SRC=fp.cpp bn_c256.cpp bn_c384.cpp bn_c512.cpp she_c256.cpp
TEST_SRC=fp_test.cpp ec_test.cpp fp_util_test.cpp window_method_test.cpp elgamal_test.cpp fp_tower_test.cpp gmp_test.cpp bn_test.cpp bn384_test.cpp glv_test.cpp paillier_test.cpp she_test.cpp vint_test.cpp bn512_test.cpp ecdsa_test.cpp conversion_test.cpp
TEST_SRC+=bn_c256_test.cpp bn_c384_test.cpp bn_c512_test.cpp she_c256_test.cpp she_c384_test.cpp
TEST_SRC+=aggregate_sig_test.cpp vector_test.cpp
TEST_SRC+=aggregate_sig_test.cpp array_test.cpp
TEST_SRC+=bls12_test.cpp
TEST_SRC+=ecdsa_c_test.cpp
ifeq ($(CPU),x86-64)

@ -107,7 +107,7 @@ void Frobenius3(G2& D, const G2& S);
namespace local {
typedef mcl::Vector<int8_t> SignVec;
typedef mcl::Array<int8_t> SignVec;
inline size_t getPrecomputeQcoeffSize(const SignVec& sv)
{
@ -1713,7 +1713,7 @@ inline void precomputeG2(std::vector<Fp6>& Qcoeff, const G2& Q)
Qcoeff.resize(BN::param.precomputedQcoeffSize);
precomputeG2(Qcoeff.data(), Q);
}
inline bool precomputeG2(mcl::Vector<Fp6>& Qcoeff, const G2& Q)
inline bool precomputeG2(mcl::Array<Fp6>& Qcoeff, const G2& Q)
{
bool b = Qcoeff.resize(BN::param.precomputedQcoeffSize);
if (!b) return false;
@ -1760,7 +1760,7 @@ inline void precomputedMillerLoop(Fp12& f, const G1& P, const std::vector<Fp6>&
{
precomputedMillerLoop(f, P, Qcoeff.data());
}
inline void precomputedMillerLoop(Fp12& f, const G1& P, const mcl::Vector<Fp6>& Qcoeff)
inline void precomputedMillerLoop(Fp12& f, const G1& P, const mcl::Array<Fp6>& Qcoeff)
{
precomputedMillerLoop(f, P, Qcoeff.data());
}
@ -1822,7 +1822,7 @@ inline void precomputedMillerLoop2(Fp12& f, const G1& P1, const std::vector<Fp6>
{
precomputedMillerLoop2(f, P1, Q1coeff.data(), P2, Q2coeff.data());
}
inline void precomputedMillerLoop2(Fp12& f, const G1& P1, const mcl::Vector<Fp6>& Q1coeff, const G1& P2, const mcl::Vector<Fp6>& Q2coeff)
inline void precomputedMillerLoop2(Fp12& f, const G1& P1, const mcl::Array<Fp6>& Q1coeff, const G1& P2, const mcl::Array<Fp6>& Q2coeff)
{
precomputedMillerLoop2(f, P1, Q1coeff.data(), P2, Q2coeff.data());
}

@ -8,7 +8,7 @@
*/
#include <mcl/gmp_util.hpp>
#include <memory.h>
#include <mcl/vector.hpp>
#include <mcl/array.hpp>
#ifndef MCL_MAX_BIT_SIZE
#define MCL_MAX_BIT_SIZE 521
@ -180,7 +180,7 @@ struct Op {
Unit one[maxUnitSize];
Unit R2[maxUnitSize];
Unit R3[maxUnitSize];
mcl::Vector<Unit> invTbl;
mcl::Array<Unit> invTbl;
size_t N;
size_t bitSize;
bool (*fp_isZero)(const Unit*);

@ -1,77 +0,0 @@
#pragma once
/**
@file
@brief tiny vector class
@author MITSUNARI Shigeo(@herumi)
@license modified new BSD license
http://opensource.org/licenses/BSD-3-Clause
*/
#include <malloc.h>
#include <stddef.h>
#include <algorithm>
namespace mcl {
template<class T>
class Vector {
T *p_;
size_t n_;
Vector(const Vector&);
void operator=(const Vector&);
public:
Vector() : p_(0), n_(0) {}
~Vector()
{
free(p_);
}
bool resize(size_t n)
{
if (n <= n_) {
n_ = n;
if (n == 0) {
free(p_);
p_ = 0;
}
return true;
}
T *q = (T*)malloc(sizeof(T) * n);
if (q == 0) return false;
for (size_t i = 0; i < n_; i++) {
q[i] = p_[i];
}
free(p_);
p_ = q;
n_ = n;
return true;
}
bool copy(const Vector<T>& rhs)
{
if (this == &rhs) return true;
if (n_ < rhs.n_) {
clear();
if (!resize(rhs.n_)) return false;
}
for (size_t i = 0; i < rhs.n_; i++) {
p_[i] = rhs.p_[i];
}
n_ = rhs.n_;
return true;
}
void clear()
{
free(p_);
p_ = 0;
n_ = 0;
}
size_t size() const { return n_; }
void swap(Vector<T>& rhs)
{
std::swap(p_, rhs.p_);
std::swap(n_, rhs.n_);
}
T& operator[](size_t n) { return p_[n]; }
const T& operator[](size_t n) const { return p_[n]; }
T* data() { return p_; }
const T* data() const { return p_; }
};
} // mcl

@ -7,7 +7,7 @@
#include <assert.h>
#include <cmath>
#include <iostream>
#include <mcl/vector.hpp>
#include <mcl/array.hpp>
#include <mcl/util.hpp>
#include <mcl/randgen.hpp>
#include <mcl/conversion.hpp>

@ -1,9 +1,9 @@
#include <mcl/vector.hpp>
#include <mcl/array.hpp>
#include <cybozu/test.hpp>
CYBOZU_TEST_AUTO(resize)
{
mcl::Vector<int> a, b;
mcl::Array<int> a, b;
CYBOZU_TEST_EQUAL(a.size(), 0);
CYBOZU_TEST_EQUAL(b.size(), 0);
Loading…
Cancel
Save