Giter VIP home page Giter VIP logo

polynomial's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

polynomial's Issues

valgrind warning in

The following warning shows up in minusTimesXn method:
==2179== Invalid read of size 8
==2179== at 0x4013F1: G2Poly::minusTimesXn(G2Poly const&, unsigned long) (g2polynomial.h:140)
==2179== by 0x401665: operator%(G2Poly const&, G2Poly const&) (g2polynomial.h:173)
==2179== by 0x401FBF: gcd(G2Poly, G2Poly) (g2polynomial.h:321)
==2179== by 0x403B22: G2Poly::mceliece(unsigned long) const (g2polynomial.h:500)
==2179== by 0x404084: main (test_g2polynomial.cpp:15)
==2179== Address 0x4c39bb8 is 0 bytes after a block of size 56 alloc'd
==2179== at 0x4A068F3: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==2179== by 0x4084CB: __gnu_cxx::new_allocator::allocate(unsigned long, void const*) (new_allocator.h:104)
==2179== by 0x4075CC: std::_Vector_base<unsigned long, std::allocator >::_M_allocate(unsigned long) (in /home/pierre/codingame/nintendo/soluce/test_g2polynomial)
==2179== by 0x406ADB: unsigned long* std::vector<unsigned long, std::allocator >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<unsigned long const*, std::vector<unsigned long, std::allocator > > >(unsigned long, __gnu_cxx::__normal_iterator<unsigned long const*, std::vector<unsigned long, std::allocator > >, __gnu_cxx::__normal_iterator<unsigned long const*, std::vector<unsigned long, std::allocator > >) (stl_vector.h:1138)
==2179== by 0x405519: std::vector<unsigned long, std::allocator >::operator=(std::vector<unsigned long, std::allocator > const&) (vector.tcc:188)
==2179== by 0x40474A: G2Poly::operator=(G2Poly const&) (g2polynomial.h:13)
==2179== by 0x401FA5: gcd(G2Poly, G2Poly) (g2polynomial.h:320)
==2179== by 0x403B22: G2Poly::mceliece(unsigned long) const (g2polynomial.h:500)
==2179== by 0x404084: main (test_g2polynomial.cpp:15)

This could be fixed with the following modifications:

void G2Poly::minusTimesXn(const G2Poly &b, uint64_t n) {
std::vector <uint64_t> result;
result.reserve(std::max(b.coeffs_.size(), coeffs_.size()));
size_t i(0), j(0);
auto size = coeffs_.size();
auto size2 = b.coeffs_.size();
auto ci = coeffs_[i];
auto cj = b.coeffs_[j] + n;
while(i < size && j < size2) {
if(ci > cj) {
result.push_back(ci);
++i; if (i<size) ci = coeffs_[i];
} else if(ci < cj) {
result.push_back(cj);
++j; if (j<size2) cj = b.coeffs_[j] + n;
} else {
++i; if (i<size) ci = coeffs_[i];
++j; if (j<size2) cj = b.coeffs_[j] + n;
}
}
// Insert remaining coeffs from other as they are obviously not in this
while(i < size) {
result.push_back(coeffs_[i]);
i++;
}
while(j < size2) {
result.push_back(b.coeffs_[j] + n);
j++;
}
this->coeffs_.swap(result);
}

Hope this helps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.